[Tex/LaTex] Insert graphic and stretch to textwidth, textheight

graphics

I'm trying to insert a graphic and stretch it to textwidth and textheight. I get a overfull box and an empty page befor the graphic. But it works when I only strech in horizontal reps vertical direction. Why I can't stretch in both directions?

This works as I want

\documentclass[]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage{mwe}
\setlength{\parindent}{0pt}
\pagestyle{empty}

\begin{document}
    \includegraphics[height=\textheight]{example-image-a}
\end{document}

But this yields an overfull vbox and an empty page

\documentclass[]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage{mwe}
\setlength{\parindent}{0pt}
\pagestyle{empty}

\begin{document}
    \includegraphics[height=\textheight, width=\textwidth]{example-image-a}
\end{document}

The only difference is the width=\textwidth.

Best Answer

The issue appears to be one of roundoff. Changing

\includegraphics[height=\textheight, width=\textwidth]{example-image-a}

to

\includegraphics[height=.9999\textheight, width=\textwidth]{example-image-a}

fixes the problem, whereas an extra 9,

\includegraphics[height=.99999\textheight, width=\textwidth]{example-image-a}

breaks it again. Such roundoff issues should not be too surprising, if one considers that constraining both the height and width is not a pure scale, but will require several constrained length multiplications in order to determine the final aspect and dimensional scale.

This MWE demonstrates the issue:

\documentclass[]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage{mwe}
\setlength{\parindent}{0pt}
\pagestyle{empty}
\newsavebox\tmpbox

\begin{document}
\the\textheight{} actual textheight

\savebox\tmpbox{\includegraphics[height=.9999\textheight,width=\textwidth]{example-image-a}}
\the\ht\tmpbox{} .9999 is below

\savebox\tmpbox{\includegraphics[height=.99999\textheight,width=\textwidth]{example-image-a}}
\the\ht\tmpbox{} .99999 is above

\savebox\tmpbox{\includegraphics[height=\textheight,width=\textwidth]{example-image-a}}
\the\ht\tmpbox{} scaled to textheight is above
\end{document}

enter image description here