3

I am trying to make a 2x4 tabular containing images, with horizontal captions at the top and vertical captions on the left.

Taking inspiration from this thread, I painfully managed to do this:

\documentclass{article}

\usepackage{graphicx}

\newlength{\tempdima}
\newlength{\tempdimb}
\newcommand{\rowname}[1]% #1 = text
{\rotatebox{90}{\makebox[\tempdimb][c]{\scriptsize#1}}}
\newcommand{\rownamee}[1]% #1 = text
{\rotatebox{-90}{\makebox[\tempdimb][c]{\scriptsize#1}}}

\begin{document}
    
\begin{figure}
    
    \settowidth{\tempdima}{\includegraphics[width=0.2\linewidth]{example-image-duck}}%
    \settoheight{\tempdimb}{\includegraphics[width=0.2\linewidth]{example-image-duck}}%
    \centering
    \begin{tabular}{@{}c@{}c@{}c@{}c@{}c@{}@{}c@{}}
        & target  & method 1 & method 2 & method 3 &    \\
        \rowname{mod 1} & \includegraphics[width=\tempdima]{example-image-duck} & \includegraphics[width=\tempdima]{example-image-duck} & \includegraphics[width=\tempdima]{example-image-duck}&\includegraphics[width=\tempdima]{example-image-duck} &     \\
        \rowname{mod 2} & \includegraphics[width=\tempdima]{example-image-duck} & \includegraphics[width=\tempdima]{example-image-duck} & \includegraphics[width=\tempdima]{example-image-duck}&\includegraphics[width=\tempdima]{example-image-duck} &     \\
    \end{tabular}   
% pet
\end{figure}
    
\end{document} 

which produces the following table: enter image description here

Clearly this approach is suboptimal.

I discovered tabularray in this thread and it should be able to do something much better, with possibility to control spacing between rows and columns, but I failed to produce anything.

Any help/tips would be greatly appreciated. Thanks!

3 Answers 3

3

I worked it out as follows

\documentclass{article}

\usepackage{graphicx}
\newlength{\tempdima}
\usepackage{tabularray}

\begin{document}

\begin{figure}
    \settowidth{\tempdima}{\includegraphics[width=0.2\linewidth]{example-image-duck}}%
    \begin{tblr}{
                    colspec = {X[c,r]X[c,h,\tempdima]X[c,h,\tempdima]X[c,h,\tempdima]X[c,h,\tempdima]X[c,h,\tempdima]},
                %   stretch = 0,
                %   colsep = 10pt,
                    }
            & Target  & method 1 & method 2 & method 3& \\
        \rotatebox{90}{mod 1}   & \includegraphics[width=\tempdima]{example-image-duck} & \includegraphics[width=\tempdima]{example-image-duck} & \includegraphics[width=\tempdima]{example-image-duck}&\includegraphics[width=\tempdima]{example-image-duck} &   \\ 
        \rotatebox{90}{mod 2}   & \includegraphics[width=\tempdima]{example-image-duck} & \includegraphics[width=\tempdima]{example-image-duck} & \includegraphics[width=\tempdima]{example-image-duck}&\includegraphics[width=\tempdima]{example-image-duck} &   \\ 
        \end{tblr}
\end{figure}

\end{document}

Which produces this:

enter image description here

3

You can use adjustbox.

\documentclass{article}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{booktabs}

\newcommand{\rowname}[1]{% #1 = text
  \adjustbox{valign=c}{\rotatebox{90}{\scriptsize#1}}%
}

\begin{document}

\begin{figure}[htp]
\centering

\setlength{\tabcolsep}{0pt}           

\begin{tabular}{c@{\hspace{0.2em}}*{4}{c}}
& target  & method 1 & method 2 & method 3 \\
\rowname{mod 1}
 & \includegraphics[valign=c,width=0.2\textwidth]{example-image-duck}
 & \includegraphics[valign=c,width=0.2\textwidth]{example-image-duck}
 & \includegraphics[valign=c,width=0.2\textwidth]{example-image-duck}
 & \includegraphics[valign=c,width=0.2\textwidth]{example-image-duck}
\\
\addlinespace
\rowname{mod 2}
 & \includegraphics[valign=c,width=0.2\textwidth]{example-image-duck}
 & \includegraphics[valign=c,width=0.2\textwidth]{example-image-duck}
 & \includegraphics[valign=c,width=0.2\textwidth]{example-image-duck}
 & \includegraphics[valign=c,width=0.2\textwidth]{example-image-duck}
\end{tabular}

\end{figure}

\end{document}

enter image description here

3

With rotating, makecell and tblr of `tabularray package, similar to your answer but added are some tweaks for better looking (according to my opinion):

\documentclass[demo]{article}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage[export]{adjustbox}
\usepackage{rotating}
\usepackage{makecell}
\usepackage{tabularray}

\begin{document}
    \begin{figure}
\adjustboxset{height=3cm, % dropout in real document
              width=\linewidth,
              valign = m,
              }
\begin{tblr}{colsep = 2pt,
             colspec = {Q[c] *{4}{X[c]}  @{}},
             cell{2-Z}{1}  = {cmd=\settowidth\rotheadsize{ mod 1 }\rotcell}
             }
    &   target  &   method 1    &   method 2    &   method 3    \\
mod 1
    &   \adjincludegraphics{example-image-duck}
        &   \adjincludegraphics{example-image-duck}
            &   \adjincludegraphics{example-image-duck}   
                &   \adjincludegraphics{example-image-duck}     \\
mod 2                
    &   \adjincludegraphics{example-image-duck}
        &   \adjincludegraphics{example-image-duck}
            &   \adjincludegraphics{example-image-duck}   
                &   \adjincludegraphics{example-image-duck}     \\
\end{tblr}
    \end{figure}
\end{document}

enter image description here

(red lines indicate text area borders)

You must log in to answer this question.

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