4

I can't quite figure it out. I'd like to be able to process the entries in a table, but > and < aren't (quite) acting as I expect them to. Here's a repro:

\documentclass{article}
\usepackage{array}
\newcolumntype{Z}{>{\foo}c<{\bar}}
\def\foo#1\bar{foo #1 bar}
\begin{document}
\begin{tabular}{ZZZZ}
A & B & C & D \\
E & F & G & H
\end{tabular}
\end{document}

When I run this through xelatex I get the following output:

$ xelatex repro
This is XeTeX, Version 3.14159265-2.6-0.99998 (TeX Live 2017/MacPorts 2017_0) (preloaded format=xelatex)
 restricted \write18 enabled.
entering extended mode
(./repro.tex
LaTeX2e <2017-04-15>
Babel <3.10> and hyphenation patterns for 5 language(s) loaded.
(/opt/local/share/texmf-texlive/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/opt/local/share/texmf-texlive/tex/latex/base/size10.clo))
(/opt/local/share/texmf-texlive/tex/latex/tools/array.sty) (./repro.aux)
! Misplaced \cr.
\reserved@c ->\ifnum 0=`{}\fi \cr 

l.8 E &
        F & G & H
? 

Oddly, it works as I expect if I use {ZZcc} as the preamble, but that must surely be only lucky. How do I use > and < column specifiers to process table entries?

ruds
  • 143

1 Answers1

3

The last column is not so easy to catch, because it is not ended by &. Then \foo gets all the stuff up to the next & including \\.

A workaround is to add a dummy last column:

\documentclass{article}
\usepackage{array}
\newcolumntype{Z}{>{\foo}c<{\bar}}
\def\foo#1\bar{foo #1 bar}
\begin{document}
\begin{tabular}{ZZZZ@{}c}
A & B & C & D &\\
E & F & G & H &
\end{tabular}
\end{document}

Result

Heiko Oberdiek
  • 271,626
  • Thanks, that explains it! Seems like something that should be mentioned in Mittelbach and Carlisle's "A new implementation of LaTeX's tabular and array environment" but at least now I understand the problem. – ruds Jul 31 '17 at 19:48