Graphics, Figures & TablesSubfig: aligning wide captions and narrow images

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
jasonsewall
Posts: 1
Joined: Sat Nov 13, 2010 3:45 am

Subfig: aligning wide captions and narrow images

Post by jasonsewall »

When trying to put several very narrow images in a figure with subfloat, I'm having trouble getting the captions to look good. By default, they are flowed inside a box the same width as the images, which looks bad. If I tweak the width of the caption via \captionsetup, the each caption and image pair is no longer aligned (horizontally)

Example:

I have a new really tall, narrow image, like so:

Code: Select all

$ ppmpat -squig 50 1000 | pnmtopng > squig.png
I have a .tex file like so:

Code: Select all

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\pagestyle{empty}
\begin{document}
\begin{figure}%
  \centering%
  \subfloat[This is a pretty long caption for such a narrow image, but I need to say a lot!]{\includegraphics[height=8in]{squig.png}}%
  \hspace{1.5in}%
  \subfloat[This is also a pretty long caption for such a narrow image, but I need to say a lot!]{\includegraphics[height=8in]{squig.png}}%
\end{figure}
\end{document}
Long, narrow captions too, obviously a problem. So, I add

Code: Select all

\captionsetup[subfloat]{width=1.25in,justification=centering}%
But that doesn't seem to fix the problem. It looks like \includegraphics assumes the image will take up the whole box, so it doesn't center it.

Adding

Code: Select all

\hspace{1cm}
just before the \includegraphics makes things look better, but that's not very satisfying.

Any thoughts?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Subfig: aligning wide captions and narrow images

Post by sommerfee »

jasonsewall wrote:When trying to put several very narrow images in a figure with subfloat, I'm having trouble getting the captions to look good. By default, they are flowed inside a box the same width as the images, which looks bad. If I tweak the width of the caption via \captionsetup, the each caption and image pair is no longer aligned (horizontally)
I have two solutions for this in mind:

1. Put the images in a parbox where you can provide a width parameter.

2. When using the subcaption package and \subcaptionbox (instead of subfig package and \subfloat) one can alter the width of the \subcaptionboxes. See subcaption manual for an example.

Axel
Post Reply