## LaTeX forum ⇒ Graphics, Figures & Tables ⇒ Captions not centered Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
norox
Posts: 3
Joined: Fri Aug 30, 2013 10:34 am

### Captions not centered

Dear TeX Community,

I am having difficulties getting my captions centered underneath my graphs. I understand captions should be centered automatically. The funny thing is, if the caption is short enough it gets centered. However for example the following one does not:

\begin{figure}[]\centering\includegraphics[scale=0.45]{mm,m1,mb,iff}\caption{Interesting rates during the crisis \\ \textit{Source: authors graph based on FRED data}}\label{mmm1iff}\end{figure}

Can anyone help me fix this?

Best,

norox
Last edited by cgnieder on Fri Aug 30, 2013 10:42 am, edited 1 time in total.

Tags:

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
For an adequate problem description please prepare a self-contained and minimal example in order to avoid speculations and guesswork.

Nevertheless, if I supplement your code snippet to a complete document, I can reproduce the problem. It seems to be better if you use the caption package and typeset the source of your figure as a second caption which is unnumbered.
\documentclass[11pt]{article}\usepackage[T1]{fontenc}\usepackage[demo]{graphicx} % delete demo option in actual document\usepackage{caption} \begin{document}   \begin{figure}[!ht]     \centering     \includegraphics[scale=0.45]{mmm1mbiff}     \caption{Interesting rates during the crisis}     \captionsetup{aboveskip=0pt,font=it}     \caption*{Source: authors graph based on FRED data}     \label{fig:mmm1mbiff}   \end{figure}\end{document}

Use this method wherever you have to add a source to a figure.

Best regards and welcome to the board
Thorsten
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

norox
Posts: 3
Joined: Fri Aug 30, 2013 10:34 am
thx problem solved!

cgnieder
Site Moderator
Posts: 1993
Joined: Sat Apr 16, 2011 7:27 pm
Captions are only centered if they are shorter than one line:

\documentclass[11pt]{article}\usepackage[T1]{fontenc}\usepackage[demo]{graphicx} % delete demo option in actual document \begin{document}   \begin{figure}[!ht]     \centering     \includegraphics[scale=0.45]{mmm1mbiff}     \caption{short}     \label{fig:short}   \end{figure}   \begin{figure}[!ht]     \centering     \includegraphics[scale=0.45]{mmm1mbiff}     \caption{this one is so long that it does not fit into a single line any more so it spans two lines}     \label{fig:long}   \end{figure}\end{document}

What's more: line breaks are not natively supported:
\documentclass[11pt]{article}\usepackage[T1]{fontenc}\usepackage[demo]{graphicx} % delete demo option in actual document \begin{document}   \begin{figure}[!ht]     \centering     \includegraphics[scale=0.45]{mmm1mbiff}     \caption{I want this to\\ be two lines}     \label{fig:error}   \end{figure}   \begin{figure}[!ht]     \centering     \includegraphics[scale=0.45]{mmm1mbiff}     \caption{I want this to\newline be two lines}     \label{fig:vanish}   \end{figure}\end{document}

However, the caption package supports line breaks in captions. If the complete caption is short enough (and the option singlelinecheck=on is active which is the default) they even are centered without any further setup as long as you use \\ and not \newline:

\documentclass[11pt]{article}\usepackage[T1]{fontenc}\usepackage[demo]{graphicx} % delete demo option in actual document\usepackage{caption} \begin{document}   \begin{figure}[!ht]     \centering     \includegraphics[scale=0.45]{mmm1mbiff}     \caption{I want this to\\ be two lines}     \label{fig:works}   \end{figure}\end{document}

In your original code this does not work, because the caption is too long and the lines are left-aligned. However, caption has a solution for this, too: \captionsetup{justification=centering}. You can use this for all captions by placing it in the preamble or for one caption only by placing it in the {figure} environment where you want this:

\documentclass[11pt]{article}\usepackage[T1]{fontenc}\usepackage[demo]{graphicx} % delete demo option in actual document\usepackage{caption}\captionsetup{justification=centering}\newcommand*\picsource[1]{\textit{#1}}\begin{document}     \begin{figure}[]     \centering     \includegraphics[scale=0.45]{mm,m1,mb,iff}     \caption{%       Interesting rates during the crisis \\       \picsource{Source: authors graph based on FRED data}}     \label{mmm1iff}     \end{figure}\end{document}

In this code I also replaced the \textit with a semantically more meaningful command.

Regards
site moderator & package author