3

In this example I have issue with \par command within tkz-tab tabular

! Paragraph ended before \\tkzTabLine was complete.
<to be read again> 
                   \par 
l.27 \tkzTabLine{,\vcenter{\hsize3cm $x$ \par
                                               $f(x)$},} % <---- here
?

I need to add multiline text in \tkzTabLine

\documentclass[12pt]{article}
\usepackage{tkz-tab}
\begin{document}

$\vcenter{\hsize3cm $x$ \par $f(x)$}$

\bigskip

\begin{tikzpicture}
\tkzTabInit {$x$ / 1 ,$f(x)$ /1}%
{$-5$,$-3$}
\tkzTabLine{,\vcenter{\hsize3cm $x$ \par  $f(x)$},} % <---- here 
\end{tikzpicture}

\end{document}
  • 2
    Try \endgraf instead of \par (they are the same thing, just different names). – Phelype Oleinik Jan 22 at 19:31
  • Thank's @PhelypeOleinik why \par do not work, and what is the difference with \endgraph ? – Salim Bou Jan 22 at 19:35
  • 2
    as Phelype says, the only difference is that it is not called \par. \par (a blank line) is not allowed in many constructs as a means of avoiding missing closing delimiters wrecking an entire document, an error is thrown at the end of the paragraph. – David Carlisle Jan 22 at 19:38
  • It's a way of TeX detecting if you forgot a } in the argument of a macro (for example, define \def\test#1{(#1)} and then use \test{a\par b} or \test{a<newline><newline>b}, and then try \long\def\test#1{(#1)}). \tkzTabLine is defined as a short macro (that is, without the \long prefix), so using \par as the argument is an error. \endgraf is the same thing as \par (defined with \let\endgraf=\par), but it has a different name, so it's okay. – Phelype Oleinik Jan 22 at 19:40
  • @PhelypeOleinik please can you add an answer for the issue. – Salim Bou Jan 22 at 19:56
5

At the time TeX was written there wasn't too many text editors with brace-matching features to catch a } you forgot somewhere, so Knuth build some ways of checking if you forgot a } before the a macro tried to grab the rest of the input file as argument. Apart from David's favourite, \outer, a macro can also be short or long.

A short macro can be defined as simply as:

\def\test#1{(#1)}

but then if you forget a }:

\test{a % missing } here

boom!}

TeX will raise that exact same error:

Runaway argument?
{a 
! Paragraph ended before \test was complete.
<to be read again> 
                   \par 
l.3 

?

The same macro call would not raise that error if you defined \test as a long macro:

\long\def\test#1{(#1)}

However TeX's scanner does not look for something that means a paragraph break, it just looks for a \par token, so LaTeX (and also plain TeX) provides you with \endgraf, which is a copy of \par defined as:

\let\endgraf=\par

You could also trick TeX by using \csname par\endcsname instead, or something else that would hide the \par token.


LaTeX's \newcommand defines a long macro by default, so if you do \newcommand\test[1]{(#1)}, the example above will work. \tkzTabLine, however, is defined with \newcommand*, which does a short \def (perhaps there's a good reason for who wrote that package to make it short; I didn't check).

Just for completeness, if you are defining the macro yourself and you are using xparse, then you need the + modifier to make the argument long, like in:

\NewDocumentCommand \test {+m} {(#1)}
  • 1
    I should downvote for the \outer comment:-) – David Carlisle Jan 22 at 20:22
  • @DavidCarlisle But then it would be an \outer\downvote, and we don't support that in LaTeX ;-) – Phelype Oleinik Jan 22 at 20:27
3

Phelype explained why \par is forbidden there. But there is a simpler way out.

\documentclass[12pt]{article}
\usepackage{tkz-tab,array}
\begin{document}

\begin{tikzpicture}
\tkzTabInit {$x$ / 1 ,$f(x)$ /1}%
{$-5$,$-3$}
\tkzTabLine{,\parbox{3cm}{$x$\\ $f(x)$},}
\end{tikzpicture}

\end{document}

enter image description here

  • Actually compiling the code and seeing what it does is said to be a good idea ;-) – Phelype Oleinik Jan 22 at 23:37

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