1

I have a custom counter \myCounter set to, say 3. I need to produce such a table:

enter image description here

The following code does not work:

\documentclass{article}

\newcounter{myCounter}
\setcounter{myCounter}{3}

\begin{document}

\begin{tabular}{cl*{\value{myCounter}{c}c}}
& \multicolumn{\value{myCounter}}{c}
    {agglutinate} & \\\cline{2-\value{myCounter+1}} % Here is the naive part
init & content1 & content2 & content3 & end \\
\end{tabular}

\end{document}

How should I perform counter arithmetics within \cline?

  • Why do you show only a snippet instead of a full example people could compile directly? – Ulrike Fischer Feb 4 '16 at 16:04
  • Usually I would say \numexpr but with a fixed number of & this is not really useful, is it? – user31729 Feb 4 '16 at 16:06
  • @UlrikeFischer I do it in order to keep the question clear. Also because the snippet I show does not compile anyway. BTW I wished there was a way to compile LaTeX code inside the stack interface, just like you can get formulae within $$ in Maths SE. This way I would not have to insert a screenshot of my table. Is this possible? – iago-lito Feb 4 '16 at 16:09
  • 1
    It doesn't make the question clearer, it is simply a nuisance that I have to type \newcounter, \setcounter, \documentclass etc to try out a solution. And if you had to try out your example first you perhaps would have realized that there are brace errors beside the \cline-problem. – Ulrike Fischer Feb 4 '16 at 16:13
  • @UlrikeFischer You're right. `came from a good intention though. – iago-lito Feb 4 '16 at 16:17
2

Calculations can be done with \numexpr number1 operator number2, but in this case, the example is a little bit useless, since the number of & is fixed to use 3 columns (in between) anyway!

\documentclass{article}

\newcounter{myCounter}

\setcounter{myCounter}{3}
\begin{document}



\begin{tabular}{cl*{\value{myCounter}}{c}c}
  & \multicolumn{\value{myCounter}}{c}{agglutinate} & \tabularnewline
    \cline{2-{\numexpr\value{myCounter}+1}}
init & content1 & content2 & content3 & end \\
\end{tabular}

\end{document}

enter image description here

  • This is what I was looking for! Consider this as "half-useful". When I add a section to my document, I have to manually add a & and a contentN into the tabular environment, but the rest of the table automatically scales up ;) Cheers! – iago-lito Feb 4 '16 at 16:13
  • @Iago-lito: If contentX would be computable the whole approach would be much more usable ;-) – user31729 Feb 4 '16 at 16:19
  • Yupe. Unfortunately it is not. Even though I would love my computer to write this article for me while I'm having a chocolate. Hey, machines can't do everything, can they? ;) – iago-lito Feb 4 '16 at 16:21
  • @Iago-lito: Not yet :D – user31729 Feb 4 '16 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.