5

This works to create a nice matrix, but rather than selecting the width, can I automatically make it scale to full line width, by setting a width percentage in one image, or do have to use width=0.25\textwidth in every line?

\begin{figure}[h]
\begin{center}$
\begin{array}{cccc}
\includegraphics[width=1in]{image1} &
\includegraphics[width=1in]{image2} \\ 
\includegraphics[width=1in]{image3} &
\includegraphics[width=1in]{image4} 
\end{array}$
\end{center}
\caption{my caption}
\end{figure}

1 Answer 1

6

Yes, it can be done with \resizebox.

I also use a trick for making the space between the figures the same horizontally and vertically.

\documentclass{article}
\usepackage{graphicx,booktabs}

\usepackage{lipsum}

\begin{document}

\lipsum[3]

\begin{figure}[htp] % not just h
\centering % not center

\resizebox{\textwidth}{!}{%
  \renewcommand{\arraystretch}{0}%
  \begin{tabular}{@{}c@{\hspace{3pt}}c@{}}
  \includegraphics[width=1in]{example-image.pdf} &
  \includegraphics[width=1in]{example-image-a.pdf} \\
  \addlinespace[3pt]
  \includegraphics[width=1in]{example-image-b.pdf} &
  \includegraphics[width=1in]{example-image-c.pdf} 
  \end{tabular}% <-- don't forget
}

\caption{my caption}

\end{figure}

\lipsum[4]

\end{document}

enter image description here

For 3 by 3 arrangement it is similar.

\documentclass{article}
\usepackage{graphicx,booktabs}

\usepackage{lipsum}

\begin{document}

\lipsum[3]

\begin{figure}[htp] % not just h
\centering % not center

\resizebox{\textwidth}{!}{%
  \renewcommand{\arraystretch}{0}%
  \begin{tabular}{@{}c@{\hspace{3pt}}c@{\hspace{3pt}}c@{}}
  \includegraphics[width=1in]{example-image.pdf} &
  \includegraphics[width=1in]{example-image.pdf} &
  \includegraphics[width=1in]{example-image-a.pdf} \\
  \addlinespace[3pt]
  \includegraphics[width=1in]{example-image-b.pdf} &
  \includegraphics[width=1in]{example-image-b.pdf} &
  \includegraphics[width=1in]{example-image-c.pdf} \\
  \addlinespace[3pt]
  \includegraphics[width=1in]{example-image-b.pdf} &
  \includegraphics[width=1in]{example-image-b.pdf} &
  \includegraphics[width=1in]{example-image-c.pdf} 
  \end{tabular}% <-- don't forget
}

\caption{my caption}

\end{figure}

\lipsum[4]

\end{document}

enter image description here

2
  • Oh, you are right. I just now realized that the difference in horizontal and vertical space between the images in my version looked shabby. Could you please elaborate on how to expand your code to 3x3? I am confused by the @{} and the hspace?
    – Jannis
    May 15, 2018 at 22:19
  • 1
    @Jannis Just do \begin{tabular}{@{}c@{\hspace{3pt}}c@{\hspace{3pt}}c@{}}. With @{} we remove the outer padding, with @{\hspace{3pt}} we set an intercolumn space of 3pt (that will be scaled, of course). I added the code.
    – egreg
    May 15, 2018 at 22:23

You must log in to answer this question.

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