0

I'm trying to load a graphic to fit the \textwidthand \textheight, i.e., the whole page except the top, bottom, left and right margins. However, when I include the graphic with the \textwidth and \textheight parameters, it doesn't fit and it is pushed to the next page.

Why is this happening? Can the geometry of the page be changed so the command

\inlcudegraphics[width=\linewidth, height=\textheight]{filename}

works?

PS. I'm not looking for a workaround of the type

\inlcudegraphics[width=.9\linewidth, height=.9\textheight]{filename}

I want to choose the margins and the picture to use exactly that space.

Current MWE

\documentclass[10pt,a4paper]{article}
\usepackage[left=1.00cm, right=1.00cm, top=1.00cm, bottom=1.00cm,marginparsep=0cm, showframe]{geometry}
\usepackage{graphicx}
\pagestyle{empty}
\setlength{\parindent}{0pt}
\begin{document}
\includegraphics[width=\linewidth, height=\textheight, trim={0 0 0 0}]{filename}
\end{document}
  • This explains the "why" part. Useful! – mendus Jun 7 '18 at 9:16
  • 1
    It also shows solutions. Both adjustbox and the max totalsize and Josephs code should work. But I would avoid such exact sizes and always allow for a rounding error. – Ulrike Fischer Jun 7 '18 at 9:23
  • Can the rounding error somehow be forced downwards? So that the picture always fits in the margins, even if there's a small white space? – mendus Jun 7 '18 at 9:29
1

There has always been a problem putting a full page image on the first page. Every other page is fine.

\documentclass[10pt,a4paper]{article}
\usepackage[left=1.00cm, right=1.00cm, top=1.00cm, bottom=1.00cm,marginparsep=0cm, showframe]{geometry}
\usepackage{graphicx}
\pagestyle{empty}
\setlength{\parindent}{0pt}
\begin{document}
\vspace*{\fill}\smash{%
\includegraphics[width=\linewidth, height=\textheight, trim={0 0 0 0}]{example-image}}
\end{document}
1

Like this

\documentclass[10pt,a4paper]{article}
\usepackage[left=1cm,
            right=1cm,
            top=1cm,
            bottom=1cm,
            marginparsep=0cm,
            showframe
            ]{geometry}
\usepackage{graphicx}
\pagestyle{empty}
%\setlength{\parindent}{0pt}

\makeatother
\begin{document}
% this only to gather some info, not needed for graphics inclusion
\setbox0\hbox{\includegraphics[width=\linewidth,
                               height=\textheight]{example-image-a}}%
\typeout{\number\wd0, \number\ht0 \space(box)}
\typeout{\number\linewidth, \number\textheight\space(actual text area dimensions)}
% actual graphics inclusion
\vbox to \textheight{\hsize\linewidth
                     \vss
                     \noindent
                     \makebox[\linewidth]{%
                     \includegraphics[width=\linewidth,
                                      height=\textheight]{example-image-a}%
                     }%
                     \vss}


\end{document}

And the log contains

35430201, 51656780 (box)
35428918, 51651632 (actual text area dimensions)

enter image description here

Note: I also tried replacing \Gscale@div with a more precise one:

\documentclass[10pt,a4paper]{article}
\usepackage[left=1cm,
            right=1cm,
            top=1cm,
            bottom=1cm,
            marginparsep=0cm,
            showframe
            ]{geometry}
\usepackage{graphicx}
\pagestyle{empty}
%\setlength{\parindent}{0pt}

\makeatletter
% https://tex.stackexchange.com/a/383700/4686
\newcommand\SetToRatio[3]{% sets #1 to be the ratio #2/#3, where #2 and #3 
    % are lengths (registers or expressions).
    % The ratio #2/#3 should evaluate to less than 16384 in absolute value to 
    % avoid arithmetic overflow. It will be computed as fixed point
    % number with about 4 or 5 digits after decimal mark.
    \edef #1%
        {\strip@pt\dimexpr
         \numexpr\dimexpr#2\relax*65536/\dimexpr#3\relax\relax sp\relax}%
}

\let\Gscale@div\SetToRatio
\makeatother
\begin{document}

\setbox0\hbox{\includegraphics[width=\linewidth,
                               height=\textheight]{example-image-a}}%
\typeout{\number\wd0, \number\ht0 \space(box)}
\typeout{\number\linewidth, \number\textheight\space(actual text area dimensions)}

\vbox to \textheight{\hsize\linewidth
                     \vss
                     \noindent
                     \makebox[\linewidth]{%
                     \includegraphics[width=\linewidth,
                                      height=\textheight]{example-image-a}%
                     }%
                     \vss}


\end{document}

but the log file then contains

35428916, 51651721 (box)
35428918, 51651632 (actual text area dimensions)

so the height is still bigger than \textheight although the width is much more precise. And the image without wrapping is still pushed to next page.

I also tried the \divdef at https://tex.stackexchange.com/a/383700/4686 and it gives exact same result as using the above e-TeX dependent approach.

Notice that then you can use

\noindent\includegraphics[width=\linewidth,
                          height=\dimexpr\textheight-50sp\relax]{example-image-a}

With the non-patched graphicx, this works: (65536sp = 1pt)

\noindent\includegraphics[width=\linewidth,
                          height=\dimexpr\textheight-5150sp\relax]{example-image-a}
0

Would this work?

\documentclass[10pt,a4paper]{article}
\usepackage[left=1.00cm, right=1.00cm, top=1.00cm, bottom=1.00cm,marginparsep=0cm, showframe]{geometry}
\usepackage{graphicx}
\usepackage{mwe}
\pagestyle{empty}
\setlength{\parindent}{0pt}
\begin{document}
\begin{figure}
 \includegraphics[width=\linewidth, height=\textheight, trim={0 0 0 0}]{example-image-a}
\end{figure}
\end{document}

enter image description here

  • It shows in the right place, but the figure is bigger than the textwidth, I believe. Plus, it doesn't make sense using a floating element when I want a fixed position. – mendus Jun 7 '18 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.