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 trying to place 4 subfigures of different sizes aligned. Here the box-k.pdf files contain boxes with marks at the midsides. The result has box-1 and box-3 aligned at the left margin, not centered (but the captions are centered).

texlive-2012, as distributed for Fedora.

\documentclass{memoir}
\usepackage{pgf}
\usepackage{subfig}

\begin{document}
  \begin{figure}[htbp]
    \setbox1=\hbox{\pgfimage{box-1}}
    \setbox2=\hbox{\pgfimage{box-2}}
    \setbox3=\hbox{\pgfimage{box-3}}
    \setbox4=\hbox{\pgfimage{box-4}}
    \centering
    \subfloat[Box 1]{
      \begin{minipage}[c]{1.0\wd3}
        \begin{center}
          \copy1
        \end{center}
      \end{minipage}
    }
    \hspace{4em}
    \subfloat[Box 2]{
      \begin{minipage}[c]{1.0\wd4}
         \begin{center}
            \copy2
         \end{center}
      \end{minipage}
    }
    \\[2ex]
    \subfloat[Box 3]{
      \begin{minipage}[c][1.0\ht4]{1.0\wd3}
        \begin{center}
          \copy3
        \end{center}
      \end{minipage}
    }
    \hspace{4em}
    \subfloat[Box 4]{
      \begin{minipage}[c]{1.0\wd4}
        \begin{center}
          \copy4
        \end{center}
      \end{minipage}
    }
    \caption{Some boxen}
  \end{figure}
\end{document}
share|improve this question
    
have a look at align-captions-of-subfigures –  cmhughes Nov 20 '12 at 1:03
    
floatrow clashes with memoir. And I can't see a way to align several rows horizontally, I want several different sized subfigures aligned both horizontally and vertically –  vonbrand Nov 20 '12 at 12:33
    
did you see my answer to in the linked question? it uses subcaption, not floatrow –  cmhughes Nov 20 '12 at 15:57
    
subcaption should not be used with memoir either, @cmhughes –  Mr. V Nov 28 '13 at 9:32
add comment

2 Answers

You should compute the width and heights, so as to catch the maximum and minimum widths:

\documentclass{memoir}
\usepackage{graphicx}
\usepackage[caption=false]{subfig}
\newlength{\alignheight}
\newlength{\alignwidth}
\newcommand{\fakeheight}[3]{%
  \makebox[#1][c]{\rule[-.5\dimexpr#2\relax]{0pt}{#2}\raisebox{-.5\height}{#3}}%
}

\begin{document}
\begin{figure}[htbp]

\sbox0{\includegraphics[width=3cm,height=2.5cm]{example-image-a}}
\setlength\alignwidth{\wd0}
\setlength\alignheight{\ht0}
\sbox2{\includegraphics[width=4cm,height=3cm]{example-image-b}}
\ifdim\wd2>\alignwidth \setlength\alignwidth{\wd2}\fi
\ifdim\ht2>\alignheight \setlength\alignheight{\ht2}\fi
\sbox4{\includegraphics[width=5cm,height=2cm]{example-image-c}}
\ifdim\ht4>\alignwidth \setlength\alignwidth{\wd4}\fi
\ifdim\ht2>\alignheight \setlength\alignheight{\ht4}\fi
\sbox6{\includegraphics[width=3.5cm,height=3.5cm]{example-image}}
\ifdim\ht6>\alignwidth \setlength\alignwidth{\wd6}\fi
\ifdim\ht2>\alignheight \setlength\alignheight{\ht6}\fi

\centering
  \subfloat[Box 1]{\fakeheight{\alignwidth}{\alignheight}{\usebox0}}\hspace{4em}%
  \subfloat[Box 2]{\fakeheight{\alignwidth}{\alignheight}{\usebox2}}\\[2ex]
  \subfloat[Box 3]{\fakeheight{\alignwidth}{\alignheight}{\usebox4}}\hspace{4em}%
  \subfloat[Box 4]{\fakeheight{\alignwidth}{\alignheight}{\usebox6}}
\caption{Some boxen}
\end{figure}
\end{document}

The command \pdfimage is deprecated by the same PGF package, in favor of \includegraphics. Of course here the maximum width and height are known, but I just used the explicit dimensions to mock up an example.

enter image description here

share|improve this answer
    
This is a lot of code for something memoir should do "out of the box", to be honest. –  Mr. V Nov 28 '13 at 9:30
add comment

The weird misalignment inside columns goes away if each minipage is like

\begin{minipage}[c]{1.0\wd2}
  \centering
  \makebox{\copy7}
\end{minipage}

Using minipage's [c] is a great way to align side-by-side figures vertically.

share|improve this answer
    
using \centering is usually preferable to the center environment; the center environment adds extra vertical space (as you saw); see should-i-use-center-or-centering-for-figures-and-tables for reference –  cmhughes Nov 23 '12 at 5:56
add comment

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.