Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm having problems with conflicting width requirements for subcaptions on subfloats that are horizontal versus vertical. I've spent considerable time searching here and more broadly, poring over the subfig package documentation, etc, and I figured out that the problem is with the widths.

For the subfloats that are arranged horizontally, the subcaptions need to be 3 inches wide; for the subfloats that are arranged vertically, the subcaptions need to be 5 inches wide. If I specify a 3in subcaption width, the subcaptions for the 5in images look awful. If I specify anything over a 3in subcaption width, the subcaptions for the 3in images are offset to the right and run off the page. When I was not specifying caption widths at all, the subfloat subcaptions became very narrow and weird.

I'm not sure how to resolve this; both subfloat arrangements need to be included in the same document. I realize that a custom environment might be in order, but don't have the first idea of how to construct something for this purpose.

Here is the example MWE (to the best of my ability, it's a first try...)

\documentclass[11pt]{article}
\usepackage{tabulary}
\usepackage{ctable}
\usepackage{epsfig}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{multirow}
\usepackage{amssymb}
\usepackage{subfig}

\captionsetup[subfloat]{
nearskip=20pt,
width=3in
}

\captionsetup{
format=hang,
width=5.5in,
}

\begin{document}

\title{Title}
\author{Me}
\date{\today}
\maketitle

Vertically arranged images:

\begin{figure}[htbp]
\begin{center}
\subfloat[Calibration image on the front of the view guide.]{\label{fig:vizcardfront}}\includegraphics[width=5in]{figures/viewcardfront.jpg}
\subfloat[Data submission form on the back of the view guide.]{\label{fig:vizcardback}}\includegraphics[width=5in]{figures/viewcardback.jpg}
\caption{The visibility monitoring view guide.}
\label{fig:viewcard}
\end{center}
\end{figure}

Horizontally arranged images:

\begin{figure}[htpb]
\begin{center}
\subfloat[A plantcam at a monitoring plot.]{\label{fig:plantcam}}{\includegraphics[width=3in]{figures/plantcam.jpg}}
\hfill
\subfloat[A HOBO$\textsuperscript{\textregistered}$ data logger for air and soil data.]{\label{fig:logger}}{\includegraphics[width=3in]{figures/logger.jpg}}
\caption{Automatic data collection instruments.}
\label{fig:autodata}
\end{center}
\end{figure}

\end{document}

Any assistance will be very much appreciated!

share|improve this question
1  
Have you looked at the subcaption package? It provides the subfigure environment which takes a width as its first argument. –  cmhughes Jan 24 '12 at 3:33

1 Answer 1

Here are some suggestions to fix your current situation:

  • Note the subfloat notation:

    \subfloat[<LoF>][<subcaption>]{<body>}
    

    Since your <body> consisted only of a \label command, the <subcaption> (actually, the <LoF> entry) had to wrap around something that is "very thin", causing it to not typeset properly. See page 4 of the subfig documentation for an explanation of this.

  • Also, the \label should be included in the <body>.

  • If you put the entire \subfloat within a fixed-width environment, the caption will wrap according to that width. This can be achieved via a minipage environment, for example. In the following minimal example, I've defined two new commands:

    \vertfig[<subcaption>]{<body>}% For vertical figure placement
    \horizfig[<subcaption>]{<body>}% For horizontal figure placement
    

    that you can use to replace the traditional \subfloat. \vertfig typesets its contents in a 5in-width minipage, while \horizfig does so in a 3in-width minipage. Both dropped the second optional argument of \subfloat[..][..]{...}, since it didn't seem to matter to you.

    As you can see, no fixed-width \captionsetup is required, since the captions wrap to the box they're contained in.

Different subfloats with different widths

\documentclass[11pt]{article}
\usepackage[a3paper]{geometry}% http://ctan.org/pkg/geometry
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
%\usepackage{caption}% http://ctan.org/pkg/caption
\usepackage{subfig}% http://ctan.org/pkg/subfig
\newsubfloat{figure}
\pagestyle{empty}% No header/footer
\newcommand{\vertfig}[2][]{%
  \begin{minipage}{5in}\subfloat[#1]{#2}\end{minipage}}
\newcommand{\horizfig}[2][]{%
  \begin{minipage}{3in}\subfloat[#1]{#2}\end{minipage}}
\begin{document}

\begin{figure}[ht]
  \centering
  \vertfig% \subfloat
    [This is probably the biggest tiger you will ever see in your life.
     The caption associated with this subfloat should span more than one
     line even though the width of the contents is 5in.]
    {\includegraphics[width=5in]{tiger}\label{fig:vizcardfront}}

  \vertfig% \subfloat
    [Data submission form on the back of the view guide.]
    {\includegraphics[width=5in]{tiger}\label{fig:vizcardback}}
  \caption{The visibility monitoring view guide.}\label{fig:viewcard}
\end{figure}

\begin{figure}[ht]
  \centering
  \horizfig%\subfloat
    [Here is another picture of the tiger, this time a little smaller.
     It is still very fierce-looking, right?]
    {\includegraphics[width=3in]{tiger}\label{fig:plantcam}}
  \hfill
  \horizfig%\subfloat
    [A HOBO$\textsuperscript{\textregistered}$ data logger for air and soil data.]
    {\includegraphics[width=3in]{tiger}\label{fig:logger}}
  \caption{Automatic data collection instruments.}\label{fig:autodata}
\end{figure}

\end{document}

geometry was merely used to set the paper size to a3paper.

share|improve this answer
    
Marvelous, thanks @Werner! The minipages did the trick and all works very nicely. Now I just have to go through all the other docs and update them accordingly - a very small price to pay for having it lay out properly. Doubtless the issues with the <body> construction are from copying a poor example; I often have a hard time finding a usable example (they're never exactly what I need) and the documentation doesn't always remedy that problem for me. –  Andrea Wiggins Jan 24 '12 at 13:37
    
What does LoF mean? –  moose Aug 18 at 18:34
    
@moose: LoF = List of Figures; LoT = List of Tables; ToC = Table of Contents. –  Werner Aug 20 at 5:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.