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
    The error message and the resolution is listed in the caption package documentation, section A.4 "Errors". – Axel Sommerfeldt Nov 5 '18 at 9:54
4

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}
  • maybe i'm blind by i dont see the difference between the two code snippets... – Mikael Fremling Nov 5 '18 at 9:58
  • @MikaelFremling oops I put the corrected version in twice, I'll delete [zz] from the first one, thanks!!!! – David Carlisle Nov 5 '18 at 10:06
  • Very elegant solution. Thanks – Mikael Fremling Nov 6 '18 at 11:16

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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