3

I am trying to create a figure a table, that is, with tabular on it.

\documentclass[a4paper]{article}
\usepackage[left=20mm,
            right=20mm,
            bottom=30mm,
            top=30mm]{geometry}
\usepackage{multirow,multicol} 
\usepackage{graphicx,tabularx,longtable}


% Rotated text inside tables
\newcommand{\spheading}[2][1]{% \spheading[<width>]{<stuff>}
    \rotatebox{90}{\parbox{#1}{\centering #2}}
}

\begin{document}
\bgroup
\def\arraystretch{1.5}\setlength{\tabcolsep}{3.5pt}
\begin{figure}[!htb]
    \centering
    \begin{tabular}{c*3{l}}
        \hline
        \multicolumn{1}{>{\centering\arraybackslash}m{.1\linewidth}}{Block Method}
        & \multicolumn{1}{>{\centering\arraybackslash}c}{EIT} 
        & \multicolumn{1}{>{\centering\arraybackslash}c}{mSDT} 
        & \multicolumn{1}{>{\centering\arraybackslash}c}{SLT} \\ \hline
        \spheading[7em]{\small $N_b = 2$}
        & \raisebox{-.5em}{%
            \includegraphics[scale=.41]{example-image-a}
        }
        & \raisebox{-.5em}{%
            \includegraphics[scale=.41]{example-image-b}
        }
        & \raisebox{-.5em}{%
            \includegraphics[scale=.41]{example-image-c}
        } \\ \hline
          \spheading[7em]{\small $N_b = 4$}
        & \raisebox{-.5em}{%
            \includegraphics[scale=.41]{example-image-a}
        }
        & \raisebox{-.5em}{%
            \includegraphics[scale=.41]{example-image-b}
        }
        & \raisebox{-.5em}{%
            \includegraphics[scale=.41]{example-image-c}
        } \\ \hline
          \spheading[7em]{\small $N_b = 5$}
        & \raisebox{-.5em}{%
            \includegraphics[scale=.41]{example-image-a}
        }
        & \raisebox{-.5em}{%
            \includegraphics[scale=.41]{example-image-b}
        }
        & \raisebox{-.5em}{%
            \includegraphics[scale=0.41]{example-image-c}
        }\\ \hline
        \spheading[7em]{\small $N_b = 10$}
        & \raisebox{-.5em}{%
            \includegraphics[scale=.41]{example-image-a}
        }
        & \raisebox{-.5em}{%
            \includegraphics[scale=.41]{example-image-b}
        }
        & \raisebox{-.5em}{%
            \includegraphics[scale=.41]{example-image-c}
        } \\ \hline
        \spheading[7em]{\small $N_b = 20$}
        & \raisebox{-.5em}{%
            \includegraphics[scale=.41]{example-image-a}
        }
        & \raisebox{-.5em}{%
            \includegraphics[scale=.41]{example-image-b}
        }
        & \raisebox{-.5em}{%
            \includegraphics[scale=.41]{example-image-c}
        } \\ \hline
        \spheading[7em]{\small $N_b = 40$}
        & \raisebox{-.5em}{%
            \includegraphics[scale=.41]{example-image-a}
        }
        & \raisebox{-.5em}{%
            \includegraphics[scale=.41]{example-image-b}
        }
        & \raisebox{-.5em}{%
            \includegraphics[scale=.41]{example-image-c}
        } \\ \hline
        \spheading[7em]{\small $N_b = 50$}
        & \raisebox{-.5em}{%
            \includegraphics[scale=.41]{example-image-a}
        }
        & \raisebox{-.5em}{%
            \includegraphics[scale=.41]{example-image-b}
        }
        & \raisebox{-.5em}{%
            \includegraphics[scale=.41]{example-image-c}
        } \\ \hline
    \end{tabular}
    \caption{Example.}
    \label{fig:BlockComparison_MatDist_pa=12}
\end{figure}
\egroup

\end{document}

As a result, I have:

enter image description here

I would like to know how to:

  • align the text of the first column;
  • increase the length of each row (so the figure is not glued to each horizontal line, and
  • split this figure into two pages.

Thanks in advice

2
  • Why rotating the items in the first column?
    – egreg
    Aug 18, 2022 at 21:33
  • This is not necessary, but since I don't know how to vertically align it, I found this solution easier.
    – AXL
    Aug 18, 2022 at 21:41

1 Answer 1

4

I don't think you want to rotate the items in the first column.

I'd not use scale, preferring to set a width. The spaces above and below the rules can be obtained with \midrule and setting the vertical space above rules the same as below (by default it's not needed).

For vertically centering the images, use valign=c, provided by adjustbox.

\documentclass[a4paper]{article}
\usepackage[
  left=20mm,
  right=20mm,
  bottom=30mm,
  top=30mm
]{geometry}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{booktabs}

\begin{document}

\begin{figure}[!htb]
\centering

\setlength{\aboverulesep}{\belowrulesep}

\begin{tabular}{@{} cccc @{} }
\toprule
 & \multicolumn{3}{c}{Block Method} \\
 \cmidrule(l){2-4}
 & EIT & mSDT & SLT \\
\midrule
$N_b = 2$
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-a}
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-b}
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-c} \\
\midrule
$N_b = 4$
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-a}
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-b}
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-c} \\
\midrule
$N_b = 5$
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-a}
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-b}
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-c} \\
\midrule
$N_b = 10$
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-a}
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-b}
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-c} \\
\midrule
$N_b = 20$
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-a}
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-b}
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-c} \\
\midrule
$N_b = 40$
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-a}
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-b}
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-c} \\
\midrule
$N_b = 50$
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-a}
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-b}
  & \includegraphics[width=0.2\textwidth,valign=c]{example-image-c} \\
\bottomrule
\end{tabular}

\caption{Example.}
\label{fig:BlockComparison_MatDist_pa=12}

\end{figure}

\end{document}

You also need no \bgroup and \egroup, because settings done inside figure are local. For instance, the value of \aboverulesep will be restored after \end{figure}.

enter image description here

5
  • Thanks, @egreg. I never paid too much attention to the differences between \hline and \toprule. I have two questions though: (1) what \setlength{\aboverulesep}{\belowrulesep} does?, and (2) what is the idea when using @{}} in \begin{tabular}{@{} cccc @{}}?
    – AXL
    Aug 19, 2022 at 0:13
  • 1
    @AndréXavier The first column usually has some padding (\tabcolsep wide), but most often this is not needed, like in this case; similarly after the last column. A \midrule has \aboverulesep and \belowrulespace around it; the standard values are different (less space above than below) for various reasons, but in this case they must be equal.
    – egreg
    Aug 19, 2022 at 8:45
  • Do know how can I split this figure into two pages? Of course, I can change the figure size. However, by doing that the figure information will be too small! I know there are packages such as longtable, supertabular, xtab and others, but I am not familiar with any of them, and I don't know which one is the best -- at least, in my case.
    – AXL
    Aug 19, 2022 at 15:54
  • 1
    @AndréXavier You want longtable.
    – egreg
    Aug 19, 2022 at 17:31
  • Thanks, @egreg.
    – AXL
    Aug 19, 2022 at 19:38

You must log in to answer this question.

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