3

I use ctable for my tables, and I'd like to use numprint's autoformatting column types as well. Unfortunately, if the last column of the tabular is a numprint column, it breaks ctable's convenient macros for rules. The problem appears to be that the numprint column has to resort to some shenanigans to detect the end of a column.

This works fine:

\documentclass{article}

\usepackage{numprint}
\newcommand\foo{\\}

\begin{document}
\begin{tabular}{N{3}{0}}
    42 \\
    1
\end{tabular}
\end{document}

But this fails to compile with the error "! Misplaced \cr." and the code snippet accompanying it is: \reserved@c ->\ifnum 0=`{}\fi \cr

\documentclass{article}

\usepackage{numprint}
\newcommand\foo{\\}

\begin{document}
\begin{tabular}{N{3}{0}}
    42 \foo
    1
\end{tabular}
\end{document}

I've tried looking at the numprint code, but I'm not clever enough to figure out how to solve this. Is there something I can do about this, or is it just not possible to make numprint work with other row terminators than \\?

  • You can use \tabularnewline instead of \\ to break the line, as in \begin{tabular}{N{3}{0}} 42 \tabularnewline 1 \end{tabular}. I don't know if that would help ctable or not. – Steven B. Segletes Apr 10 '14 at 15:04
  • 1
    Use \relax\foo (or some other unexpandable macro like \protect\foo). – Werner Apr 10 '14 at 16:01
  • \relax before the terminator works great. Thanks! – arnsholt Apr 10 '14 at 16:41
4

Use \relax\foo (or some other unexpandable macro):

\documentclass{article}

\usepackage{numprint}
\newcommand\foo{\\}

\begin{document}
\begin{tabular}{N{3}{0}}
    42 \relax\foo
    1
\end{tabular}
\end{document}

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.