version=pmwiki-2.2.1 ordered=1 urlencoded=1 agent=Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.19) Gecko/20081216 Ubuntu/8.04 (hardy) Firefox/2.0.0.19 author=Petko charset=ISO-8859-1 csum=refactor ctime=1141945978 host=77.195.128.91 name=PmWiki.Tables rev=54 targets=PmWiki.TableDirectives text=(:Audience: authors (basic) :)%0a(:Summary:Simple tables with double pipe markup, one row per line:)%0a!! Table basics%0a%0aPmWiki has two types of table markup; the markup described in this page is useful for creating ''simple'' tables with lots of small cells, while [[table directive(s)]] markups help with larger scale tables. For more possibilities with table formatting see [[Cookbook:Rowspan in simple tables]] and [[Cookbook:Formatting tables]].%0a%0aTables are created via use of double pipe characters: @@||@@. Lines beginning with this markup denote rows in a table or a formatting line. Within table row lines the double-pipe is used to delimit cells. In the examples below a border is added for illustration (the default is no border).%0a%0aThe first line in the markup contains formatting commands for the table. It only has double pipe characters at the start of the line.%0a%0a(:markup caption='Basic table' class=horiz:)%0a|| border=1%0a|| cell 1 || cell 2 || cell 3 ||%0a|| cell 1 || cell 2 ||%0a(:markupend:)%0a%0aHeader cells can be created by placing ! as the first character of a cell. Note that these are ''table headers'', not ''headings'', so it doesn't extend to !!, !!!, etc.%0a%0a(:markup caption='Table headers' class=horiz:)%0a|| border=1%0a||! cell 1 ||! cell 2 ||! cell 3 ||%0a|| cell 1 || cell 2 || cell 3 ||%0a(:markupend:)%0a%0aA table can have a caption, indicated by [@||!caption!||@]. Any caption must appear prior to other rows of the table.%0a%0a(:markup caption='Table caption' class=horiz:)%0a|| border=1%0a||! A special table !||%0a||! cell 1 ||! cell 2 ||! cell 3 ||%0a|| cell 1 || cell 2 || cell 3 ||%0a(:markupend:)%0a%0a%0a!! Formatting cell contents%0a%0aCell contents may be aligned left, centered, or aligned right. %0a* To left-align contents, place the cell contents next to the leading @@||@@.%0a* To center contents, add a space before and after the cell contents.%0a* To right-align contents, place a space before the cell contents and leave the cell contents next to the trailing @@||@@.%0a%0a(:markup caption='Cell alignments':)%0a|| border=1 width=100%25%0a||!cell 1 ||! cell 2 ||! cell 3||%0a||left-aligned || centered || right-aligned||%0a(:markupend:)%0a%0a(:markup caption='Default cell alignments':)%0a|| border=1 width=100%25%0a||!cell default||!cell left ||%0a||default-aligned||left-aligned ||%0a(:markupend:)%0a%0aNote that header and detail cells have different default alignments.%0a%0aTo get a cell to span multiple columns, follow the cell with empty cells.%0a(At present there is no markup for spanning rows.)%0a%0a(:markup caption='Column spanning':)%0a|| border=1 width=100%25%0a|| |||| right column ||%0a|| || middle column ||||%0a|| left column ||||||%0a|| left column || middle column || right column ||%0a(:markupend:)%0a%0a!! Table attributes%0a%0aAny line that begins with [@||@] but doesn't have a closing [@||@] sets the ''table attributes'' for any tables that follow. These attributes can control the size and position of the table, borders, background color, and cell spacing. (In fact these are just standard HTML attributes that are placed in the %3ctable> tag.)%0a%0aUse the [@width=@] attribute to set a table's width, using either a percentage value, an absolute size, or '''*'''.%0a%0a(:markup caption='Table width':)%0a|| border=1 width=100%25 %0a|| cell 1 || cell 2 || cell 3 ||%0a|| c1 || cellcellcellcell2 || cell 3 ||%0a(:markupend:)%0a%0aThe [@border=@] attribute sets the size of a table's borders.%0a%0a(:markup caption='Bordered table' class=horiz:)%0a|| border=10 width=70%25%0a||!cell 1 ||! cell 2 ||! cell 3||%0a||left-aligned || centered || right-aligned||%0a(:markupend:)%0a%0a(:markup caption='Borderless table' class=horiz:)%0a|| border=0 width=70%25%0a||!cell 1 ||! cell 2 ||! cell 3||%0a||left-aligned || centered || right-aligned||%0a(:markupend:)%0a%0aUse [@align=center@], [@align=left@], and [@align=right@] to center, left, or right align a table. Note that [@align=left@] and [@align=right@] create a ''floating table'', such that text wraps around the table.%0a%0a(:markup caption='Table alignment: center':)%0a|| border=1 align=center width=50%25%0a||!cell 1 ||! cell 2 ||! cell 3||%0a||left-aligned || centered || right-aligned||%0aNotice how text does not wrap with a table using "align=center".%0a(:markupend:)%0a%0a(:markup caption='Table alignment: left':)%0a|| border=1 align=left width=50%25%0a||!cell 1 ||! cell 2 ||! cell 3||%0a||left-aligned || centered || right-aligned||%0aNotice how text wraps to the right of a table using "align=left".%0a(:markupend:)%0a%0a(:markup caption='Table alignment: right':)%0a|| border=1 align=right width=50%25%0a||!cell 1 ||! cell 2 ||! cell 3||%0a||left-aligned || centered || right-aligned||%0aNotice how text wraps to the left of a table using "align=right".%0a(:markupend:)%0a%0aNote: to get a table to align left (but not "float left") requires CSS, as in%0a->[@||style="margin-left:0px;"@]%0a%0aThe [@bgcolor=@] attribute sets the background color for a table. At present there is no way to specify the color of individual rows or cells in this type of table (but see Cookbook:FormattingTables).%0a%0a(:markup class=horiz:)%0a|| border=1 align=center bgcolor=yellow width=70%25%0a||!cell 1 ||! cell 2 ||! cell 3||%0a||left-align || center || right-align||%0a(:markupend:)%0a%0a>>faq%3c%3c [[#faq]]%0aQ: How do I create a basic table? %0aA: Tables are created via use of the double pipe character: @@||@@. Lines beginning with this markup denote rows in a table; within such lines the double-pipe is used to delimit cells. In the examples below a border is added for illustration (the default is no border).%0a%0a(:markup caption='Basic table' class=horiz:)%0a|| border=1 rules=rows frame=hsides%0a|| cell 1 || cell 2 || cell 3 ||%0a|| cell 1 || cell 2 || cell 3 ||%0a(:markupend:)%0a%0aQ: How do I create cell headers?%0aA: Header cells can be created by placing ! as the first character of a cell. Note that these are ''table headers'', not ''headings'', so it doesn't extend to !!, !!!, etc.%0a%0a(:markup caption='Table headers' class=horiz:)%0a|| border=1 rules=cols frame=vsides%0a||! cell 1 ||! cell 2 ||! cell 3 ||%0a|| cell 1 || cell 2 || cell 3 ||%0a(:markupend:)%0a%0aQ: How do I create an advanced table? %0aA: See [[PmWiki.TableDirectives | table directives]]%0a%0aQ: My tables are by default centered. When I try to use '||align=left' they don't align left as expected. %0aA: Use ||style="margin-left:0px;" instead. %0a%0aQ: How can I specify the width of columns?%0aA: You can define the widths via custom styles, see Cookbook:FormattingTables and $TableCellAttrFmt. Add in config.php :%0a[@$TableCellAttrFmt = 'class=col\$TableCellCount';@]%0a-> And add in pub/css/local.css : %0a[@%0atable.column td.col1 { width: 120px; }%0atable.column td.col3 { width: 40px; }%0a@]%0a%0aQ: How can I display a double pipe "||" in cell text using basic table markup?%0aA: Escape it with [@[=||=]@] to display || unchanged.%0a time=1242924562