[texhax] variable number of columns in a longtable

Uwe Lueck uwe.lueck at web.de
Fri May 9 20:39:07 CEST 2008


Thanks for the interesting question, Susan -- I can only guess something right now: 

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.
[...]
--------------------
[...] 
> \makeatletter
> \newif\if at SHORT
> % only the short column (does not work):
> %\@SHORTtrue
> % two columns instead (seems to work):
> \@SHORTfalse
> 
> \if at SHORT\longtable{|l|l|}\else\longtable{|l|l|l|}\fi
> \hline
> \endhead
> \endfoot
> main column
> & \if at SHORT
>     only one additional column
>   \else
>       first  additional column
>     & second additional column
>   \fi
> \\\hline
> \endlongtable
> \end{document}
> ---------------

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. 

I dare to become bold and unhumble, but thus I might convince you 
that my solution is well-tested, namely with more than three dozens of tables in a 
critical editions I'm working for (volume for German Copernicus Complete Edition). 

My simple solution to hide `&' is fooling TeX by making `&' active and expanding to  
to TeX's original `&'. The following snippet from my 

    http://www.tex.ac.uk/tex-archive/macros/latex/contrib/lineno/edtable.sty

may make clear how to exactly (I also omit confusing lines): 

% Change ampersand at \Anote etc.: (wizard interface) 
%% 2003/10/31. 
% & is changed by \Anote etc. \begingroup 
% ---Global change seems to break table setup. 
\begingroup 
\gdef\@ET at hideamps{\catcode`\&\active}
\@ET at hideamps 
\gdef\@ET at ampnotes{% 
  \let&\@ET at hideamp 
  \let\@ET at EN@rnote\@EN at note 
  \def\@EN at note{\@ET at hideamps\@ET at EN@rnote}%
  \let\@ET at EN@rnotelb\@EN at notelabel 
  \def\@EN at notelabel{\@ET at hideamps\@ET at EN@rnotelb}%
} 
\endgroup 
\def\@ET at hideamp{&}

HTH -- Uwe. 


More information about the texhax mailing list