2

I want to include a picture with width=\textwidth and height=\textheight. In the following MWE, the picture is not placed in the desired page. It produce one blank page first and then the picture. If I do not want the blank page what should I do?

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics[width=\textwidth,height=\textheight]{picture.jpg}
\end{document}
10
  • 1
    you might try "reducing" the height of the graphic by preceding it (after a page break) by some negative \vspace. start with \vspace*{-1\baselineskip) and increase the value gradually until the graphic stays on that page. then you could "compensate" by splitting the negative space between the top and bottom of the page. Commented Aug 17, 2015 at 16:31
  • Just do \includegraphics[height=\textheight]{picture.jpg} as you can not set both sizes. If the aspect ratio is different to \textwidth/\textheight, your image will become too big for the page.
    – LaRiFaRi
    Commented Aug 17, 2015 at 16:32
  • 1
    you need \noindent as currently you are starting a paragraph with the image so it is indented by \parindent so you do not have \textwidth space Commented Aug 17, 2015 at 17:00
  • 4
    @SayOL you need noindent for horizontal, then for vertical you need as barbara said in initial comment \vspace*{-something} tex is trying to put the baseline of the image \topskip below the top of the page Commented Aug 17, 2015 at 17:10
  • 1
    as posted above both width and height of the text area are exceeded. Commented Aug 17, 2015 at 17:29

1 Answer 1

4

Here is an example which creates a 1 page document in which the text area is filled by a suitably scaled A4 image.

I use width=\textwidth, height=\textheight, keepaspectratio. This means that the image will be as large as it can be subject to three constraints:

  1. width not to exceed \textwidth,
  2. height not to exceed \textheight
  3. image not be be distorted i.e. the width and height will be scaled by the same factor if they require scaling.

scaled image

\documentclass[a4paper]{article}
\usepackage{graphicx,geometry}
\begin{document}
\noindent\includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{example-image-a4}
\end{document}

If you really want to use the entire page, rather than just the area reserved for the text block, you need a different approach:

\documentclass[a4paper]{article}
\usepackage{graphicx,geometry,kantlipsum}
\begin{document}
\newgeometry{scale=1}%
\noindent\includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{enfys}\thispagestyle{empty}
\restoregeometry
\kant[1-3]
\end{document}

This produces the following two pages of output shown as a double-page spread (but with the odd page on the left):

full page image reverting to regular layout for Kant

3
  • My picture dimensions is not proportional to the dimensions of the paper. So when I add option keepaspectratio it is not stretched to fit the whole text area.
    – Say OL
    Commented Aug 18, 2015 at 2:44
  • @SayOL OK. Sorry... I don't see the problem. Either use keepaspectratio to prevent distortion or don't use it and the area will be filled but, of course, the disproportionate scaling will distort the image somewhat. I mean, there's no rule that you can't distort it. Just people don't usually want the distortion. If you don't mind, just omit the option. (I doubt it would matter with my rainbow, for example. If I were using that, distortion wouldn't really be an issue.)
    – cfr
    Commented Aug 18, 2015 at 2:48
  • for future users) Depends on what you want exactly, but if you want the image to silently overflow then \vbox to \textheight{...} the image instead. It makes sense if the image jumps to the next page if there's already something on the page, but when the page is blank it isn't clear why the behavior isn't the default.
    – user202729
    Commented Nov 16, 2021 at 14:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .