# Problem with lengths and images

I'm trying a simple page with an image in the top of it as a header and an square image centered in the rest of the page.

I would like the images to fill the full page width. After trying some aproaches, I have decided to use subfigures (from subcaption package) because although I'm talking about a single square image centered in the page, in the future i will need to create some image matrices, something like that:

Coming back to my single square image centered in page template, I have set some latex lengths to 0 cm:

\setlength{\parindent}{0cm}
\setlength{\parskip}{0cm}
\setlength{\skip\footins}{0pt}
\setlength{\topskip}{0.0pt}
\setlength{\footskip}{0.0pt}


And using geometry package, I have defined the page as follows:

\geometry{
layoutheight = 21 cm,
layoutwidth  = 29.7 cm,
layouthoffset = 0cm,
layoutvoffset = 0cm,
left=0cm,
right=0cm,
top=0cm,
bottom=0cm
}


then, my code:

\begin{document}
\begin{figure}[H]

\begin{subfigure}{21cm}
\vspace*{3.3cm}\hspace*{0.0cm}\includegraphics[width=21cm,keepaspectratio]{0}
\end{subfigure}
\end{figure}
\end{document}



Of course, I've defined \headerImage and \graphicspath correctly.

When render, I can read the next message:  Overfull \vbox (154.68237pt too high) has occurred while \output is active  And the result is a pdf file with two pages, first of them completly white, and the next one with my header and my image perfectly centered, and both images fill the complete page width. The second page is perfect.

Doing some calculations, 21cm (square image) + 2.1cm (header image) + 3.3cm (vspace) = 26,4 cm

Why is the first empty page added to the document?, How can I avoid the Overfull \vbox eror?

I'm not sure, but perhaps there is some other latex length that i don't know that should be set to 0??

Thank you very much in advance.

Edited:

Here is my code:

\documentclass{article}

\newcommand{\imagesPath}{/home/projects/latex-templates/images/}

%%% REQUIRED PACKAGES %%%
\usepackage{graphicx}
\usepackage[paperwidth=21 cm,paperheight=29.7 cm]{geometry}
\usepackage{color}
\usepackage{xcolor}
\usepackage{xstring}
\usepackage{calc}
\usepackage{fp}
\usepackage{float}
\usepackage{subcaption}
\usepackage{printlen}
\usepackage{import}

\graphicspath{{\imagesPath}}

%%% REDEFINED LATEX LENGTHS %%%
\setlength{\parindent}{0cm}
\setlength{\parskip}{0cm}
\setlength{\skip\footins}{0pt}
\setlength{\topskip}{0.0pt}
\setlength{\footskip}{0.0pt}
\setlength{\baselineskip}{0.0pt}
\setlength{\abovecaptionskip}{0.0pt}
\setlength{\belowcaptionskip}{0.0pt}

\geometry{
layoutheight = 21 cm,
layoutwidth  = 29.7 cm,
layouthoffset = 0cm,
layoutvoffset = 0cm,
left=0cm,
right=0cm,
top=0cm,
bottom=0cm,
showcrop=false,
showframe=false,
}

\graphicspath{{\imagesPath}}

%%% BACKGROUND COLOR %%%
\definecolor{backgroundcolor}{HTML}{FFFFFF}
%%% DOCUMENT DEFINITION %%%
\pagenumbering{gobble}
\pagecolor{backgroundcolor}
\message{INIT DOCUMENT}
\begin{document}
\begin{figure}[H]
\begin{subfigure}{21cm}
\vspace{3.2675cm}\hspace*{0.0cm}\includegraphics[width=21cm,keepaspectratio]{0}
\end{subfigure}
\end{figure}
\end{document}


And here is the result:

As you can see, there are two pages in the result pdf file. The second one is perfect, but without the first one! I'm sure this first empty page appears due to the:  Overfull \vbox (154.68237pt too high) has occurred while \output is active

What can I do to avoid this first empty page appears

• Use width=\linewidth and remove the height options of the images. If you need some less that the text width, use fractions of this relative length as .45\linewidth, not absolute lengths as 12cm. This will work always, even if you change the margins. – Fran Sep 21 '19 at 10:28
• BTW, please post always a minimal working example (MWE) not code fragments. – Fran Sep 21 '19 at 10:30
• BTW, keepaspectratio have sense only when you set both width and height. When you fix only one, there are not enough information of how not keep the aspect/ratio. Right? – Fran Sep 21 '19 at 10:36
• you have no captions and do not want the figure to move so you should not be using figure or subfigure here it just complicates the markup for no gain. – David Carlisle Sep 21 '19 at 11:37
• Thank you for your responses. @Fran, I have edited my original post, adding the MWE. I can't use \linewidth, because I want to fill the complete page width, that is 21cm. David, I have obtained the same result, after removing figure and subfigure environments. – Pianjy Sep 21 '19 at 23:29

Is not still clear for me what you want exactly, if a matrix of images in landscape or portrait mode, or if this should be part of some text document or a single page. Anyway, this could be a start point for a landscape page:

\documentclass[a4paper,landscape]{article}
\usepackage{graphicx}
\usepackage[margin=0cm]{geometry}

\begin{document}
\centering
\makebox[0pt]{\includegraphics[width=\paperwidth,height=3cm]{example-image}}
\vfill\hfill
\includegraphics[width=.45\paperwidth,height=.4\paperheight,keepaspectratio]{example-image}\hfill
\includegraphics[width=.45\paperwidth,height=.4\paperheight,keepaspectratio]{example-image-a}\hfill{}
\vfill\hfill
\includegraphics[width=.45\paperwidth,height=.4\paperheight,keepaspectratio]{example-image-b}\hfill
\includegraphics[width=.45\paperwidth,height=.4\paperheight,keepaspectratio]{example-image-c}\hfill{}
\vfill
\end{document}


For a portrait page, simply remove landscape in the first line:

Of course, when you use your own original images, that of the header should have the right width/height ratio, and then use only the width option. For the others images, if they are not in a 4x3 format, maybe you must adjust a bit .45\paperwidth or 4\paperheightto obtain the desired spaces around the images.

• Thank you very much for your answers @Fran. Your document is perfect for a 2x2 image matrix. In my first mentioned case, the single square image centered in a portrait A4 page, finally I have solved it, changing \begin{figure}[H] by \begin{figure}[htbp] – Pianjy Sep 22 '19 at 21:42
• After doing this change, this annoying first empty page dissapear. Althought I'm still curious about why it appears when using \begin{figure}[H] instead of \begin{figure}[htbp] and about the Overfull \vbox (154.68237pt too high) has occurred while \output is active` that is shown when compiling – Pianjy Sep 22 '19 at 21:53