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 am using pdflatex with PDF images for figures. When I do not scale the image, the figure goes off the page. When I do scale the image, it is very poorly placed. A little too far to the right of the page. I know something is not correct, because not only does the placement look terrible, but when I put a frame around the float, the frame crosses the image.

Here is a minimal working example. I'm not sure how to include the PDF image here. The image is a horizontally long image, not a standard size. I guess this might be the problem? How does one deal with this issue?

\documentclass{article}
\usepackage{graphicx}
\usepackage{float}
\begin{document}
\section{Section Title}
\begin{figure}[h]
  \caption{Blah blah}
  \includegraphics[scale=.4]{Graph.pdf}
\end{figure}
\end{document}
share|improve this question
2  
You should post an image of the exact display produced from your minimal working example. Since a "frame crosses the image", this may be an issue with the image bounding box. You should either correct for this using the bb=lx ly ux uy option of \includegraphics, or recreate the image with a correctly cropped bounding box. What package did you use to create the image? –  Werner Dec 1 '11 at 6:56
add comment

3 Answers

up vote 7 down vote accepted

Using scale, leads to a lot of problems, especially if you have images with different aspect ratios, rather limit the size of the image by using width and height as follows:

\includegraphics[width=\textwidth, height=\textheight, keepaspectratio]{Graph.pdf}

The image will either be scaled so as not to exceed any of the two limits and will keep the aspect ratio correct.

You can also use actual dimensions, instead of of \textwidth or \textheight and also values such as 0.7\textwidth.

Just a short explanation also why it is always good to include both a textwidth as well as a textheight. The number of floats and the amount of vertical space they can occupy on a page is controlled by a number of parameters. For example topfraction controls the top fraction of the page that can be occupied by a top float. In my opinion default settings are set too low ending up with relatively small images occupying full pages.

Try the minimal below. Then change \topfraction to 0.6 and try again. From two nicely looking pages, you will end with a lot of emptiness and three pages.

\documentclass[crown]{octavo}
\usepackage[showframe=true]{geometry}
\usepackage{graphicx,lipsum,caption}
 \renewcommand{\topfraction}{0.9}   % max fraction of floats at top change to 0.6
 \renewcommand{\bottomfraction}{0.9}% max fraction of floats at bottom
    %   Parameters for TEXT pages (not float pages):
 \setcounter{topnumber}{2}
 \setcounter{bottomnumber}{2}
\setcounter{totalnumber}{4}     % 2 may work better
\setcounter{dbltopnumber}{2}    % for 2-column pages
\renewcommand{\dbltopfraction}{0.7} % fit big float above 2-col. text
\renewcommand{\textfraction}{0.07}  % allow minimal text w. figs
 %   Parameters for FLOAT pages 
 \renewcommand{\floatpagefraction}{0.7}
% floatpagefraction must be less than topfraction !!
\renewcommand{\dblfloatpagefraction}{0.7} 
\begin{document}%
First page image will go to next page, if topfraction is less than 0.71

\begin{figure}[tp]
\rule{\textwidth}{0.71\textheight} 
\captionof{figure}{First Figure}
\end{figure}

\lipsum[1]

\begin{figure}[tp]
\rule{\textwidth}{0.3\textheight} 
\captionof{figure}{Second Figure}
\end{figure}
\end{document}

The second reason which is more obvious for including a height in the specs, is not to cause overflow at the bottom, as with the image below that I set width=\textwidth. This case is very obvious, but if you have figures that are more or less squarish this can trip you.

The best strategy for a book with a lot of figures, is to standardize on a number of image sizes and carefully set all parameters.

enter image description here

share|improve this answer
1  
The scale does preserve aspect ratio: I wonder what you mean here. –  Joseph Wright Dec 1 '11 at 6:58
    
@Joseph Yes it does. If you though scale to 0.5 an image which is 3 times the width of \textwidth it will overflow, hence I am recommending not to use scale but rather natural page limits. Same scale also would give problems with thin tall figures etc... –  Yiannis Lazarides Dec 1 '11 at 7:08
    
Well yes, if you don't do a first 'survey' typesetting without the scale! I'm also not sure why you use both the width and height keys: if you use only one, the aspect ratio is preserved automatically. –  Joseph Wright Dec 1 '11 at 8:15
3  
@JosephWright I will post some more details and an example in the evening, but imagine that you have an image which is equal to textwidth + 3 mm, but has a natural image height of textheight+5cm. If you only specify that width=textwidth, it will still overflow at the bottom; hence my preference for always if possible to specify both. Where the images are in floats a height limit is advisable as well to ensure that the limits on the fraction of a page that can be occupied by floats is not exceeded for a few mm and the image disappears to another page or even to the end of the document. –  Yiannis Lazarides Dec 1 '11 at 9:18
    
I was using Mathematica to produce the images. My solution was on the Mathematica side, I just reduced the size of the images to be put into the document and it fixed the problem. Thank you for your explanation. There is a lot of information here, so I will have to come back to the post when I am finished with the report I'm working on since I was able to get it working for now. Thank you again for the explanation. –  Bre Dec 2 '11 at 21:02
add comment

Have you tried using \centering

 \begin{figure}[h]
 \centering
 \caption{Blah blah}
 \includegraphics[scale=.4]{Graph.pdf}
 \end{figure}
share|improve this answer
add comment

The following code let's you scale the image to the full width of the textblock (which is the most you can get without having the image stick out on the left or right, or on both sides):

\begin{figure}[ht]
\includegraphics[width=\textwidth]{Graph.pdf}
\caption{Blah blah} \label{fig:blahblah}
\end{figure}

If the width of the textblock is insufficient to do justice to the image, you could try rotating the entire figure float by 90 degrees ("portrait mode" on the piece of paper). To do so, you could use the sidewaysfigure environment, which is provided by the rotating package. You'd type \usepackage{rotating} in the preamble and later

\begin{sidewaysfigure}
\includegraphics[width=\textwidth]{Graph.pdf}
\caption{Blah blah} \label{fig:blahblah}
\end{sidewaysfigure}

Sideways-figures are placed automatically on separate pages, hence there's no need to add a [h] or [ht] location specifier.

share|improve this answer
add comment

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.