7

I have three models that I test under different parameter configurations. I created a figure where every column corresponds to a model. I would like to add the value of the parameter at the left of every row. After reading this answer, this is what I do:

\documentclass{article}

\usepackage[draft]{graphicx}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\centering
\begin{subfigure}[t]{0.30\textwidth}
    \rotatebox[origin=c]{90}{$R=1$}
    \includegraphics[width=\textwidth]
    {test.png}
    \rotatebox[origin=c]{90}{$R=2$}
    \includegraphics[width=\textwidth]
    {test.png}
    \rotatebox[origin=c]{90}{$R=3$}
    \includegraphics[width=\textwidth]
    {test.png}
    \caption{model A}
\end{subfigure}
\hspace{1em}
\begin{subfigure}[t]{0.30\textwidth}
    \includegraphics[width=\textwidth]  
    {test.png}
    \includegraphics[width=\textwidth]
    {test.png}
    \includegraphics[width=\textwidth]
    {test.png}
    \caption{model B}
\end{subfigure}
\hspace{1em}
\begin{subfigure}[t]{0.30\textwidth}
    \includegraphics[width=\textwidth]  
    {test.png}
    \includegraphics[width=\textwidth]
    {test.png}
    \includegraphics[width=\textwidth]
    {test.png}
    \caption{model C}
\end{subfigure}
\caption{Grid test}
\end{figure}

But I get this: test

How can I make it right?

1
  • I just updated my answer with another option that might be of interest for you. Feb 16, 2015 at 18:54

2 Answers 2

7

One possibility (the % signs suppressing spurious blank spaces are essential):

Update

A modified version (the whole construct now stays inside the text width):

\documentclass{article}
\usepackage[draft]{graphicx}
\usepackage{subcaption}
\usepackage{showframe}% just for visiual guide

\begin{document}

\begin{figure}
\centering
\begin{subfigure}[t]{\dimexpr0.30\textwidth+20pt\relax}
    \makebox[20pt]{\raisebox{40pt}{\rotatebox[origin=c]{90}{$R=1$}}}%
    \includegraphics[width=\dimexpr\linewidth-20pt\relax]
    {test.png}
    \makebox[20pt]{\raisebox{40pt}{\rotatebox[origin=c]{90}{$R=2$}}}%
    \includegraphics[width=\dimexpr\linewidth-20pt\relax]
    {test.png}
    \makebox[20pt]{\raisebox{40pt}{\rotatebox[origin=c]{90}{$R=3$}}}%
    \includegraphics[width=\dimexpr\linewidth-20pt\relax]
    {test.png}
    \caption{model A}
\end{subfigure}\hfill
\begin{subfigure}[t]{0.30\textwidth}
    \includegraphics[width=\textwidth]  
    {test.png}
    \includegraphics[width=\textwidth]
    {test.png}
    \includegraphics[width=\textwidth]
    {test.png}
    \caption{model B}
\end{subfigure}\hfill
\begin{subfigure}[t]{0.30\textwidth}
    \includegraphics[width=\textwidth]  
    {test.png}
    \includegraphics[width=\textwidth]
    {test.png}
    \includegraphics[width=\textwidth]
    {test.png}
    \caption{model C}
\end{subfigure}
\caption{Grid test}
\end{figure}

\end{document}

The result:

enter image description here

First version

(labels protrude to the left margin):

\documentclass{article}
\usepackage[draft]{graphicx}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\centering
\begin{subfigure}[t]{0.30\textwidth}
    \makebox[0pt][r]{\makebox[30pt]{\raisebox{40pt}{\rotatebox[origin=c]{90}{$R=1$}}}}%
    \includegraphics[width=\textwidth]
    {test.png}
    \makebox[0pt][r]{\makebox[30pt]{\raisebox{40pt}{\rotatebox[origin=c]{90}{$R=2$}}}}%
    \includegraphics[width=\textwidth]
    {test.png}
    \makebox[0pt][r]{\makebox[30pt]{\raisebox{40pt}{\rotatebox[origin=c]{90}{$R=3$}}}}%
    \includegraphics[width=\textwidth]
    {test.png}
    \caption{model A}
\end{subfigure}
\hspace{1em}
\begin{subfigure}[t]{0.30\textwidth}
    \includegraphics[width=\textwidth]  
    {test.png}
    \includegraphics[width=\textwidth]
    {test.png}
    \includegraphics[width=\textwidth]
    {test.png}
    \caption{model B}
\end{subfigure}
\hspace{1em}
\begin{subfigure}[t]{0.30\textwidth}
    \includegraphics[width=\textwidth]  
    {test.png}
    \includegraphics[width=\textwidth]
    {test.png}
    \includegraphics[width=\textwidth]
    {test.png}
    \caption{model C}
\end{subfigure}
\caption{Grid test}
\end{figure}

\end{document}

The result:

enter image description here

Adjust the lengths in the \raiseboxes and the inner \makeboxes according to your needs.

1
  • Very nice solution. What I don't like in your updated version, however, is that the first caption is not centered below the first column of pictures anymore. I used a separate column without a caption which holds the row labels to mitigate this. Feb 2, 2017 at 17:09
1

There are two problems with your code: First, since you use width=\textwidth, the label and the image do not fit in one line and hence a new line is started for the image. The second problem is that the baseline of the image is not in its vertical center. This can be shifted by \raisebox. Assuming that all your images have the same width and height, the following might help':

\documentclass{article}

\usepackage[draft]{graphicx}
\usepackage{subcaption}
\newcommand\myrowlabel[1]{%
  \rotatebox[origin=c]{90}{#1}%
}
\begin{document}

\begin{figure}
  \centering
  \begin{subfigure}[c]{0.30\textwidth}\raggedleft
    \myrowlabel{$R=1$}
    \raisebox{-.5\height}{\includegraphics[width=.9\textwidth]
    {test.png}}\\
    \myrowlabel{$R=2$}
    \raisebox{-.5\height}{\includegraphics[width=.9\textwidth]
    {test.png}}\\
    \myrowlabel{$R=3$}
    \raisebox{-.5\height}{\includegraphics[width=.9\textwidth]
    {test.png}}
    \caption{model A}
\end{subfigure}%
\hspace{1em}
\begin{subfigure}[c]{0.30\textwidth}\raggedleft
    \includegraphics[width=.9\textwidth]  
    {test.png}
    \includegraphics[width=.9\textwidth]
    {test.png}
    \includegraphics[width=.9\textwidth]
    {test.png}
    \caption{model B}
\end{subfigure}
\hspace{1em}
\begin{subfigure}[c]{0.30\textwidth}\centering
    \includegraphics[width=.9\textwidth]  
    {test.png}
    \includegraphics[width=.9\textwidth]
    {test.png}
    \includegraphics[width=.9\textwidth]
    {test.png}
    \caption{model C}
\end{subfigure}
\caption{Grid test}
\end{figure}
\end{document}

Note that if \textwidth is small, width=.9\textwidth might not leave enough space for the label, too. Furthermore, you might consider using \hspace{\fill} instead of \hspace{1em} if you have a small \textwidth. enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .