0

This is related to a previous question that was well answered by egreg. I would like to typeset the following without the vlines around cells (1,0) and (3,0):

enter image description here

Using the code below, would, in principle, do that. However, the \refstepcounter call before the \multicolumn gives an \omit related error, like in the previous question. Tried various things, but in general the question is, how to affect some logic per table row, in a single macro, when the first cell in that row is a \multicolumn given that, apparently, \multicolumn must be the first command in an expansion?

\documentclass{article}
\usepackage{longtable}

\newcounter{tablerowi} \NewExpandableDocumentCommand{\mc}{m}{\multicolumn{1}{l}{#1}} \NewExpandableDocumentCommand{\tableRow}{smm}{% \IfBooleanTF{#1}{% \mc{} & \mc{#3} & \mc{\thetablerowi} \ }{% \refstepcounter{tablerowi} \mc{#2} & \mc{#3} & \mc{\thetablerowi} \ } }

\begin{document} \begin{longtable}[c]{|p{2.5cm}|p{2.5cm}|p{2.5cm}|}
\hline month & name & month #\\hline \tableRow{November}{Election Day} \tableRow{November}{Thanksgiving} \tableRow{December}{Advent} \tableRow{December}{Christmas}\hline \end{longtable} \end{document}

1 Answers1

1

You already stated the problem in the question itself. There cannot be \refstepcounter{tablerowi} before \mc.

Workarounds: (weird but works)

%! TEX program = lualatex
\documentclass{article}
\usepackage{longtable}

\newcounter{tablerowi} \NewExpandableDocumentCommand{\mc}{m}{\multicolumn{1}{l}{#1}} \NewExpandableDocumentCommand{\tableRow}{smm}{% \IfBooleanTF{#1}{% \mc{} & \mc{#3} & \mc{\thetablerowi} \ }{% \mc{\refstepcounter{tablerowi}#2} & \mc{#3} & \mc{\thetablerowi} \ %\mc{#2}\refstepcounter{tablerowi} & \mc{#3} & \mc{\thetablerowi} \ % this works too as long as tablerowi is not used inside #2 } }

\begin{document} \begin{longtable}[c]{|p{2.5cm}|p{2.5cm}|p{2.5cm}|}
\hline month & name & month #\\hline \tableRow{November}{Election Day} \tableRow{November}{Thanksgiving} \tableRow{December}{Advent} \tableRow{December}{Christmas}\hline \end{longtable} \end{document}

user202729
  • 7,143