[texhax] variable number of columns in a longtable
Uwe Lueck
uwe.lueck at web.de
Sat May 10 02:17:36 CEST 2008
Susan Dittmar <SDittmar at eureca.de> schrieb am 08.05.2008 13:33:18:
> I would like to use the same document for two output formats, both
> generated with LaTeX. One of the differences is the number of columns in
> one longtable.
Sorry, I keep my diagnosis from before, but I hardly hinted at a ready solution --
I am presenting one here.
Diagnosis was: "Look at The TeXbook: AFAIK the `&'s in a TeX array are the tokens that
TeX looks at first for in an \halign. Therefore you can't hide them by any \if. "
Very simple solution (after hours of trying along my former way):
\newcommand{\HiddenAmp}{&}
\newcommand{\longcolumn}[1]{\if at SHORT\else \HiddenAmp #1\fi}
This ensures that TeX's \halign discovers the cell delimiter only after the \if
has been expanded.
You haven't specified which column is the extra one, below you can choose via `%'
whether it is the second or the third one (tested).
--------------------
\documentclass{scrartcl}
\usepackage{longtable}
\begin{document}
\makeatletter
\newif\if at SHORT
%\@SHORTtrue
\@SHORTfalse
\newcommand{\HiddenAmp}{&}
\newcommand{\longcolumn}[1]{\if at SHORT\else \HiddenAmp #1\fi}
\if at SHORT\longtable{|l|l|}\else\longtable{|l|l|l|}\fi
\hline
\endhead
\endfoot
first certain column
\longcolumn{additional column}
&
second certain column
% \longcolumn{additional column}
\\\hline
\endlongtable
\end{document}
---------------
HTH -- Uwe.
More information about the texhax
mailing list