Changes

Jump to navigation Jump to search
1,976 bytes added ,  13:23, 13 February 2006
Added section on character alignment, explaining mode=2
</context>
</td></tr></table>
 
== Using character alignment ==
 
ConTeXt can align columns of numbers on a character (often a decimal point to align accounting data) automatically, removing the need to add fixed spaces into your document. For any such column you need to specify the character on which to align. You use the <tt>aligncharacter=yes</tt> parameter to set up character alignment, <tt>alignmentcharacter={.}</tt> to say what the character should be (in this case a full stop) and <tt>align=middle</tt> to set the overall alignment of the column.
 
<table><tr valign="top"><td>
<texcode>
\bTABLE
\setupTABLE[column][1][align=right]
\setupTABLE[column][2][alignmentcharacter={.},
aligncharacter=yes,align=middle]
\bTR \bTH Category \eTH \bTH Data entry \eTH \eTR
\bTR \bTD First \eTD \bTD 71.3 \eTD \eTR
\bTR \bTD Second \eTD \bTD 43.7 \eTD \eTR
\bTR \bTD Total \eTD \bTD 115 \eTD \eTR
\eTABLE
</texcode>
</td><td>
<context>
\bTABLE
\setupTABLE[column][1][align=right]
\setupTABLE[column][2][alignmentcharacter={.},aligncharacter=yes,align=middle]
\bTR \bTH Category \eTH \bTH Data entry \eTH \eTR
\bTR \bTD First \eTD \bTD 71.3 \eTD \eTR
\bTR \bTD Second \eTD \bTD 43.7 \eTD \eTR
\bTR \bTD Total \eTD \bTD 115 \eTD \eTR
\eTABLE
</context>
</td></tr></table>
 
You'll note that the final line, because it has no . in the number, gets aligned under the right-hand side of the numbers. In most circumstances you would want such a number aligned with the left-hand set of digits. To so do, issue the following command in your preamble:
 
<texcode>
\chardef\characteralignmentmode=2
</texcode>
 
and now the table above will turn out like this:
 
<context>
\chardef\characteralignmentmode=2
\bTABLE
\setupTABLE[column][1][align=right]
\setupTABLE[column][2][alignmentcharacter={.},aligncharacter=yes,align=middle]
\bTR \bTH Category \eTH \bTH Data entry \eTH \eTR
\bTR \bTD First \eTD \bTD 71.3 \eTD \eTR
\bTR \bTD Second \eTD \bTD 43.7 \eTD \eTR
\bTR \bTD Total \eTD \bTD 115 \eTD \eTR
\eTABLE
</context>
[[Category:Tables]]
[[Category:XML]]
21

edits

Navigation menu