0

I'm making a somewhat complicated figure and I'm having trouble aligning the text in some of my row captions. The below is a MWE that shows my problem.

\documentclass{article}
\usepackage{graphicx}
\usepackage{multirow}

\begin{document}
\begin{figure*}
\centering
\def\rowheight{2cm}  % Height of each row
\renewcommand{\arraystretch}{.5}  % Space between rows inside block
\def\blockspace{5mm}  % Space between blocks
\def\colwidth{.25\textwidth}  % Width of each column
\setlength{\tabcolsep}{1mm}  % Space between columns
\begin{tabular}{cc|ccc}
    \multirow{2}{*}{\rotatebox[origin=c]{90}{Block 1}} &
    \includegraphics[width=\colwidth,height=\rowheight]{example-image-a} &
    \includegraphics[width=\colwidth,height=\rowheight]{example-image-b} &
    \includegraphics[width=\colwidth,height=\rowheight]{example-image-c} &
    \rotatebox[origin=r]{270}{Row 1} \\
     & \includegraphics[width=\colwidth,height=\rowheight]{example-image-a} &
    \includegraphics[width=\colwidth,height=\rowheight]{example-image-b} &
    \includegraphics[width=\colwidth,height=\rowheight]{example-image-c} &
    \rotatebox[origin=r]{270}{Row 2} \\[\blockspace]
    \multirow{2}{*}{\rotatebox[origin=c]{90}{Block 2}} &
    \includegraphics[width=\colwidth,height=\rowheight]{example-image-a} &
    \includegraphics[width=\colwidth,height=\rowheight]{example-image-b} &
    \includegraphics[width=\colwidth,height=\rowheight]{example-image-c} &
    \rotatebox[origin=r]{270}{Row 1} \\
     & \includegraphics[width=\colwidth,height=\rowheight]{example-image-a} &
    \includegraphics[width=\colwidth,height=\rowheight]{example-image-b} &
    \includegraphics[width=\colwidth,height=\rowheight]{example-image-c} &
    \rotatebox[origin=r]{270}{Row 2} \\[\blockspace]
    \multirow{2}{*}{\rotatebox[origin=c]{90}{Block 3}} &
    \includegraphics[width=\colwidth,height=\rowheight]{example-image-a} &
    \includegraphics[width=\colwidth,height=\rowheight]{example-image-b} &
    \includegraphics[width=\colwidth,height=\rowheight]{example-image-c} &
    \rotatebox[origin=r]{270}{Row 1} \\
     & \includegraphics[width=\colwidth,height=\rowheight]{example-image-a} &
    \includegraphics[width=\colwidth,height=\rowheight]{example-image-b} &
    \includegraphics[width=\colwidth,height=\rowheight]{example-image-c} &
    \rotatebox[origin=r]{270}{Row 2}
\end{tabular}
\end{figure*}

\end{document}

Compiled

I'd like all the captions on the sides to be center aligned either to their respective blocks (each block is a set of two rows) or to the rows themselves. However, the current configuration doesn't really align them properly, and other configurations with origin=c or origin=l have performed even worse when I tested them.

How do I appropriately align the side captions? Alternatively, is there a better way to lay out this kind of figure than tabular?

2 Answers 2

1

The right texts are easy to handle. You just need to add adjustbox package, add valign=c to each image so their baselines are in the middle of images, and use \rotatebox[origin=c]...; it will rotate and place texts right in the middle. Also, if you have a number of images with the same options, adjustbox has a nice solution to avoid repetition, \adjustboxset{...}, which will insert all settings specified inside to each instance of \includegraphics. It can be set globally in a preamble or locally in a group.

I find rotations in multirow a bit tricky. if I use anything else than one line of text, it usually shifts the content. Adding a small adjustment can correct it; use the third optional parameter.

Final note, try to avoid \def. Either \newcommand for macros or \newlength\name for length names (followed by \setlength\name{...}) are better options because they warn about accidental overwriting something that is already defined, whereas \def silently change them.

Your example

enter image description here

\documentclass{article}
\usepackage{graphicx}
\usepackage[Export]{adjustbox}
\usepackage{multirow}

\newlength\rowheight
\newlength\colwidth
\newlength\blockspace
\newlength\smallspace
\newlength\multirowcor

\begin{document}
\begin{figure*}
  \setlength\rowheight{2cm}  % Height of each row
  \setlength\colwidth{.25\textwidth}  % Width of each column
  \setlength\blockspace{1cm}
  \setlength\smallspace{0.9cm}
  \setlength\multirowcor{-5mm}
  \adjustboxset{width=\colwidth,height=\rowheight,valign=c}
  \centering
  \renewcommand{\arraystretch}{.5}  % Space between rows inside block
  \setlength{\tabcolsep}{1mm}  % Space between columns
  \begin{tabular}{cc|ccc}
    \multirow{2}*[\multirowcor]{\rotatebox[origin=c]{90}{Block 1}}
    & \includegraphics{example-image-a}
    & \includegraphics{example-image-b}
    & \includegraphics{example-image-c}
    & \rotatebox[origin=c]{270}{Row 1} \\[\smallspace]
    & \includegraphics{example-image-a}
    & \includegraphics{example-image-b}
    & \includegraphics{example-image-c}
    & \rotatebox[origin=c]{270}{Row 2} \\[\blockspace]
    \multirow{2}*[\multirowcor]{\rotatebox[origin=c]{90}{Block 2}}
    & \includegraphics{example-image-a}
    & \includegraphics{example-image-b}
    & \includegraphics{example-image-c}
    & \rotatebox[origin=c]{270}{Row 1} \\[\smallspace]
    & \includegraphics{example-image-a}
    & \includegraphics{example-image-b}
    & \includegraphics{example-image-c}
    & \rotatebox[origin=c]{270}{Row 2} \\[\blockspace]
    \multirow{2}*[\multirowcor]{\rotatebox[origin=c]{90}{Block 3}}
    & \includegraphics{example-image-a}
    & \includegraphics{example-image-b}
    & \includegraphics{example-image-c}
    & \rotatebox[origin=c]{270}{Row 1} \\[\smallspace]
    & \includegraphics{example-image-a}
    & \includegraphics{example-image-b}
    & \includegraphics{example-image-c}
    & \rotatebox[origin=c]{270}{Row 2}
  \end{tabular}
\end{figure*}

\end{document}
3

Here is a solution that uses tikz to get the desired effect. If you are not familiar with tikz, I wouldn't recommand this solution for you because there is a lot to fathom before being able to modify it as you want. Just know that nearly everything is possible with tikz.

In your case, rather than using a table(ular), I used a foreach loop to place the image. Then, I defined a node named block with the text block that is located between the cell00 and cell10, rotated by 90° and shifted by a little bit on the x axis.

I then defined the row1 and row2 nodes to be 25 units on the right of the desired cells, rotated around their north anchor by -90°.

If you are asking yourself "Why does it have to be so complicated?". It is because tikz allow you to do so much and overcomes all limitations that are present in table for example. Anis.

\documentclass{article}
\usepackage{graphicx}
%\usepackage{multirow}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\begin{figure}[h]
\begin{tikzpicture}
\begin{scope}
\foreach \y in {0,1}{
    \foreach \x in {0,1,2}{
    \node (cell\y\x)at (4*\x,3*\y){\includegraphics[width=3cm]{example-image-a}};
}   
}
\node[rotate=90](block) at ($(cell00)!0.5!(cell10) -(2,0)$) {block1};
\node[right of = cell02,right = 30,rotate=-90,anchor=north](row1) {Row1};
\node[right of = cell12,right = 30,rotate=-90,anchor=north](row2) {Row2};
\end{scope}

\begin{scope}[yshift=6cm]
\foreach \y in {0,1}{
    \foreach \x in {0,1,2}{
        \node (cell\y\x)at (4*\x,3*\y){\includegraphics[width=3cm]{example-image-a}};
    }   
}
\node[rotate=90](block) at ($(cell00)!0.5!(cell10) -(2,0)$) {block1};
\node[right of = cell02,right = 30,rotate=-90,anchor=north](row1) {Row1};
\node[right of = cell12,right = 30,rotate=-90,anchor=north](row2) {Row2};
\end{scope}
\end{tikzpicture}
\centering
\end{figure}
\end{document}

You must log in to answer this question.

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