0

Problem: I have groupings of images to be displayed together on a single page. They are groups of two, three, four, or five. Some should be grouped/displayed horizontally on a single page with captions centered under each while others should be grouped/displayed vertically. For some groups the spacing should be very minimal but evident.

Question: How do I control the spacing or positioning of the images to get them next to each other as described?

Example (with every package I'm using):

% BEGIN PREAMBLE

\documentclass[fleqn,12pt]{memoir}
\pagestyle{headings}
\setlength{\headheight}{14.5pt}
\usepackage{calc}

\makeevenhead{headings}{}{}{Some Images}
\makeoddhead{headings}{Some Images}{}{}
\makeevenfoot{headings}{}{}{\thepage}
\makeoddfoot{headings}{\thepage}{}{}

\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{latexsym}
\usepackage{amsmath}

\usepackage{graphicx}
\usepackage{caption}
\usepackage{microtype}
\usepackage{booktabs}

\usepackage{enumitem}

\addtolength{\oddsidemargin}{-.875in}
\addtolength{\evensidemargin}{-.875in}
\addtolength{\textwidth}{1.75in}

\addtolength{\topmargin}{-.875in}
\addtolength{\textheight}{1.75in}

% END PREAMBLE

\begin{document}\thispagestyle{empty}

\vspace*{200pt}

\begin{center}
\Huge{\textbf{Some Images}}
\end{center}

\newpage

\vspace*{200pt}

\noindent Some introductory paragraph goes here.

\bigskip

A second introductory paragraph here.

\newpage

\vspace*{75pt}

\begin{center}
\includegraphics[scale=0.60]{image file name #1}
\captionof*{figure}{Image Name #1}
\end{center}

\begin{center}
\includegraphics[scale=0.90]{Image file name #2}
\captionof*{figure}{Image Name #2}
\end{center}

\end{document}
1

1 Answer 1

1

First of all, I would suggest to load blindtext package and use \Blinddocument to test layouts. If you insert \blindmathtrue, the dummy text also contains equations.

You can easily distribute images across a page. Stack images line by line (without double empty lines) and latex will put everything next one another. Just make sure they fit the width. Additionally, the tools from subcaption help with captioning. The example below is based on \subcaptionbox but there are many other solutions.

A few options are possible when make horizontal groups. They lead to different arrangements. All the cases discussed below assume centring via \centering macro:

  • don't append anything after an image and let LaTeX add space
\subcaptionbox{...}{...}
% ...
\subcaptionbox{...}{...}

If you want to increase the spacing, use \hspace{}, \qquad etc.

  • distribute images with equal spacing before, after and between images; here you should append \hfil after every image but the last one
\subcaptionbox{...}{...}\hfil
\subcaptionbox{...}{...}\hfil
% ...
\subcaptionbox{...}{...}
  • similarly to the previous case, distribute images with equal spacing but let images stick to margins; simply append \hfill instead of \hfil.

Below is a code with example. The line of geometry is only added for the demo, which produces a reference frame to show the current layout. sidewaysfigure (package rotating) is one way to render a content vertically. You should use \clearpage instead of \newpage. I'd also recommend on figure floats to let LaTeX optimise pages.

\documentclass[fleqn,12pt]{memoir}
% \usepackage{calc}
% \usepackage{amssymb}
% \usepackage{amsmath}
\usepackage{graphicx}
\usepackage{subcaption}
% \usepackage{microtype}
% \usepackage{booktabs}
% \usepackage{enumitem}
\usepackage{rotating}
\usepackage{blindtext}

\makeevenhead{headings}{}{}{Some Images}
\makeoddhead{headings}{Some Images}{}{}
\makeevenfoot{headings}{}{}{\thepage}
\makeoddfoot{headings}{\thepage}{}{}

\addtolength{\oddsidemargin}{-.875in}
\addtolength{\evensidemargin}{-.875in}
\addtolength{\textwidth}{1.75in}

\addtolength{\topmargin}{-.875in}
\addtolength{\textheight}{1.75in}

\pagestyle{headings}
\setlength{\headheight}{14.5pt}
% END PREAMBLE

\usepackage[pass,showframe]{geometry}


%%% DOCUMENT
\begin{document}
\thispagestyle{empty}

\vspace*{200pt}

\begin{center}
\Huge{\textbf{Some Images}}
\end{center}

\blindmathtrue\Blinddocument

\begin{figure}[tbh]
  \setkeys{Gin}{width=0.3\linewidth}   % all immages in the group gain optioanal arguments 
  \centering
  \subcaptionbox{Image Name 1}{\includegraphics{example-image-a}}\qquad
  \subcaptionbox{Image Name 2}{\includegraphics{example-image-b}}
  \caption{Group of two images}\label{fig:group-imageb1}
\end{figure}

\blindtext

\begin{figure}[tbh]
  \setkeys{Gin}{width=0.3\linewidth}   % all immages in the group gain optioanal arguments 
  \centering
  \subcaptionbox{Image Name 1\label{fig:11}}{\includegraphics{example-image-a}}\hfil
  \subcaptionbox{Image Name 2\label{fig:12}}{\includegraphics{example-image-b}}\hfil
  \subcaptionbox{Image Name 3\label{fig:13}}{\includegraphics{example-image-c}}
  \caption{Group of three images}\label{fig:group-images2}
\end{figure}

\blindtext

\begin{figure}[tbh]
  \setkeys{Gin}{width=0.18\linewidth}
  \centering
  \subcaptionbox{Image 1\label{fig:21}}{\includegraphics{example-image-duck}}\hfill
  \subcaptionbox{Image 2\label{fig:22}}{\includegraphics{example-image-duck}}\hfill
  \subcaptionbox{Image 3\label{fig:23}}{\includegraphics{example-image-duck}}\hfill
  \subcaptionbox{Image 4\label{fig:24}}{\includegraphics{example-image-duck}}\hfill
  \subcaptionbox{Image 5\label{fig:25}}{\includegraphics{example-image-duck}}
  \caption{Group of five images}\label{fig:group-images-3}
\end{figure}

\blindtext

\begin{sidewaysfigure}[tbh]
  \setkeys{Gin}{width=0.14\linewidth}
  \captionsetup{position=bottom,belowskip=3ex}
  \centering
  \subcaptionbox{Image 1}{\includegraphics{example-image}}\hfill
  \subcaptionbox{Image 2}{\includegraphics{example-image}}\hfill
  \subcaptionbox{Image 3}{\includegraphics{example-image}}\hfill
  \subcaptionbox{Image 4}{\includegraphics{example-image}}\hfill
  \subcaptionbox{Image 5}{\includegraphics{example-image}}\hfill
  \subcaptionbox{Image 6}{\includegraphics{example-image}}
  \par
  \subcaptionbox{Image 7}{\includegraphics{example-image}}\hfill
  \subcaptionbox{Image 8}{\includegraphics{example-image}}\hfill
  \subcaptionbox{Image 9}{\includegraphics{example-image}}\hfill
  \subcaptionbox{Image 10}{\includegraphics{example-image}}\hfill
  \subcaptionbox{Image 11}{\includegraphics{example-image}}\hfill
  \subcaptionbox{Image 12}{\includegraphics{example-image}}
  \par
  \subcaptionbox{Image 13}{\includegraphics{example-image}}\hfill
  \subcaptionbox{Image 14}{\includegraphics{example-image}}\hfill
  \subcaptionbox{Image 15}{\includegraphics{example-image}}\hfill
  \subcaptionbox{Image 16}{\includegraphics{example-image}}\hfill
  \subcaptionbox{Image 17}{\includegraphics{example-image}}\hfill
  \subcaptionbox{Image 18}{\includegraphics{example-image}}
  \caption{Grid of images}\label{fig:grid-images}
\end{sidewaysfigure}

Reference: figure~\ref{fig:11} and figure~\ref{fig:23}.
\end{document}
4
  • Why \clearpage and not \newpage?
    – E2R0NS
    Sep 8 at 22:53
  • 1
    It does more than just page break. Here's a good explanation: tex.stackexchange.com/a/497776/31283
    – Celdor
    Sep 8 at 23:37
  • Why \centering and not the center environment as in my original code?
    – E2R0NS
    Sep 8 at 23:50
  • 1
    It doesn't mean you should not use center environment at all; center adds some extra spacing around it, so it has its use cases. \centering is barely a switch meaning that is everything in the same scope onward will be centred. Since each float environment, s.a. figure and table, also adds spacing, you should just use \centering in those cases.
    – Celdor
    Sep 9 at 12:19

You must log in to answer this question.

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