It is possible to position the image without redefining the page geometry. Redefining the page geometry in general can give you problems.
First let us use some TikZ code to position a block at the top of the page. the block will be half an A4 size i.e., an A5 paper size. When we use an overlay as you see from the image below:
The MWE is shown below:
\documentclass[a4paper]{article}
\usepackage{tikz,lipsum}
\usepackage{hyperref}
\begin{document}
\thispagestyle{empty}
\begin{tikzpicture}[overlay,remember picture,anchor=north west,inner sep=0pt, outer sep=0pt]
\node at (current page.north west) {%
\begin{tikzpicture}[overlay,remember picture, inner sep=0pt, outer sep=0pt,anchor=north west]
\path[color=black,fill=purple]
(0,0) rectangle ++(\the\paperwidth,-0.5\paperheight);
\end{tikzpicture}
};
\end{tikzpicture}
\lipsum
\end{document}
Now of course this is not satisfactory as you want to position the text after the image or the TikZ picture. In order to achieve this you enclose the tikz picture in a \vbox
set at half-page height.
\documentclass[a4paper]{article}
\usepackage{tikz,lipsum}
\usepackage{hyperref}
\begin{document}
\vbox to 0.5\paperheight{\begin{tikzpicture}[overlay,remember picture,anchor=north west,inner sep=0pt, outer sep=0pt]
\node at (current page.north west) {%
\begin{tikzpicture}[overlay,remember picture, inner sep=0pt, outer sep=0pt,anchor=north west]
\path[color=black,fill=purple]
(0,0) rectangle ++(\the\paperwidth,-0.5\paperheight);
\end{tikzpicture}%
};%
\end{tikzpicture}}
\section{Test}
\lipsum
\end{document}
If you replace the code in the node with an includegraphics
command, your image should be imported at the top of the page with no problems.
It is also possible to do the same without any tikZ code. I will post this a bit later if this is what you are after.
As pdf uses different parameters for paperheight
and paperwidth
, I normally use the package hyperref
to ensure they are corrected. If you do not want to load it you can use:
\newcommand*{\fixpdflayout}{%
\pdfpageheight=\the\paperheight
\pdfpagewidth=\the\paperwidth
\ifxetex\else
\ifdim\pdfvorigin=0pt\pdfvorigin=1in\fi
\ifdim\pdfhorigin=0pt\pdfhorigin=1in\fi
\fi}
\headheight
/package fancyhdr
\headheight
is set to 0.46cm
= 13.08846pt
. But the header set in page style fancy needs 14.96666pt
. See the warning of package fancyhdr
:
Package Fancyhdr Warning: \headheight is too small (13.08846pt):
Make it at least 14.96666pt.
We now make it that large for the rest of the document.
This may cause the page layout to be inconsistent, however.
As an emergency measure, package fancyhdr
changes \headheight
and "distroys" your page layout in the process. Therefore increase the \headheight
to 15pt
(or 14.96666pt
) and correct the layout (smaller height of the text body to get room for the header, ...), e.g.:
\setlength{\headheight}{15pt}
\addtolength{\textheight}{0.46cm}% old \headheight
\addtolength{\textheight}{-15pt}% new \headheight
Paper size for the output driver
LaTeX holds the paper size in the dimen registers \paperwidth
and \paperheight
. It can be set by a document class option or packages like geometry
. Since the default for the standard classes (article
, report
, book
) is letterpaper
, specifying a4paper
is correct.
However, the LaTeX kernel does not tell the paper size to the output driver, it does not deal with output drivers at all. :-(
Then it depends on the default of the output driver (pdfTeX, XeTeX, ...), which paper size is choosen.
Some packages like geometry
, typearea
, hyperref
, pdftex.def
fill the gap that the LaTeX kernel leaves and tell the paper size to the output driver.
The minimal example sets the layout manually without any of the packages above.
For example package geometry
, which can also be used for the page layout,
can be used after the layout assignments at the end of the preamble:
\usepackage[pass]{geometry}
Option pass
prevents that package geometry
does change the page layout.
But it tells the output driver the paper size. Thus you should also get A4 with XeTeX.
Best Answer
To set the paper with for LaTeX use the option "a4paper" or "a5paper". But this option only set an internal LaTeX length. To change also the size of "pdf background" you must issue some special commands. Which ones depends on the engine. If you load a package like
hyperref
,geometry
,graphics
they will do the work for you. Without such a package you can use withxelatex
this:(I'm using a5 paper to avoid that some default paper settings hide the effect.)