Graphics, Figures & TablesAlignment of captions

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
squall83
Posts: 5
Joined: Thu Nov 26, 2009 10:38 am

Alignment of captions

Post by squall83 »

Hello everyone,

I am looking for a way to change the caption alignment. The alignment seems to be centered for short texts and left-aligned for long ones as can be seen in the following example:

Code: Select all

\documentclass[]{scrbook}
\usepackage{graphicx}
\usepackage{caption}

\begin{document}

\begin{figure}
  \centering
  \includegraphics[scale=0.5]{Testimage.png}
  \caption{text,\\text}
\end{figure}

\begin{figure}
  \centering
  \includegraphics[scale=0.5]{Testimage.png}
  \caption{a much much much much much longer text,\\a much much much much much longer text}
\end{figure}

\end{document}
In my document I use minipages and subcaptions to group similar images and since some descriptions are shorter than others, so the alignment changes all the time, which looks bad. My primary wish is to always get the layout you get from the long texts (i.e. the second image in the example), because I like it if all lines start at the same column. It would be ideal if I could get that layout without everything flushing to the left, i.e. the first line should still be centered.

Out of curiosity I'd also like to know if there is a way to change the alignment arbitrarily even though I probably won't do that. ^^

Kind regards,
Alex

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
TikZ book
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Alignment of captions

Post by gmedina »

Hi,

the caption package offers some options to customise the alignment (and many other attributes of captions). For further options, you could refer to the floatrow or hvfloat packages.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
squall83
Posts: 5
Joined: Thu Nov 26, 2009 10:38 am

Re: Alignment of captions

Post by squall83 »

Thanks, but the command I'd like to use doesn't work. I tried to insert

\captionsetup{format=hang}

either before my figures or inside my figures. I also tried

\captionsetup{format=plain}
\captionsetup{singlelinecheck=off}

just out of curiosity, but only the 2nd command worked. The format commands are being ignored. What am I missing here?


edit: Since I'm working with minipages and subcaption just using \captionsetup{singlelinecheck=off} solved my current problem, but if I had used a normal figure with the caption command the captionsetup would've pushed the caption too far to the left. Using a small enough minipage can prevent this effect but this is just a workaround, so I'd like to know if there is a better way to do this.
Post Reply