1

I'm trying to fit four figures with various sizes into a table on one page. I started with the following code, but couldn't figure out how to get it work. How can I achieve that?

begin{figure}
\begin{tabular}{ll}
  \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{fig1.jpg} &
  \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{fig2.jpg} \\
  \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{fig3.pdf} & 
  \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{fig4.pdf} \\
\end{tabular}
\end{figure}
ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
bluepole
  • 529

1 Answers1

1

Besides reducing \textwidth to some less than 50%, in general it could be better change this length to \linewidth. Many times is exactly the same length, but when this is not true, probably what you want really is \linewidth, not \textwidth nor \columnwidth. See Automatically set the figure width depending on whether the layout is one or two column.

To reduce typing of repeated code in the next example I used a rudimentary macro, I hope this will be not confusing. It show two floats, with and without subcaptions, where using \linewidth does matter even in documents with only one column.

MWE

\documentclass{article}
\usepackage[demo]{graphicx} % remove "demo" to use with your images
\usepackage{subcaption}

% macro only to simplify floats code 
% now  \linewidth  = \textwidth 

\newcommand\myfig[1]{%
\includegraphics[width=.49\linewidth,height=.2\textheight,keepaspectratio]{#1}}

\begin{document}

% simple example without subcaptions
\begin{figure}
\centering
\myfig{fig1.jpg}\hfill\myfig{fig2.jpg}\\[1ex]
\myfig{fig3.dpf}\hfill\myfig{fig4.dpf}\\
\caption{Four images}
\end{figure}


% example with subcaptions

\renewcommand\myfig[1]{%
\includegraphics[width=.95\linewidth,height=.5\linewidth,keepaspectratio]{#1}}

% Note that now the image width will be the  95% of the
% subfigure line width, that is less than the 48% of the 
% line width (= text width) of the main text.    

\begin{figure}
\centering
\begin{subfigure}[t]{0.48\linewidth}
\myfig{fig1.jpg}
\caption{fig1}%
\end{subfigure}
\begin{subfigure}[t]{0.48\linewidth}
\myfig{fig2.jpg}
\caption{fig2}
\end{subfigure}

\begin{subfigure}[t]{0.48\linewidth}
\myfig{fig3.pdf}
\caption{fig3}
\end{subfigure}
\begin{subfigure}[t]{0.48\linewidth}
\myfig{fig4.pdf}
\caption{fig4}
\end{subfigure}

\caption{Four images again}

\end{figure}


\end{document}
Moriambar
  • 11,466
Fran
  • 80,769