# How to add line break to caption without using caption package

I wish to add a line break to a caption, but I would wish to avoid adding of caption package. Is it possible?

\documentclass{article}
\usepackage[format=plain,
justification=raggedright,singlelinecheck=false]{caption}
\begin{document}
\begin{figure}
\caption{This is the caption\\ This is the second line}
\end{figure}
\end{document}

• Why don't you want to use caption package? Mar 9, 2013 at 3:31
• @hpesoj626 it's related to this question:tex.stackexchange.com/questions/101424/… Mar 9, 2013 at 3:37
• Unless you specifically need a linebreak I suggest you make two paragraphs by adding a blank line. Sep 24, 2018 at 15:31

\documentclass{article}
\begin{document}
\begin{figure}
\caption[caption]{This is the caption\\\hspace{\textwidth}This is the second line}
\end{figure}

\end{document}


The reason why \\ does not work originally is that the caption is small enough to fit on one line. The default caption setting first sets the caption in an mbox and if that is less than the line width that box is centred. Otherwise that box is discarded and the caption is re-set in a parbox. On the first setting \\ does nothing as it is always a no-op in such a box, on the second setting (if it is used) then \\ starts a new line. So all you have to do is make sure that the first setting is not used, as the space at the start of a line is discarded, it doesn't really matter how big the space is, so long as the total natural width of the whole caption is bigger than \textwidth.

• I think the \\ can be omitted? Mar 9, 2013 at 12:10
• @YiannisLazarides no see comment to Hendrick (it sort of works in this case but you get an overfull box) but in general you need \\  as the setting is not raggedright by default) Mar 9, 2013 at 12:15
• @David: Wow, great explanation, thank you very much! Mar 9, 2013 at 20:07
• In an Overleaf document I was unable to include \\, but the hspace worked nicely. It used IEEEtran.cls (packages [utf8]inputenc, framed, booktabs, hyperref, wrapfig, tikz, todonotes, regexpatch, xcolor, listings). The error was: Argument of \Hy@tempa has an extra }. <inserted text> \par l.631 .... Apr 7, 2017 at 21:17
• Nice answer. I defined a new command like so \newcommand\nextline{\\*\hspace{\textwidth}} with the star version of \\* to prevent a new page. Reasonable? Sep 18, 2018 at 13:39

The problem with using \\ in \caption{..} (a single mandatory argument) is that this defaults to \caption[..]{..} (optional + mandatory), and \\ is problematic in the optional argument. If you specify an alternative non-\\ optional argument, then it's okay, but \\ is made "useless" or has no effect. You could use a tabular to set the argument:

\documentclass{article}
\begin{document}
\begin{figure}
\caption[This is the caption; This is the second line]
{\tabular[t]{@{}l@{}}This is the caption \\ This is the second line\endtabular}
\end{figure}
\end{document}


Of course, if you don't need the optional argument (since you might not be using a \listoftables), just use an empty optional argument. Without more context of the requirement, I'm not sure how useful it might be.

• I think this is the prettiest option. Jul 22 at 22:19

Not sure why, but a \protect\linebreak works in the boxhandler package, but not in the \caption command.

\documentclass{article}
\usepackage{boxhandler}
\begin{document}

\bxfigure{Caption goes \protect\linebreak here}
{\fbox{Goodbye, very, very, very cruel world}}

\begin{figure}
\begin{center}
\fbox{Goodbye, very, very, very cruel world}
\caption{Caption goes \protect\linebreak here}
\end{center}
\end{figure}

\end{document}


One alternative is a minipage with \\ in the long caption. Note that in this way, the sort caption (between []) is not longer optional but as mandatory argument. If you want also a line break in the list of figures, simply use a \newline in the sort caption:

Edit: As Werner noted, the width of minipage must be less than \linewidth to avoid problems (now corrected in the MWE) or use varwidth package)

\documentclass{article}
\begin{document}
\listoffigures
\begin{figure}
\centering
\caption
[This is the caption \newline This is the second line]
{\begin{minipage}[t]{.8\linewidth}This is the caption \\This is the second line \end{minipage}}
\end{figure}
\end{document}

• This probably was accompanied by a bad box...
– Werner
Mar 9, 2013 at 6:27
• @Werner, what do you mean by "bad box" is the "Overfull \hbox" warning? How dangerous is it really?
– Fran
Mar 9, 2013 at 7:13
• Since you're setting the contents in a box, if the figure name + number + first line of caption > \textwidth, it will spill over the margin visually. While that may never happen, the box will necessarily push the caption to the left (always) because of its size. In this instance it would be better to use varwidth.
– Werner
Mar 9, 2013 at 15:34
• As usual you're right. Funnily, I really did a first draft with varwidth, but then I thought that if he wanted a solution without caption package, he would not want a solution using another package and tested that original minipage worked also in the MWE.
– Fran
Mar 9, 2013 at 18:52

Alternatively, you can use \protect\linebreak, also without caption package.

For a short caption text, it works the same as \\\hspace{\textwidth}. However, it can be a better solution, if your caption text is longer and without the line break would occupy more than one line and you want it to be stretched to fill the line.

Example:

    \documentclass{article}
\begin{document}
\begin{figure}
\caption[caption]{This is the first line of a caption text that \\\hspace{\textwidth} without the
linebreak would occupy more than one line and it goes and it goes}
\end{figure}
\begin{figure}
\caption{This is the first line of a caption text that \protect\linebreak without the
linebreak would occupy more than one line and it goes and it goes}
\end{figure}
\end{document}


• Welcome to tex.sx. Jan 25, 2020 at 15:11
• This doesn't work for me. Do you use the... caption package in your first example? Jun 20, 2020 at 23:41
• Thanks, I corrected the code for first example (\\\hspace.. instead of "\\"), so that it works without caption package. Jun 27, 2020 at 13:31