Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I often encounter a situation where I would like to fit two or three figures on one page. I define my figures as follows:

\begin{figure}[htpb]     
\centering       
\includegraphics[width=0.xx\linewidth]{images/filename.png}     
\caption{Caption}   
\label{fig:tag}      
\end{figure}

The xx value depends on the size of the image I'm using and it takes some trial and error to find the optimal value. With square graphs xx=50 approximately.

I am looking for a way to avoid the trial and error part. I assume I need to use something else than \linewidth, but I don't know what.

Updates:

I've tried 0.5\pageheight instead of \linewidth but this is not satisfactory. I can fit two images on one page even if I use 0.6\pageheight for the size of each image. This is in landscape mode though. This is not logical to me as that would mean the two images together would span 1.2 times the height of the page.

I've also tried to set my height of the image in portrait mode just to test. I've set height=0.5\textheight and height=0.5\paperheight but both generate images that are too large to fit together on one page.

share|improve this question
    
If it is the height not the width that is the limiting factor you want height= not width= or you can specify both and use keepaspectratio so that it does not distort the image. –  David Carlisle Oct 10 '12 at 13:56
    
did you use 0.6\pageheight for the width or the height? –  jenson_bo Oct 10 '12 at 13:56
1  
Sorry, should've mentioned that I was in a landscape environment. But I just tried height=0.5\paperheight and height=0.5\textheight in normal portrait mode but both give images that don't fit on one page together. I've edited the Updates section to reflect my experiences. –  Bart Arondson Oct 10 '12 at 13:58
2  
keep in mind that the caption needs some space too. But even without the figure environment I need something like height=0.5\textheight and height=0.495\textheight to put two images on one page - cause there is a gap of 0.1em between the images. –  jenson_bo Oct 10 '12 at 14:13
    
Yes, I know the captions need some space, but I was hoping there would be some command which just places two images, including captions, on one page without fiddling to find the correct size. –  Bart Arondson Oct 10 '12 at 14:23

2 Answers 2

up vote 14 down vote accepted
+50

The following example assumes that the images can be scaled to the half of the text height, then the example measures the height of the captions and calculates the available height for the images.

\documentclass{article}
\usepackage[pass,showframe]{geometry}

\newsavebox\CaptionBoxA
\newsavebox\CaptionBoxB
\newlength\ImgHeight   

\begin{document}

\begin{figure}
  \vbox to \textheight{%
    \centering
    \setbox\CaptionBoxA=\vbox{%
      \begingroup % color support
        \centering
        \caption{My first figure}%
        \label{fig:first}%
      \endgroup
    }
    \setbox\CaptionBoxB=\vbox{%
      \begingroup % color support
        \centering
        \caption{My second figure}%
        \label{fig:second}%
      \endgroup
    }
    \setlength{\ImgHeight}{%
      .5\dimexpr\textheight 
        -\ht\CaptionBoxA-\dp\CaptionBoxA
        -\ht\CaptionBoxB-\dp\CaptionBoxB
        -\floatsep
      \relax
    }

    \rule{10mm}{\ImgHeight}%
    % \includegraphics[height=\ImgHeight,width=\linewidth,keepaspectratio]{...}

    \unvbox\CaptionBoxA

    \vspace{\floatsep}
    \vspace{0pt minus .25\floatsep}% glue for safety
    \vspace{0pt plus 1fil}% glue for smaller images 
    \nointerlineskip % interline skip affects the calculation of \ImgHeight

    \rule{10mm}{\ImgHeight}
    % \includegraphics[height=\ImgHeight,width=\linewidth,keepaspectratio]{...}

    \unvbox\CaptionBoxB
    % \vspace{0pt plus 1fil}% glue for smaller images
}
\end{figure}

\end{document}

Result with paper size A5 and rules instead of images:

Result

Remarks:

  • The code would have to be put in a macro for practical usage.
  • There is room for improvements. For example, the available space is equally distributed among the images. If one image cannot be scaled to the available space because of width limitations, then the other image could grow.
  • There is room for extensions (three and more images, ...).
share|improve this answer
    
works great and there's room for tweaking. Thanks a lot! –  Bart Arondson Oct 20 '12 at 20:30
    
After running it a couple of times I noticed LaTeX chokes on \usepackage[pass,showframe]{geometry}. It says: Option clash for package geometry. If I delete the arguments I don't get the error anymore. –  Bart Arondson Oct 23 '12 at 19:09
1  
@BartArondson The \usepackage[pass,showframe] was just added for showing the page layout. Thus you do not need it for your real world file. If you want to see the page layout, just add showframe to your option list of geometry or use \PassOptionsToPackage{showframe}{geometry} right at the beginning of the file. –  Heiko Oberdiek Oct 23 '12 at 19:18

Edit: I think that @Heiko Oberdiek's answer is way more pro than mine. These are just a couple tricks. I'm not even sure why, but so far, these seem to work for me.

Maybe this answer is not even very TeX-like, but I'm a graphic designer with some experience, and just based on sheer amount of trial and error routines in the past, I am now accustomed to get two/three figures per page (or more) using a size of 45% the text height for two vertical images, or 45% the text width, for the horizontal ones. Use 30% for three images, etc. The trick is always leave around 10% of the \textwhatever free. It also helps a lot placing figures inside minipages, see this example (adapted to latex from other examples found in the LyX Wiki):

\documentclass[10pt]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{4}
\usepackage{graphicx}

% Remember that line breaks matter. 
\begin{document}
% this some image i have, use your own...
\begin{minipage}[c][1\totalheight][t]{0.3\columnwidth}
\centering

\includegraphics[width=1\textwidth]{img/_orig/c2/c2-img2}%
\end{minipage}\hfill{}%
\begin{minipage}[c][1\totalheight][t]{0.3\columnwidth}%
\centering

\includegraphics[width=1\textwidth]{img/_orig/c2/c2-img2}%
\end{minipage}\hfill{}%
\begin{minipage}[c][1\totalheight][t]{0.3\columnwidth}%
\centering

\includegraphics[width=1\textwidth]{img/_orig/c2/c2-img2}%
\end{minipage}\\
[0.25cm]

\begin{minipage}[c][1\totalheight][t]{0.3\columnwidth}%
\centering

\includegraphics[width=1\textwidth]{img/_orig/c2/c2-img2}\\
[0.25cm]\includegraphics[width=1\textwidth]{img/_orig/c2/c2-img2}%
\end{minipage}\hfill{}%
\begin{minipage}[c][1\totalheight][t]{0.3\columnwidth}%
\centering

Several images in one page.%
\end{minipage}\hfill{}%
\begin{minipage}[c][1\totalheight][t]{0.3\columnwidth}%
\centering

\includegraphics[width=1\textwidth]{img/_orig/c2/c2-img2}\\
[0.25cm]\includegraphics[width=1\textwidth]{img/_orig/c2/c2-img2}%
\end{minipage}\\
[0.25cm]

\begin{minipage}[c][1\totalheight][t]{0.3\columnwidth}%
\centering

\includegraphics[width=1\textwidth]{img/_orig/c2/c2-img2}%
\end{minipage}\hfill{}%
\begin{minipage}[c][1\totalheight][t]{0.3\columnwidth}%
\centering

\includegraphics[width=1\textwidth]{img/_orig/c2/c2-img2}%
\end{minipage}\hfill{}%
\begin{minipage}[c][1\totalheight][t]{0.3\columnwidth}%
\centering

\includegraphics[width=1\textwidth]{img/_orig/c2/c2-img2}%
\end{minipage}
\end{document}
share|improve this answer
1  
Sorry, I am looking more for a "pro" solution, so thanks for your effort, but Heiko Oberdiek did a better job. –  Bart Arondson Oct 20 '12 at 20:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.