General ⇒ \newline (or equivalent) inside a \caption
-
- Posts: 2
- Joined: Mon Nov 17, 2008 3:34 am
\newline (or equivalent) inside a \caption
Hello,
I have done numerous searches on this forum for "inserting a new line in a caption" to no avail as too many terms are filtered out! I've tried both \\ and \newline but these do not seem to help. I have read the documentation for the package caption as well and can't seem to figure this. Any help would be greatly appreciated.
Thanks!
I have done numerous searches on this forum for "inserting a new line in a caption" to no avail as too many terms are filtered out! I've tried both \\ and \newline but these do not seem to help. I have read the documentation for the package caption as well and can't seem to figure this. Any help would be greatly appreciated.
Thanks!
NEW: TikZ book now 40% off at Amazon.com for a short time.

\newline (or equivalent) inside a \caption
Hello,
if your captions are longer than one line (without the line break), they will be set as a paragraph and you can use \\ freely. Otherwise, you have to stop LaTeX from centering short captions; how to do that depends on the document class you're using. If you want to use line breaks in captions, don't forget to specify a (possibly empty) short version, otherwise errors will occur.
if your captions are longer than one line (without the line break), they will be set as a paragraph and you can use \\ freely. Otherwise, you have to stop LaTeX from centering short captions; how to do that depends on the document class you're using. If you want to use line breaks in captions, don't forget to specify a (possibly empty) short version, otherwise errors will occur.
\newline (or equivalent) inside a \caption
Hi,
you can use justified as the justification option of the caption package, as the following simple example illustrates:
you can use justified as the justification option of the caption package, as the following simple example illustrates:
Code: Select all
Code, edit and compile here:
\documentclass{article}\usepackage{caption}\captionsetup{justification=justified}\usepackage{lipsum}%just to generate some text\begin{document}\begin{table}[!ht]\centering\begin{tabular}{cc}\hlinesome text & some text\\some text & some text\\\hline\end{tabular}\caption{A table with line changes\\ inside the caption.\\\lipsum[1]}\label{tab:test}\end{table}\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
\newline (or equivalent) inside a \caption
What exactly is the difference? I've just noticed that the caption package always allows line breaks inside captions, regardless of the chosen options—and "justified" is the default value for "justification". So it should be sufficient to include the caption package and give a short caption (without short caption, it never works, unless you \protect the line break):gmedina wrote:you can use justified as the justification option of the caption package, as the following simple example illustrates:
Code: Select all
Code, edit and compile here:
\documentclass{article}\usepackage{caption}\begin{document}\begin{table}[!ht]\centering\begin{tabular}{cc}\hlinesome text & some text\\some text & some text\\\hline\end{tabular}\caption[]{A table with line changes\\inside the caption.}\label{tab:test}\end{table}\end{document}
Last edited by phi on Mon Nov 17, 2008 11:12 am, edited 1 time in total.
\newline (or equivalent) inside a \caption
Yes, phi, you are right regarding the first part: it is enough to load the caption package: However, line breaks cause no problems even without protecting the line break or without using an optional argument:phi wrote:...So it should be sufficient to include the caption package and give a short caption (without short caption, it never works, unless you \protect the line break)
Code: Select all
Code, edit and compile here:
\documentclass{article}\usepackage{caption}\begin{document}\listoftables\begin{table}[!ht]\centering\begin{tabular}{cc}\hlinesome text & some text\\some text & some text\\\hline\end{tabular}\caption{A table with line changes\\inside the caption\\and no optional argument nor \texttt{protect}}\label{tab:test}\end{table}\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
\newline (or equivalent) inside a \caption
Your code produces dozens of errors when I try to compile it. Perhaps we have different versions of the class and packages? The beginning of my log file reads:gmedina wrote:However, line breaks cause no problems even without protecting the line break or without using an optional argument:
Code: Select all
This is pdfTeXk, Version 3.141592-1.40.3 (Web2C 7.5.6) (format=pdflatex 2008.10.30) 17 NOV 2008 11:23entering extended mode%&-line parsing enabled.**\nonstopmode \input{"/tmp/rr.tex"}(/tmp/rr.tex (/usr/share/texmf-texlive/tex/latex/base/article.clsDocument Class: article 2005/09/16 v1.4f Standard LaTeX document class(/usr/share/texmf-texlive/tex/latex/base/size10.cloFile: size10.clo 2005/09/16 v1.4f Standard LaTeX file (size option))\c@part=\count79\c@section=\count80\c@subsection=\count81\c@subsubsection=\count82\c@paragraph=\count83\c@subparagraph=\count84\c@figure=\count85\c@table=\count86\abovecaptionskip=\skip41\belowcaptionskip=\skip42\bibindent=\dimen102)(/usr/share/texmf-texlive/tex/latex/caption/caption.styPackage: caption 2007/01/07 v3.0k Customising captions (AR)(/usr/share/texmf-texlive/tex/latex/caption/caption3.styPackage: caption3 2007/01/07 v3.0k caption3 kernel (AR)(/usr/share/texmf-texlive/tex/latex/graphics/keyval.styPackage: keyval 1999/03/16 v1.13 key=value parser (DPC)\KV@toks@=\toks14)\captionmargin=\dimen103\captionmarginx=\dimen104\captionwidth=\dimen105\captionindent=\dimen106\captionparindent=\dimen107\captionhangindent=\dimen108))No file rr.aux.\openout1 = `rr.aux'.
\newline (or equivalent) inside a \caption
Hi,
You are using and old version of the caption package and that causes those errors. I would suggest you to update that package. The following excerpt from your log file shows that you use caption3 2007/01/07 version 3.0k:
As you can see your version of caption is not updated and that's why you are getting those errors.
My example code compiles OK in any system that uses a recent version of caption.
phi wrote:Your code produces dozens of errors when I try to compile it. Perhaps we have different versions of the class and packages?...
You are using and old version of the caption package and that causes those errors. I would suggest you to update that package. The following excerpt from your log file shows that you use caption3 2007/01/07 version 3.0k:
Here's the relevant part of the log file I got after compiling my example code, adding \listilesAs to get a list of the packages used and their versions:phi wrote: Document Class: article 2005/09/16 v1.4f Standard LaTeX document class
(/usr/share/texmf-texlive/tex/latex/base/size10.clo
File: size10.clo 2005/09/16 v1.4f Standard LaTeX file (size option)
(/usr/share/texmf-texlive/tex/latex/caption/caption.sty
Package: caption 2007/01/07 v3.0k Customising captions (AR)
(/usr/share/texmf-texlive/tex/latex/caption/caption3.sty
Package: caption3 2007/01/07 v3.0k caption3 kernel (AR)
(/usr/share/texmf-texlive/tex/latex/graphics/keyval.sty
Package: keyval 1999/03/16 v1.13 key=value parser (DPC)
\KV@toks@=\toks14
Code: Select all
*File List*article.cls 2005/09/16 v1.4f Standard LaTeX document classsize10.clo 2005/09/16 v1.4f Standard LaTeX file (size option)caption.sty 2008/08/02 v3.1i Customizing captions (AR)caption3.sty 2008/08/02 v3.1i caption3 kernel (AR)keyval.sty 1999/03/16 v1.13 key=value parser (DPC)***********
My example code compiles OK in any system that uses a recent version of caption.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Re: \newline (or equivalent) inside a \caption
OK, you're right, but I have the most recent system that is available in my distribution (TeXLive 2007). I won't update it simply because of this change. On the contrary, documents that compile on my system compile nearly nowhere else because nearly no one has a system from 2007 or later (really!). So my system is rather too new, not too old. 

-
- Posts: 2
- Joined: Mon Nov 17, 2008 3:34 am
Re: \newline (or equivalent) inside a \caption
Thanks for your help.
I added the caption package passing justification=centering to it as mentioned and it works fine. It is definitely worthy to reiterate that the optional short captions are a necessity and that \newline does not always perform the same function as \\ does (or at least I don't think it did for me).
I added the caption package passing justification=centering to it as mentioned and it works fine. It is definitely worthy to reiterate that the optional short captions are a necessity and that \newline does not always perform the same function as \\ does (or at least I don't think it did for me).
\newline (or equivalent) inside a \caption
No. The optional argument is not necessary. What is really necessary is to use an updated version of the caption package.thrillRseekR wrote:Thanks for your help.
I added the caption package passing justification=centering to it as mentioned and it works fine. It is definitely worthy to reiterate that the optional short captions are a necessity and that \newline does not always perform the same function as \\ does (or at least I don't think it did for me).
1,1,2,3,5,8,13,21,34,55,89,144,233,...