[Tex/LaTex] Figure very poorly placed

floatshorizontal alignment

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}

Best Answer

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

Related Question