27

basically i need something like rowspan option in html table. I want that an figure 3 and figure 4 occupy three rows, I need a layout something like this:

|figure 1 | figure 2 |               |               |
|figure 5 | figure 6 | figure 3 | figure 4 |
|figure 7 | figure 8 |               |               |

how i can get this layout?

3 Answers3

23
\documentclass{article}

\usepackage[demo]{graphicx}
\usepackage{subfig}
\usepackage{tabularx}

\begin{document}

\begin{figure}
\def\tabularxcolumn#1{m{#1}}
\begin{tabularx}{\linewidth}{@{}cXX@{}}
%
\begin{tabular}{cc}
\subfloat[A]{\includegraphics[width=2cm]{logo}} 
   & \subfloat[B]{\includegraphics[width=3cm]{logo}}\\
\subfloat[C]{\includegraphics[width=2cm]{logo}} 
   & \subfloat[D]{\includegraphics[width=3cm]{logo}}\\
\subfloat[E]{\includegraphics[width=2cm]{logo}} 
   & \subfloat[F]{\includegraphics[width=3cm]{logo}}\\
\end{tabular}
&
\subfloat[G]{\includegraphics[width=2cm,height=4cm]{logo}}
&
\subfloat[H]{\includegraphics[width=\linewidth]{logo}}
\end{tabularx}

\caption{Many figures}\label{foo}
\end{figure}

\end{document}

the demo output

Moriambar
  • 11,466
  • Nice method , I am looking for an arrangement exactly like this only that I don't want '(a),(b),(c)...' alphabets below the images , but I do need individual captions below each subfloat. Thanks for any help – Nishant Jun 25 '14 at 08:07
12

Adding to Leo Liu's answer: As the figures 3 and 4 are probably larger than the others, you also need to use the multirow package to span several rows. The package has quite a bit of trouble with the vertical alignment, so you'll need to adjust the optional argument of the \multirow commands by hand.

\documentclass{article}

\usepackage{graphicx}
\usepackage{subfig}
\usepackage{multirow}
\usepackage{array}

\begin{document}

\begin{figure}
\centering
\begin{tabular}{cccc}
\subfloat[A]{\includegraphics{logo}} & 
\subfloat[B]{\includegraphics{logo}} & 
\multirow{-3}[2.5]{*}{\subfloat[D]{\includegraphics[width=2cm,height=4cm]{logo}}} &
\multirow{-3}[-3]{*}{\subfloat[E]{\includegraphics[width=2cm,height=3cm]{logo}}} \\
\subfloat[E]{\includegraphics{logo}} & 
\subfloat[F]{\includegraphics{logo}}\\
\subfloat[G]{\includegraphics{logo}}&
\subfloat[H]{\includegraphics{logo}} \\
\end{tabular}
\caption{Many figures}
\end{figure}

\end{document}

Subfigures with rowspanning

This is the image file used (save as logo.png)


If you want to use a sledgehammer to crack a nut, you could also use TikZ nodes and matrices. Herbert pointed out in the comments that this approach is overkill for the given problem. I'll leave it here to serve as an example of what not to do and perhaps as a template for more complex subfigure layout challenges which might arise and justify the use of this "heavy machinery".

\documentclass{article}

\usepackage{graphicx}
\usepackage{subfig}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\captionsetup[subfloat]{farskip=0pt} % Remove the top glue from subfloats
\begin{figure}
\centering
\begin{tikzpicture}[every node/.style=inner sep=0pt]
\matrix [name=m,
cells={anchor=south},
column sep=0.8cm,row sep = 0.4cm]
{
\node (f1) {\subfloat[A]{\includegraphics{logo}} }; &
\node (f2) {\subfloat[B]{\includegraphics{logo}} }; \\
\setcounter{subfigure}{4}
\node (f5)  {\subfloat[E]{\includegraphics{logo}} }; &
\node (f6) {\subfloat[F]{\includegraphics{logo}} }; \\
\node (f7)  {\subfloat[G]{\includegraphics{logo}} }; &
\node (f8)  {\subfloat[H]{\includegraphics[width=4cm]{logo}} };  \\
};
\setcounter{subfigure}{2}
\node (f3) [right=.8cm of m] {\subfloat[C]{\includegraphics[height=4cm,width=2cm]{logo}} }; 
\node (f4) [right=.8cm of f3] {\subfloat[D]{\includegraphics[height=2cm,width=2cm]{logo}} }; 
\end{tikzpicture}

\caption{Many figures}
\end{figure}

\end{document}

Subfigures placed using TikZ

David Carlisle
  • 757,742
Jake
  • 232,450
  • it is not powerful, it is absolutely overkill using nodes for this ... –  Jan 24 '11 at 15:47
  • @Herbert How would you produce an array of such subfigures? – Jake Jan 24 '11 at 16:51
  • @Jake using package floatrow –  Jan 24 '11 at 16:52
  • @Herbert Have you tried using floatrow for the case described by maxim? I tried adapting the "picture book" example (p. 97, floatrow manual), but it becomes completely unintuitive and unmaintainable very quickly. I'd be interested to see an answer to the OP's question using floatrow. Of course you're right that usually you shouldn't need to typeset subfigures using a TikZ picture, but the OP's problem is more complex than usual. – Jake Jan 24 '11 at 16:57
  • @Jake: you already had a good sulution with a tabular. If you'd used a nested tabular then you can get rid of the multirow package. See my example –  Jan 24 '11 at 17:15
  • 1
    @Herbert: Indeed, your solution is much more elegant. I've added a paragraph to my answer pointing out that TikZ is not the right tool for the job. However, I can imagine that there'll be situations where the TikZ approach can be justified. The tabular solution does not handle different widths for subfigs C and D (G and H in your example) without manual adjustments, for example; or try replacing subfigs B and F (B and D) with one tall subfigure. That said, your approach is undoubtedly much better for the vast majority of cases. – Jake Jan 24 '11 at 17:57
  • multirow worked well for me - you're right that it's a bit fiddly to get the alignment, but once it's done it works great. – zelanix Aug 20 '15 at 18:57
1

You can put them in a tabular environment. If numbers are needed, you also have to change the figure counter.

\usepackage{array} % in preamble

\begin{figure}
\begin{tabular}{*{4}{>{\centering\arraybackslash}p{.2\textwidth}}}
one \caption{a} & two \caption{b} \\
\addtocounter{figure}{2}five \caption{b} & six \caption{b}
 & \addtocounter{figure}{-4}three \caption{b} & four \caption{b} \\
\addtocounter{figure}{2}
seven \caption{b} & eight \caption{b} \\
\end{tabular}
\end{figure}
David Carlisle
  • 757,742
Leo Liu
  • 77,365