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.

Is there a nice way to include multiple figures in the format of a table?

I want it to look something like the following mock-up (pardon my terrible MS Paint skills), and am willing to include any necessary packages. I would love it if there were a nice way to label the columns as rows as I did (a and b, and 1, 2, and 3).

enter image description here

share|improve this question
1  
Will this be part of a bigger figure or table? And how do you want to be able to reference the figures? For example, \ref{figurea1} should return 1a1 if it's part of Figure 1? –  Werner Apr 17 '12 at 2:01
    
@Werner This is not part of a bigger table--I want a table made up of these 6 figures. I want to include each of them as a separate figure, and be able to \ref them separately as well. –  jamaicanworm Apr 17 '12 at 2:02
add comment

2 Answers

up vote 8 down vote accepted

The following works by defining a new \fixedlabel labelling scheme. \fixedlabel{<lab>}{<tag>} fixes the label <tag> associated with <lab> (similar to the \tag labelling mechanism of amsmath).

enter image description here

% http://tex.stackexchange.com/questions/52189/including-table-of-figures
\documentclass{article}
\makeatletter
\def\fixedlabel#1#2{%
  \@bsphack%
  \protected@write\@auxout{}%
         {\string\newlabel{#1}{{#2}{\thepage}}}%
  \@esphack}
\makeatother
\begin{document}

\begin{table}[ht]
  \centering
  \begin{tabular}{c@{\quad}cc}
    & a & b \\
    1 & \rule[-25pt]{100pt}{50pt}\fixedlabel{block1a}{1a} 
      & \rule[-25pt]{100pt}{50pt}\fixedlabel{block1b}{1b} \\ \\
    2 & \rule[-25pt]{100pt}{50pt}\fixedlabel{block2a}{2a} 
      & \rule[-25pt]{100pt}{50pt}\fixedlabel{block2b}{2b} \\ \\
    3 & \rule[-25pt]{100pt}{50pt}\fixedlabel{block3a}{3a} 
      & \rule[-25pt]{100pt}{50pt}\fixedlabel{block3b}{3b}
  \end{tabular}
  \caption{This is a caption.}\label{figtab}
\end{table}

See, for example, \ref{block1a} and~\ref{block2b} in Table~\ref{figtab}.

\end{document}

A hyperref-compatible version of \fixedlabel is given by:

\def\fixedlabel#1#2{%
  \@bsphack
  \begingroup
    \@onelevel@sanitize\@currentlabelname
    \edef\@currentlabelname{%
      \expandafter\strip@period\@currentlabelname\relax.\relax\@@@%
    }%
    \phantomsection%
    \protected@write\@auxout{}{%
      \string\newlabel{#1}{%
        {#2}%
        {\thepage}%
        {#2}%
        {\@currentHref}{}%
      }%
    }%
  \endgroup
  \@esphack
}
share|improve this answer
    
I have a slight problem. In my document the label for each row is not simply 1, 2, 3--rather, it is some longer text such as \text{$p = 0.1\%$ noise, $N = 100$ trials}. This text is too long, as it pushes both figures to its right into the margin. How can I make this labeling text separate into two lines? When I try \text{$p = 0.1\%$ noise,} \\ \text{$N = 100$ trials} the second line gets pushed all the way beneath the figure... –  jamaicanworm Apr 17 '12 at 17:37
1  
@jamaicanworm: You could insert a tabular for those entries: \begin{tabular}{@{}c@{}} $p = 0.1\%$ noise, \\ $N = 100$ trials \end{tabular} The zero-padding ensures that your original columnar spacing (isn't affected, but allows for you to add multiple rows within a single cell. –  Werner Apr 17 '12 at 17:45
    
Thanks, but then the label gets pushed to the bottom of the row, instead of remaining vertically centered in the row. –  jamaicanworm Apr 17 '12 at 18:37
1  
@jamaicanworm: How about using an >{\centering\arraybackslash}m{5em} column type for the left column (not for the inner tabular, but the outer tabular). This would require the addition of the array package. My MWE uses \rule for a fake image, so I didn't have time to play around. Give some feedback if you're still stuck and I'll post an updated MWE. –  Werner Apr 17 '12 at 19:14
1  
@jamaicanworm: If all the figures except one is of an inappropriate size, you can store one of the OK ones in a box (to measure it's width) and then resize the non-OK one to that width. Something like \newsavebox{\myfig}\savebox{\myfig}{\includegraphics[..]{OK-fig}} and then use \includegraphics[width=\wd\myfig]{non-OK-fig}. If this is not clear, ask a follow-up question. –  Werner Apr 17 '12 at 19:33
show 1 more comment

Here's one possible solution using the tabu package:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{tabu}
\usepackage{caption,subcaption}

\newcounter{tmp}

% \MyIm{<figure name>}{<label>}
\newcommand\MyIm[2]{%
  \captionof*{subfigure}{}
  \includegraphics[width=4cm,height=2cm]{#1}
  \captionof{subfigure}{}\label{#2}%
}

\begin{document}

\begin{center}
\setcounter{tmp}{\thefigure}
\captionsetup[subfigure]{labelformat=empty}
\begin{tabu}{>{\refstepcounter{figure}\thefigure\setcounter{subfigure}{0}}l%
  X[c,m]X[c,m]}
  \multicolumn{1}{l}{\setcounter{figure}{0}} & a & b \\[-20pt]
  & \MyIm{name1}{a} & \MyIm{name2}{b}  \\[-30pt]
  & \MyIm{name3}{c} & \MyIm{name4}{d}  \\[-30pt]
  & \MyIm{name5}{e} & \MyIm{name6}{f} 
\end{tabu}\setcounter{figure}{\thetmp} 
\end{center}

\ref{a} \ref{b} \ref{c} \ref{d} \ref{e} \ref{f}

\end{document}

enter image description here

Some remarks:

  1. A tmp counter was used to store the value of the counter figure before the table and then, at the end the value for figure was restored

  2. The subcaption package was used to provide an empty caption for each figure; this allows the easy assignment of a \label for cross-referencing.

  3. This solution cooperates with hyperref; the only thing to do is to load hyperref and hypcap:

    \usepackage{hyperref}
    \usepackage{hypcap}
    
share|improve this answer
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.