# Prevent image from automatically centering?

I'm inserting an image like so...

\begin{figure}[h!]
\includegraphics[width=400mm]{wut.png}
\caption{Gantt Chart}
\end{figure}


However, the image is automatically beginning in the center of my page and due to its size it's running off of the right hand side of the page. How would I force this image to begin at the left margin?

-
Looks like you dimension needs to be: width=40mm. 400mm is too big. –  Peter Grill Jan 11 '12 at 23:18
The contents of figure is not centered by default. If you try \fbox{\includegraphics{wut.png}} you'll probably see that it has some white border around it. –  egreg Jan 11 '12 at 23:20
@egreg Yes, but the content starts where the text does. I'd like the image to begin where the "page" begins, not where the text does. –  Skizit Jan 11 '12 at 23:28
tex.stackexchange.com/questions/16582/… might be helpful for you. –  doncherry Jan 12 '12 at 0:39

## 3 Answers

The image is not centering; it is just too large for the text area, where you want it inserted. A technique I use is to pull it out into the margin. However, if you are on double sided paper, you will need to take care of odd or even pages.

Essentially what you do is to add an hspace{<length>} in front of \includegraphics. In the minimal below I calculate it (see \imagehskip) and allow a bit of a bleed at the paper edges. Since you want it printed "here", you might as well get rid of the float and add the caption with the caption image (as it might also need adjustments). The amount of pull will depend on the width of the image and the class you use. Just experiment a bit.

For very wide images (you need a centerfold) that is the image needs to be spread over two pages.

These are much easier (if they occupy the full page height).

% First page
\includegraphics[height=0.95\textheight]{./graphics/africamedics}
% second page
\hspace*{-\textwidth} \includegraphics[height=0.95\textheight]{./graphics/africamedics}


Here is a rather long minimal

\documentclass[twoside]{book}
\usepackage[latin,english]{babel}
\usepackage{graphicx,lipsum,lettrine,xcolor,rotating}
\usepackage{multicol,caption}
\RequirePackage[showframe=false]{geometry}
\IfFileExists{changepage.sty}{\RequirePackage{changepage}}{}
\makeatletter
%% redefine LaTeX's plain as myplain for headings
\def\ps@myplain{\let\@mkboth\@gobbletwo
\let\@oddhead\@empty\def\@oddfoot{\reset@font\hfil\thepage}
\let\@evenhead\@empty\def\@evenfoot{\reset@font\thepage\hfil}}
%

%% Watermark package with small footprint
%% for more sophisticated macros use TikZ
\def\even@samplepage{%
\begin{picture}(0,0)
\put(\Xeven,\Yeven){\turnbox{90}{\Huge \textcolor{\watermark@textcolor}{\watermark@text}}}
\end{picture}
}
%% Define a macro to print SAMPLE PAGE IN THE MARGIN
\def\odd@samplepage{%
\begin{picture}(0,0)
\put(\Xodd,\Yodd){\turnbox{90}{\Huge \textcolor{\watermark@textcolor}{\watermark@text}}}
\end{picture}
}
%% Define the watermark words
\def\watermarktext#1{\gdef\watermark@text{\fontfamily{phv}\selectfont#1}}
\def\watermarktextcolor#1{\gdef\watermark@textcolor{#1}}
\watermarktext{PRE-PRINT}
\watermarktextcolor{purple}

%% redefine LaTeX's plain as myplain for headings
\def\ps@samplepage{\let\@mkboth\@gobbletwo
\let\@oddhead\odd@samplepage\def\@oddfoot{\reset@font\hfil\thepage}
\let\@evenhead\even@samplepage\def\@evenfoot{\reset@font\thepage\hfil}}
%%
%
%% We define two macros to position the watermark on the page
\def\Xodd{500}
\def\Xeven{-70}\def\Yeven{-810}
\def\Yeven{-\expandafter\strip@pt\textheight}
\let\Yodd\Yeven

\newlength\bleed@clearance
\setlength\bleed@clearance{0mm}
%% image corrections
%\the\dimexpr
%1in+\marginparwidth+\textwidth+\marginparsep+\evensidemargin-0.8in\relax
\newlength\oddcorrection
%\setlength\oddcorrection{\dimexpr(-1in-\oddsidemargin)+\bleed@clearance\relax}
\setlength\oddcorrection{\dimexpr(-1in+\oddsidemargin-\marginparsep+7pt)+\bleed@clearance\relax}

\newlength\evencorrection
\setlength\evencorrection{\dimexpr(-\marginparwidth-\marginparsep-\oddsidemargin-1pt)\relax}
%% caption related
\newlength\captiontextwidth
\setlength\captiontextwidth{\dimexpr 0.7\paperwidth\relax}
%% caption corrections
%\newlength\oddclearance
%\setlength\oddclearance{\dimexpr 7cm\relax}
%\newlength\evenclearance
%\setlength\evenclearance\bleed@clearance
%
%  we set two macros to cater for recto and verso
%  pages
%  \imagehskip is the shift of the image
%  we use changepage tofind out
%  if we recto or verso
\def\imagehskip{%
\checkoddpage%
\if@twoside%
\ifoddpage%
\noindent\hspace*{\oddcorrection}%
\else%
\hspace*{\evencorrection}%
\fi%
\else
\noindent\hspace*{\oddcorrection}%
\fi
}%
% similarly define the captionskip amount. This also will
% depend on the paper setout as well as the page being
% recto or verso.
\def\captionhskip{%
\checkoddpage
\if@twoside%
\ifoddpage%
%% Need to define a small margin at the end, if bleed is zero is a problem 50pt
\hspace*{\dimexpr \oddcorrection-\bleed@clearance+0.3\paperwidth-50pt\relax}%
\else%
\hspace*{\dimexpr-1in-\oddsidemargin-\marginparsep\relax}%
\fi%
\else%
\hspace*{\dimexpr 0.25\paperwidth+\oddcorrection-\bleed@clearance\relax}%
\fi%
}%
%%
%% we check for odd and even numbers with the changepage package.
%% we first check if the page is odd.
%
%% Include the graphic
%% The image needs to be the sixe of the paper - clearance
\def\addimage#1{%
\checkoddpage%
%% The image width is determined by the paper width - bleed clearance
\imagehskip\includegraphics[width=\dimexpr\paperwidth-\bleed@clearance\relax]{./graphics/#1}%
\par%
\vspace{0.5\baselineskip}%
}% do a vsplit here
%
\newcommand\addcaption[2][A heading]{%
\captionhskip
\vbox\bgroup
\hsize\captiontextwidth
\parindent0pt\textbf{#1}\quad#2\par
\egroup
%\vfill\vfill
}%
%% The multicol caption, displays its caption as multicolumns
%%  it uses the package multicol with a default setting of 3 columns
%%
\newcommand\addmulticolcaption[2][3]{%
\begin{multicols}{#1}
#2
\end{multicols}
\par
} %
%

\pagestyle{samplepage}
\begin{document}
\newgeometry{top=5mm,bottom=15mm}
.
\newpage
%% First page
\thispagestyle{samplepage}
\clearpage
\addimage{botticelli02}\par
\addcaption{\protect\lipsum[1]}\par
\bigskip
\lettrine{M}{adonna}\lipsum*[3]
\par

\clearpage
%% First page
\clearpage
\addimage{botticelli02}\par
\addcaption{\protect\lipsum[1]}\par
\bigskip
\lettrine{M}{adonna}\lipsum*[3-4]
\par
\clearpage
%% First page
\addimage{botticelli16}
\addcaption{\protect\lipsum*[3]}

\restoregeometry
\end{document}

-

As egreg commented, the figure environment does not center by default. If you reduce your dimensions you see that the figure is left aligned exactly where the the left margin of the page begins. The [showframe] option is used with the geometry package to show where the margins of the page are:

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage[demo]{graphicx}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{figure}[h!]
\includegraphics[width=100mm]{wut.png}
\caption{Gantt Chart}
\end{figure}
\end{document}​

-

(This is basically the same as http://tex.stackexchange.com/a/16584/4012 and http://tex.stackexchange.com/a/39148/4012.)

Here's a solution with the phenomenal paper width of 410mm, assuming you don't want to scale your picture, as your question kinda implies. If you're willing to scale your picture, which might be necessary in case you don't have 410mm-paper handy, get rid of the line with geometry and embed the picture e.g. with \includegraphics[width=0.9\paperwidth]{wut.png}, which might look decent.

Note that the picture is centered in this example. Having it start at the left border of the page would require different code, but then it'd be good to know what paper we're using, how wide the image is supposed to be etc. This solution might just work for you though.

\documentclass{article}

\usepackage[demo]{graphicx}% demo because I don't have your file.

\usepackage[paperwidth=410mm,showframe]{geometry}
% showframe to show where normal text would end

\begin{document}
\begin{figure}[h!]
\makebox[\textwidth][c]{\includegraphics[width=400mm]{wut.png}}
\caption{Gantt Chart}
\end{figure}
\end{document}


-