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 have a float with two subfloats:

A float with two subfloats

I want the circles to be vertically aligned from their top such as in the following figure. But I don't want the subcaptions to be placed above the subfloats but vertically aligned below as in the figure above.

A float with two subfloats with subcaptions above them

I'm not bound to any package in particular (even if I used subfig for this examples). I have tried http://gicl.cs.drexel.edu/people/tjkopena/wiki/pmwiki.php?n=SWAT.VerticallyAligningSubfigures, http://www.howtotex.com/tips-tricks/vertical-alignment-of-subfigures/ and http://stackoverflow.com/questions/2328403/vertical-alignment-of-subfigures-latex without success.

\documentclass{article}

\usepackage{tikz}
\usepackage{subfig}

%\captionsetup[subfloat]{position=top}% Uncomment this to generate the second figure

\begin{document}

\begin{figure}
\centering
\subfloat[Small circle]{%
  \begin{tikzpicture}
    \draw circle (1.25cm) {};
  \end{tikzpicture}%
}
\qquad
\subfloat[Big circle]{%
  \begin{tikzpicture}
    \draw circle (2cm) {};
  \end{tikzpicture}%
}
\caption{Circles}
\end{figure}

\end{document}
share|improve this question
    
Maybe tex.ac.uk/cgi-bin/texfaq2html?label=topgraph will help –  N.N. Sep 26 '11 at 9:53

3 Answers 3

A quick introductory remark: According to the latest edition of the l2tabu document, both the subfigure and subfig packages should no longer be used; instead, one should use the subcaption package (from the same author of the caption package).

The problem you describe might best be solved using the floatrow package, as it provides all kinds of ways of aligning both the contents of side-by-side (sub)figures and their respective captions. Unfortunately, I find the writing style of the package's manual rather hard to penetrate, so I wasn't able to come up with a working MWE. Hopefully you'll have better luck. :-)

share|improve this answer
    
Thanks for the tip! The floatrow manual was not an easy read but finally I got it working, see my answer. –  N.N. Sep 26 '11 at 20:02
    
I'm delighted that my tip turned out to be so useful! I'll keep your answer among my "favorites." :-) –  Mico Sep 26 '11 at 20:55
    
Why should the subfigure and subfig package no longer be used? Beside the hyperref support they are working fine and are well-documented. Furthermore they even work with document classes the caption package is not supporting - as opposite to the/my subcaption package. So IMHO l2tabu is wrong here. –  Axel Sommerfeldt Sep 27 '11 at 6:23
    
You ask an excellent question -- I suggest you take it up with the author(s) of the l2tabu document. To be honest, I was a bit surprised when I saw that claim in the latest issue of l2tabu, but I thought it may nevertheless be important information for some people. –  Mico Sep 27 '11 at 13:37

Not an automatic procedure, but not so difficult to use:

\documentclass{article}

\usepackage{tikz}
\usepackage{subfig}

\newcount\bsubfloatcount
\newtoks\bsubfloattoks
\newdimen\bsubfloatht

\makeatletter
\newcommand{\bsubfloat}[2][]{%
  \sbox\z@{#2}%
  \ifdim\bsubfloatht<\ht\z@
    \bsubfloatht=\ht\z@
  \fi
  \advance\bsubfloatcount\@ne
  \@namedef{bsubfloat\romannumeral\bsubfloatcount}{%
    \subfloat[#1]{\vbox to\bsubfloatht{\hbox{#2}\vfill}}}%
}
\newcommand{\resetbsubfloat}{\bsubfloatcount\z@\bsubfloatht=\z@}
\makeatother

\begin{document}

\begin{figure}
\centering
\bsubfloat[Small circle]{%
  \begin{tikzpicture}
    \draw circle (1.25cm) {};
  \end{tikzpicture}%
}
\bsubfloat[Big circle]{%
  \begin{tikzpicture}
    \draw circle (2cm) {};
  \end{tikzpicture}%
}
\bsubfloati\qquad\bsubfloatii
\caption{Circles}
\end{figure}

\end{document}

The \bsubfloat commands are just for doing the calculation, then you can use \bsubfloati, \bsubfloatii, \bsubfloatiii, \bsubfloativ and so on (they are reset on each figure environment) to set up the row of subfloats.

If you have multiple rows, you should use \resetbsubfloat between them and use again \bsubfloati and so on for the placement.

More automatic procedure

Here is one, it has some weaknesses, but it should work.

\documentclass{article}

\usepackage{tikz}
\usepackage{subfig}

\newtoks\bsubfloattoks
\newdimen\bsubfloatht

\makeatletter
\newenvironment{bsubfloatrows}[1][\quad]
  {\def\bsubfloatspace{#1}\resetbsubfloatrows
   \def\\{\printbsubfloatrow\resetbsubfloatrows\par
     \@ifnextchar[{\bsubfloatvspace}{}}%
   \def\bsubfloatvspace[##1]{\vspace{##1}}%
  }
  {\printbsubfloatrow}
\newcommand{\bsubfloat}[2][]{%
  \sbox\z@{#2}%
  \ifdim\bsubfloatht<\ht\z@
    \bsubfloatht=\ht\z@
  \fi
  \bsubfloattoks=\expandafter{\the\bsubfloattoks
    \bsubfloatspace\subfloat[#1]{\vbox to\bsubfloatht{\hbox{#2}\vfill}}}%
}
\newcommand\resetbsubfloatrows{\bsubfloatht\z@\bsubfloattoks={\@gobble}}
\newcommand{\printbsubfloatrow}{\the\bsubfloattoks}
\makeatother



\begin{document}

\begin{figure}
\centering
\begin{bsubfloatrows}[\hfill]
\bsubfloat[Small circle]{%
  \begin{tikzpicture}
    \draw circle (1.25cm) {};
  \end{tikzpicture}%
}
\bsubfloat[Big circle]{%
  \begin{tikzpicture}
    \draw circle (2cm) {};
  \end{tikzpicture}%
}
\\[36pt]
\bsubfloat[Small circle]{%
  \begin{tikzpicture}
    \draw circle (1cm) {};
  \end{tikzpicture}%
}
\bsubfloat[Big circle]{%
  \begin{tikzpicture}
    \draw circle (1.2cm) {};
  \end{tikzpicture}%
}
\end{bsubfloatrows}
\caption{Circles}
\end{figure}

\end{document}

As you see, subfloats are enclosed in an environment, where each row is processed separately as regards the height. The horizontal spacing between two subfloats is given as optional argument to the environment (that's one weakness).

share|improve this answer
up vote 8 down vote accepted

As suggested by Mico in his answer it can be done with the floatrow package. To make subcaptions it depends on subcaption which depends on caption.

\documentclass{article}

\usepackage{tikz}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{floatrow}
\usepackage{calc}% To calculate width for \FBwidth

\floatsetup{ 
  heightadjust=object,
  valign=t
}

\begin{document}

\begin{figure}
\ffigbox
{%
  \begin{subfloatrow}
    \ffigbox[\FBwidth+0.5cm]% Width of subfloat
    {%
      \begin{tikzpicture}
        \draw circle (1.25cm) {};
      \end{tikzpicture}%
    }
    {%
      \subcaption{Small circle}%
    }
    \ffigbox[\FBwidth+0.5cm]% Width of subfloat
    {%
      \begin{tikzpicture}
        \draw circle (2cm) {};
      \end{tikzpicture}%
    }
    {%
      \subcaption{Big circle}%
    }
  \end{subfloatrow}
}
{%
  \caption{Circles}%
}
\end{figure}

\end{document}

Vertically top-aligned circles with vertically aligned subcaptions below

share|improve this answer
    
floatrow isn't compatible with the memoir class. Is it possible to achieve this another way when using memoir? –  hertzsprung Aug 2 at 11:33

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.