Use \textwidth
for the width of the text block, and \paperwidth
if you want to fit it into the paper width. You could also use \linewidth
if you want to fit the image within the line width, which may vary depending on the environment you're in (for example, within a list like enumerate
).
Note that if you use \includegraphics
outside a figure
or table
environment, you might want to prepend it with \noindent
to avoid the image being pushed over to the right by \parindent
. Also, centering the image within the page width (when using \paperwidth
) is best obtained using
\begin{center}
\makebox[\textwidth]{\includegraphics[width=\paperwidth]{...}}
\end{center}
or
\noindent\makebox[\textwidth]{\includegraphics[width=\paperwidth]{...}}
In both instances it typesets a box of width \textwidth
, while the contents may stretch outside this width (given by width=\paperwidth
). Fixing it to \textwidth
avoids Overfull \hbox warnings
.
This works as expected within the article
and report
document class, while some horizontal re-adjustment is required in book
. For completeness, and without resorting to page numbering issues that may occur at shipout if the image is placed near a page break, the following \centerimg[<options>]{<image>}
command works for all standard document classes, including book
:
\documentclass{article}
\usepackage{graphicx,changepage}
\newcommand{\adjustimg}{% Horizontal adjustment of image
\checkoddpage%
\ifoddpage\hspace*{\dimexpr\evensidemargin-\oddsidemargin}\else\hspace*{-\dimexpr\evensidemargin-\oddsidemargin}\fi%
}
\newcommand{\centerimg}[2][width=\textwidth]{% Center an image
\makebox[\textwidth]{\adjustimg\includegraphics[#1]{#2}}%
}
\begin{document}
\mbox{} \par
\noindent\centerimg[width=\paperwidth,height=200pt]{tiger}
\newpage
\mbox{} \par
\noindent\centerimg[width=\paperwidth,height=200pt]{tiger}
\end{document}
The horizontal adjustment for book
(obtained via \adjustimg
) depends on whether the page number is odd or even. The above MWE, with the tiger
image, compiles to the output:
The problem is that most multiline constructs have the current linewidth as the resulting width, so rescaling them does not make sense anyway. However, you can try the \resizebox
on something like
\begin{tabular}{@{}c@{}}
foo\\
bar
\end{tabular}
and should have reasonable chances for success (the @{}
take away the normal per-column padding).
Best Answer
Use
graphicx
package instead ofgraphics
, as only the former supports the key-value syntax. For thegraphics
version, one needs to useSee eg Packages: graphics vs graphicx and detailed guide on graphics with LaTeX.