1

Here is an effect i've irritated me on for a while.

When creating a figure environment with a caption like the one below

\begin{figure}[ht]
%%%Some figure
\caption{Some text
some more text

some text after a double line break}
\end{figure}

latex throws an error if I leave any line empty.

pdfTeX warning: pdflatex (file my_file.pdf): PDF inclusion: multiple pdfs with page group included in a single page >] Runaway argument? {Some text some more text ! Paragraph ended before \caption@prepareanchor was complete. \par l.xxx some text after a double line break}

My simple and maybe naive question is, why is this? Can one get around it except by adding a comment '%' in the gap of the empty line?

1
  • 1
    The error message and the resolution is listed in the caption package documentation, section A.4 "Errors".
    – user2574
    Nov 5, 2018 at 9:54

1 Answer 1

5

The error from

\documentclass{article}

\begin{document}

\begin{figure}[ht]
%%%Some figure
\caption{Some text
some more text

some text after a double line break}
\end{figure}
\end{document}

is

! Paragraph ended before \addcontentsline was complete.

because the standard table of contents code is not set up for multi-paragraph captions, so you can supply a short version for the toc:

\documentclass{article}

\begin{document}

\begin{figure}[ht]
%%%Some figure
\caption[zz]{Some text
some more text

some text after a double line break}
\end{figure}
\end{document}
6
  • 1
    maybe i'm blind by i dont see the difference between the two code snippets... Nov 5, 2018 at 9:58
  • 1
    @MikaelFremling oops I put the corrected version in twice, I'll delete [zz] from the first one, thanks!!!! Nov 5, 2018 at 10:06
  • Hi @MikaelFremling I am getting the same error and unfortunetely couldn't get the resolution, although this answer is accepted. I like putting some lines among different parts in latex but do not like getting these runaway argument errors. Can you please help? May 30, 2022 at 10:29
  • 1
    @Ferda-Ozdemir-Sonmez "I like putting some lines among different parts in latex " sorry that is saying "I like adding syntax errors but do not like the error messages" White space in TeX plays a specific syntactic role and can't just be added in random places. May 30, 2022 at 13:11
  • @Ferda-Ozdemir-Sonmez the easy solution is to put "%%" on every empty line. This is since latex simply ignores the lines then. May 30, 2022 at 13:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .