[Tex/LaTex] How to get the true width (including margins) of a page for inserting images? \textwidth and \textheight are too large

graphicsmargins

When I enter the following:

text width in cm: \printinunitsof{cm}\prntlen{\textwidth}

text height in cm: \printinunitsof{cm}\prntlen{\textheight}

I see output:

text width in cm: 15.11078cm
text height in cm: 21.58693cm

However, when I create an image exactly 15cm by 21cm, and insert it into my document, it is far too large, by about the amount of the margin sizes.

I was under the impression that textwidth was supposed to be only the text box, already accounting for margins. Why is the output I see too large?

I'm looking to include some pre-sized images in my document but can't divide the page in any reasonable way without knowing how large it is. Any hints on what is going on with the output above, or how I might do this better?

EDIT, updated to include MWE

\documentclass[12pt]{report}
\usepackage{graphicx} % Required for inserting images
\usepackage{layouts}
\usepackage{lipsum}
\graphicspath{{/my/path}}
\DeclareGraphicsExtensions{.png}

\begin{document}

text width in cm: \printinunitsof{cm}\prntlen{\textwidth}

text height in cm: \printinunitsof{cm}\prntlen{\textheight}

line width in cm: \printinunitsof{cm}\prntlen{\linewidth}

column width in cm: \printinunitsof{cm}\prntlen{\columnwidth}

\lipsum{1-4}

\newpage

%\makebox[\textwidth][c]{\includegraphics{/my/path/myimg}}

\end{document}

Now, run this, you'll see this output:

text width in cm: 13.70499cm
text height in cm: 19.27483cm
line width in cm: 13.70499cm
column width in cm: 13.70499cm
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut…

Go to your favorite image program, and make a colored rectangular image corresponding to what this output says the text size is, that is 13.7cm x 19.2cm.

Uncomment the insert image above,

\makebox[\textwidth][c]{\includegraphics{/my/path/myimg}}

When you do you, and rerun it, you will see that the image extends well into the footer area. The output of \textwidth and and \textheight just isn't corresponding to the text box—these commands don't seem to account for margins, headers, footers—but I was under the impression this is exactly what the text box ought to correspond to—the printable part of the page, after you deduct all the rest.

Best Answer

Create a complete example which shows that it doesn't work. Here is an example which shows that it is possible:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
foo

\includegraphics[width=\textwidth,height=\textheight]{tiger}

\rule{1pt}{\textheight}bar

baz
\end{document}

The second page of my test document:

enter image description here

Related Question