3

I need to arrange images like in the image below. I have looked to several examples but every time, either the images are not aligned or the captions stay out of position. How should I do?

This is the original paper

enter image description here

Regards!

2 Answers 2

3

Your figure layout is roughly given by a 6-column tabular, with the height of the left-most image given by the difference between the vertical position of the top of the first row of images and the bottom of the second row of images. One can use zref's savepos module to capture node positions on the page, together with some box manipulation (storing content in a box for measuring purposes) to automate the resizing of the larger (left-most) image.

The following example does exactly this and requires at least two compilations with every change in the height of the smaller images (or the position of the figure).

enter image description here

\documentclass{article}

\usepackage{graphicx}
\usepackage[savepos]{zref}

\newlength{\smallimagewidth}

\begin{document}

\begin{figure}
  \setlength{\tabcolsep}{3pt}% Space between images
  \setlength{\smallimagewidth}{15mm}% Small image width
  \begin{tabular}{ *{6}{c} }
    % Top row of images
    & 
      \zsaveposy{top-image}% Capture position of top row images (on the baseline)
      \includegraphics[width=\smallimagewidth]{example-image} &
      \includegraphics[width=\smallimagewidth]{example-image} &
      \includegraphics[width=\smallimagewidth]{example-image} &
      \includegraphics[width=\smallimagewidth]{example-image} &
      \includegraphics[width=\smallimagewidth]{example-image} \\
    &
      A &
      B &
      C &
      D &
      E \\
    % Bottom row of images
    \setbox0=\hbox{\includegraphics[width=\smallimagewidth]{example-image}}% Store top image in box
    % Insert larger image (height = 'top-image' + 'height of top image' - 'bottom image')
    \smash{\includegraphics[height=\dimexpr\zposy{top-image}sp+\ht0-\zposy{bottom-image}sp]{example-image}} &
      \zsaveposy{bottom-image}% Capture position of lower row of images
      \includegraphics[width=\smallimagewidth]{example-image} &
      \includegraphics[width=\smallimagewidth]{example-image} &
      \includegraphics[width=\smallimagewidth]{example-image} &
      \includegraphics[width=\smallimagewidth]{example-image} &
      \includegraphics[width=\smallimagewidth]{example-image} \\
    AAAA &
      F &
      G &
      H &
      I &
      J
  \end{tabular}
  \caption{A figure caption.}
\end{figure}

\end{document}

You can change the width of the smaller images by setting a different \smallimagewidth, while the separation between the images is given by \tabcolsep (the regular gap between columns within a tabular).

We \smash the larger images, so it doesn't interfere with the row spacing. This shouldn't matter, since the size is adjusted to line up with the heights set for the smaller images.

4

A bit of linear algebra:

\documentclass{article}
\usepackage[a4paper,margin=1cm]{geometry}
\usepackage{xfp}
\usepackage{graphicx}


\begin{document}

\begin{figure}[htp]

% measure the x/y ratio of the images
\sbox0{\includegraphics{example-image-16x9}}
\edef\q{\fpeval{(\ht0)/(\wd0)}}
\sbox2{\includegraphics{example-image}}
\edef\r{\fpeval{(\ht2)/(\wd2)}}

% height+depth of a strut
\edef\s{\fpeval{\ht\strutbox+\dp\strutbox}}

% target width (95% of textwidth)
\edef\t{\fpeval{0.95\textwidth}}

% if x is the desired width of the big image and
% u the desired width of the small images, then
%
% x+5u=t        % big image and five small ones
% qx+s=2ru+2s   % big image + caption = two small images and captions
%
% the system solves as
%
% x=(2rt+5s)/(2r+5q)
% u=(qt-s)/(2r+5q)

\edef\x{\fpeval{(2*\r*\t+5*\s)/(2*\r+5*\q)}pt}
\edef\u{\fpeval{(\q*\t-\s)/(2*\r+5*\q)}pt}

\renewcommand{\arraystretch}{0}
\setlength{\tabcolsep}{0pt}

\begin{tabular}{c}
\includegraphics[width=\x]{example-image-16x9}\\
\strut BSD68: 119082
\end{tabular}\hfill
\begin{tabular}{c}
\includegraphics[width=\u]{example-image}\\
\strut GT\\
\includegraphics[width=\u]{example-image}\\
\strut DnCNN [17]
\end{tabular}\hfill
\begin{tabular}{c}
\includegraphics[width=\u]{example-image}\\
\strut Noisy ($\sigma=50$)\\
\includegraphics[width=\u]{example-image}\\
\strut MemNet [18]
\end{tabular}\hfill
\begin{tabular}{c}
\includegraphics[width=\u]{example-image}\\
\strut BM3D [63]\\
\includegraphics[width=\u]{example-image}\\
\strut IRCNN [19]
\end{tabular}\hfill
\begin{tabular}{c}
\includegraphics[width=\u]{example-image}\\
\strut TNRD\\
\includegraphics[width=\u]{example-image}\\
\strut FFDNet [20]
\end{tabular}\hfill
\begin{tabular}{c}
\includegraphics[width=\u]{example-image}\\
\strut RED [16]\\
\includegraphics[width=\u]{example-image}\\
\strut RDN (ours)
\end{tabular}

\end{figure}

\end{document}

enter image description here

Explanation.

\q is the image ratio (height/width) of the big picture, \r that of the small ones; \x is the final width of the big picture, \u the final width of the small pictures; \t is 95% of the text width, to allow for some spacing between the pictures; \s is the height plus depth of a strut.

Thus we want that \x+5\u=\t and \q\x+\s=2\r\u+2\s. Solve the linear system.

I exploit the fact that \fpeval returns length as pure numbers representing the length in points.

1
  • Very very nice your affirmation "A bit of linear algebra"...and the code. :-)
    – Sebastiano
    Nov 21, 2019 at 23:54

You must log in to answer this question.

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