https://wiki.contextgarden.net/api.php?action=feedcontributions&user=84.27.244.22&feedformat=atomWiki - User contributions [en]2024-03-29T07:56:55ZUser contributionsMediaWiki 1.34.1https://wiki.contextgarden.net/index.php?title=Table&diff=6578Table2006-09-17T18:26:57Z<p>84.27.244.22: Add {} around \starttable \stoptable</p>
<hr />
<div>< [[Tables Overview]] | [[tabulate]] | [[Tables]] ><br />
<br />
This is ConTeXts oldest table module. It uses the same formatting as [[tabulate]] (see [[Tables Overview]]).<br />
<br />
This mode is based on Michael Wichura's TaBlE package for PlainTeX. The official manual for it is commercial (about 40 USD), see [http://www.pctex.com/books.html PCTeX] -- but note that the TaBlE manual only talks about the original syntax, which does not use <cmd>NC</cmd>, <cmd>HL</cmd> cum suis.<br />
<br />
The only ConTeXt docs are in [[manual:ms-cb-en.pdf|ConTeXt - an excursion]].<br />
<br />
== Basic Commands ==<br />
<br />
<table cols="2"><tr valign="top"><td><br />
<texcode><br />
\starttable[|l|l|]<br />
\HL<br />
\NC Command \VL Meaning \SR % or \NC\AR<br />
\HL<br />
\NC \tex{NC} \VL next column \AR<br />
\NC \tex{HL} \VL horizontal line \AR<br />
\NC \tex{VL} \VL vertical line \AR<br />
\NC \tex{NR} \VL next row \LR<br />
\HL<br />
\NC \tex{SR} \VL single row \AR<br />
\NC \tex{FR} \VL first row \AR<br />
\NC \tex{MR} \VL middle row \AR<br />
\NC \tex{LR} \VL last row \LR % or \NC\AR<br />
\HL<br />
\NC \tex{AR} \VL automatic row \SR % or \NC\AR<br />
\HL<br />
\stoptable<br />
</texcode><br />
</td><td><br />
<context><br />
\switchtobodyfont[ss, 8pt]<br />
\starttable[|l|l|]<br />
\HL<br />
\NC Command \VL Meaning \SR % or \NC\AR<br />
\HL<br />
\NC \tex{NC} \VL next column \AR<br />
\NC \tex{HL} \VL horizontal line \AR<br />
\NC \tex{VL} \VL vertical line \AR<br />
\NC \tex{NR} \VL next row \LR<br />
\HL<br />
\NC \tex{SR} \VL single row \AR<br />
\NC \tex{FR} \VL first row \AR<br />
\NC \tex{MR} \VL middle row \AR<br />
\NC \tex{LR} \VL last row \LR % or \NC\AR<br />
\HL<br />
\NC \tex{AR} \VL automatic row \SR % or \NC\AR<br />
\HL<br />
\stoptable<br />
</context><br />
</td></tr></table><br />
<br />
* You get vertical lines (rules), if you use <cmd>VL</cmd> instead of <cmd>NC</cmd>.<br />
* Better use <cmd>SR</cmd>, <cmd>FR</cmd>, <cmd>MR</cmd>, <cmd>LR</cmd> instead of <cmd>NR</cmd>.<br />
* You can also use <cmd>AR</cmd> instead of <cmd>SR</cmd>, <cmd>FR</cmd>, <cmd>MR</cmd> and <cmd>LR</cmd> (AR for automatic row).<br />
* You can leave out the <cmd>NC</cmd> before the "row" command, but not if you use <cmd>AR</cmd> in a last or single row (see example).<br />
* You can influence the table with <cmd>setuptables</cmd>.<br />
* There are also <cmd>BL</cmd> and <cmd>CL</cmd> for colored backgrounds, see below.<br />
<br />
==Column Definition==<br />
<br />
The table is defined by the template enclosed in square brackets after <cmd>starttable</cmd>. The template has the form<br />
<tt>|keys for the first column|keys for the second column|...|keys for the last column|</tt>. Please note that the each column is surrounded by <tt>|</tt> signs. These are necessary. The formatting keys for each column can be a choice of<br />
<br />
<table width="100%" cols="2"><tr valign="top"><td><br />
<context><br />
\switchtobodyfont[ss, 8pt]<br />
\starttable[|l|lp(.5\textwidth)|]<br />
\HL<br />
\NC \bf Key \VL \bf Meaning \SR<br />
\HL<br />
\NC \NC Primitive Keys \SR<br />
\HL<br />
\NC \type{a{tokens}}\VL Adds \type{tokens} {\em after} the column content\AR<br />
\NC \type{b{tokens}}\VL Adds \type{tokens} '''before''' the column content\AR<br />
\NC {\tt \backslash\{ } \VL Enclose the column in braces (grouping)\AR<br />
\NC \type{*{n}{keys}}\VL Equivalent to repeating the formatting keys \type{keys} \type{n} times\NC\LR<br />
\HL<br />
\NC \NC Positioning Keys\SR<br />
\HL<br />
\NC \type{\LeftGlue} \VL Specifies the left glue to be used before the column\AR<br />
\NC \type{\RightGlue} \VL Specifies the right glue to be used after the column\AR<br />
\NC \type{l} \VL left-aligned column\AR<br />
\NC \type{c} \VL centered column\AR<br />
\NC \type{r} \VL right-aligned column\AR<br />
\NC \type{p(width)} \VL Set each cell as a paragraph\AR<br />
\NC \type{w} \VL Set minimum column width\AR<br />
\NC \type{k} \VL Insert a kern both left and right of the column\AR<br />
\NC \type{i} \VL Add a kern to the left of the column\AR<br />
\NC \type{j} \VL Add a kern to the right of the column\LR<br />
\HL<br />
\NC \NC Numeric and Math Item Keys \SR<br />
\HL<br />
\NC \type{n} \VL Numeric item not in math mode\AR<br />
\NC \type{N} \VL Numeric item in math mode\AR<br />
\NC \type{m} \VL Each cell is in (inline) math mode. Equivalent to \type{b$ a$}\AR<br />
\NC \type{M} \VL Each cell is in display math mode. Equivalent to \type{\{b{$\displaystyle}a$}} \AR<br />
\NC \type{\m} \VL Equivalent to \type{l b{{}}m}\AR<br />
\NC \type{\M} \VL Equivalent to \type{l b{{}}M}\LR<br />
\HL<br />
\NC \NC Style Keys \SR<br />
\HL<br />
\NC \type{f\command} \VL Set font according to following \tex{command}\AR<br />
\NC \type{B} \VL Bold. Equivalent to \type{f\bf}\AR<br />
\NC \type{I} \VL Italic. Equivalent to \type{f\it}\AR<br />
\NC \type{S} \VL Slanted. Equivalent to \type{f\sl}\AR<br />
\NC \type{R} \VL Roman. Equivalent to \type{f\rm}\AR<br />
\NC \type{T} \VL Teletype. Equivalent to \type{f\tt}\AR<br />
\NC \type{C} \VL Color. Use it in combination with \backslash\{ (e.g. \backslash\{C\{red\} )\LR<br />
\HL<br />
\NC \NC Tabskip Keys \SR<br />
\HL<br />
\NC \type{s} \VL Set the tabskip to the right of this column and of all following columns up to the next \type{s} or \type{o} key\AR<br />
\NC \type{o} \VL Set the tabskip to the right of this column only\LR<br />
\HL<br />
\stoptable<br />
</context><br />
</td><td><br />
===Examples===<br />
; <code>|l|</code> : a left aligned column, as wide as necessary<br />
; <code>|lw(2cm)|</code> : a left aligned column of at least 2 cm width<br />
; <code>|p(2cm)|</code> : a centered(!) paragraph of 2 cm width<br />
; <code>|lp(.5\textwidth)|</code> : a left aligned paragraph of specified width<br />
; <code>...</code> : Please add more<br />
; <code>...</code> : <br />
<br />
{{todo|add more examples of column definitions}}<br />
</td></tr></table><br />
<br />
==Column Spans==<br />
<br />
It's possible to create columnspans (i.e. cells that span more than one column) with the command <cmd>use{<i>N</i>}</cmd> where ''N'' is the number of columns spanned by the cell. It's often necessary to use <cmd>ReFormat[<i>new keys</i>]{}</cmd> to reformat this specific cell according to the ''new keys''.<br />
<br />
<br />
<table cols="2"><tr valign="top"><td><br />
<texcode><br />
\starttable[s(0pt)|ls(10pt)|rs(0pt)|]<br />
\HL<br />
\NC \use{2}\ReFormat[cB]{Spanning head} \SR<br />
\HL<br />
\NC left column text \VL right column text \NC \AR<br />
\NC new row \VL new row \NC \AR<br />
\NC left column text \VL \ReFormat[l]{reformatted} \NC \AR<br />
\HL<br />
\NC \use{2}Spanning entry \SR <br />
\HL<br />
\stoptable<br />
</texcode><br />
</td><td><br />
<context><br />
\starttable[s(0pt)|ls(10pt)|rs(0pt)|]<br />
\HL<br />
\NC \use{2}\ReFormat[cB]{Spanning head} \SR<br />
\HL<br />
\NC left column text \VL right column text \NC \AR<br />
\NC new row \VL new row \NC \AR<br />
\NC left column text \VL \ReFormat[l]{reformatted} \NC \AR<br />
\HL<br />
\NC \use{2}Spanning entry \SR <br />
\HL<br />
\stoptable<br />
</context><br />
</td></tr></table><br />
<br />
==Table as Floating Object==<br />
<br />
<texcode><br />
\placetable[here][tab:sample]{sample table}{<br />
\starttable ...<br />
\stoptable<br />
}<br />
</texcode><br />
<br />
* See [[Floating Objects]] in general.<br />
* If you need information about <cmd>placetable</cmd> look after <cmd>placefloat</cmd> in the manual or texshow!<br />
* If you'd like to leave out the table's caption (here: "sample table"), you can't simply leave the braces empty but must write <tt>none</tt>!<br />
<br />
==Background Colors==<br />
<br />
A very nice application in table are background colors for rows/cells (a feature that doesn't work in [[tabulate]]):<br />
<br />
<table cols="2"><tr valign="top"><td><br />
<texcode><br />
\setupcolors[state=start]<br />
\starttable[|l|l|]<br />
\HL<br />
\BL[1]\SR<br />
\NC Command \NC Meaning \SR<br />
\HL<br />
\NC \tex{NC} \NC next column \FR<br />
\NC \tex{NR} \NC next row \LR<br />
\HL<br />
\CL[green]\SR<br />
\NC \tex{AR} \NC automatic row \SR<br />
\HL<br />
\stoptable<br />
</texcode><br />
</td><td><br />
<context><br />
\setupcolors[state=start]<br />
\starttable[|l|l|]<br />
\HL<br />
\BL[1]\SR<br />
\NC Command \NC Meaning \SR<br />
\HL<br />
\NC \tex{NC} \NC next column \FR<br />
\NC \tex{NR} \NC next row \LR<br />
\HL<br />
\CL[green]\SR<br />
\NC \tex{AR} \NC automatic row \SR<br />
\HL<br />
\stoptable<br />
</context><br />
</td><br />
</tr></table><br />
The commands work something like this: first, you say what background colour you want for the next row<br />
and then you typeset the row. Observe: the line with the colour-command and the row it is supposed<br />
to colour should end in the same command (i.e. both \SR, \LR, \FR, ...). If they don't, the background<br />
won't cover the whole cell.<br />
<br />
* <cmd>BL</cmd> makes a gray background: the optional argument tells BL how many cells it should color<br />
* <cmd>CL</cmd> makes a colored line<br />
<br />
==Fit Table Width==<br />
<br />
Hans posted a solution to the list for fitting a wide table (with paragraphs and vertical lines) to the page width. The key to his solution is the <code>.45\textwidth</code> settings when setting each cell as a paragraph.<br />
<br />
<texcode><br />
\SetTableToWidth{\textwidth}<br />
<br />
\starttable[|p(.45\textwidth)|p(.45\textwidth)|]<br />
\HL<br />
\VL foo foo foo foo foo foo \VL bar bar bar bar bar bar \VL\AR<br />
\HL<br />
\stoptable<br />
</texcode><br />
<!-- It makes no sense to typeset this here. --><br />
<br />
[[Category:Tables]]</div>84.27.244.22https://wiki.contextgarden.net/index.php?title=Modes&diff=6556Modes2006-09-10T20:09:27Z<p>84.27.244.22: doifmode and doifmodeelse [] to {}</p>
<hr />
<div>< [[The ConTeXt Way]] | [[Inside ConTeXt]] | [[Project structure]] ><br />
<br />
Often you'd like to publish different versions of a document, say a presentation and a handout or a student's and a teacher's version.<br />
<br />
ConTeXt supports such filtering with its '''modes''':<br />
<br />
<texcode><br />
ConTeXt is a great TeX macro package.<br />
\startmode[handout] % The following text will only appear in the handout<br />
It’s based on Plain TeX like the better known LaTeX.<br />
\stopmode<br />
</texcode><br />
<br />
<texcode><br />
\startnotmode[print]<br />
Here's a link to my homepage: \url[...]<br />
\stopnotmode<br />
</texcode><br />
<br />
<texcode><br />
\doifmode{answers}{The answer to the homework is 42.}<br />
</texcode><br />
<br />
<texcode><br />
\doifmodeelse{draft}{Draft Version}{Final Version}<br />
</texcode><br />
<br />
<tt>...mode</tt> and <tt>...notmode</tt> let you filter your content sufficient in most cases.<br />
You can also give several modes like <tt>\startmode[handout,print]</tt>.<br />
<br />
Modes are also a convenient way to comment out sections (typical: "obsolete" mode).<br />
<br />
You can typeset the different modes like:<br />
<br />
<pre><br />
texexec myfile --mode=handout --result=handout.pdf<br />
</pre><br />
<br />
You don't need the <tt>--result</tt>, but otherwise you'd get the same filename for both modes.<br />
<br />
Modes are extremely powerful when applied to text. However, they can be applied to configuration problems as well. A user wanted to generate different versions of the same file with different fonts:<br />
<texcode><br />
\startmode[palatino]<br />
\usetypescript[adobekb][8r]<br />
\usetypescript[palatino][8r]<br />
\setupbodyfont[palatino,12pt]<br />
\stopmode<br />
<br />
\startmode[times]<br />
\usetypescript[adobekb][8r]<br />
\usetypescript[postscript][8r]<br />
\setupbodyfont[postscript,12pt]<br />
\stopmode<br />
<br />
\starttext<br />
\input knuth<br />
\showfontstrip<br />
\stoptext<br />
</texcode><br />
<br />
And run with one of the following:<br />
<pre><br />
texexec --pdf --mode=palatino filename<br />
texexec --pdf --mode=times filename<br />
</pre><br />
<br />
If you want to enable some mode(s) without changing the command line (e.g. because you use some TeX GUI), you can use<br />
<cmd>enablemode</cmd><tt>[mymode]</tt> in your source. Put this before you load your environment! You can even enable several modes at once like <tt>[a4,print]</tt>.<br />
<br />
== First-run-mode: Doing things only once ==<br />
<br />
When you need to call external programs to process some of your data and return you some results, you probaly want to do that only once (instead of three times, if ConTeXt needs three runs). Here's how you can do it:<br />
<br />
<texcode><br />
\doifmode{*\v!first}{%<br />
% external program which creates a file figure1.ps<br />
\executesystemcommand{some_external_program ...}<br />
% convert PS into PDF<br />
\executesystemcommand{texmfstart pstopdf figure1.ps}<br />
}<br />
<br />
% include the resulting PDF<br />
\externalfigure[figure1]<br />
</texcode><br />
<br />
<br />
[[Category:ConTeXt programming]]</div>84.27.244.22