# How to have a figure touch the top edge of the page?

I want to have a letterhead format with the corporate logo at the very top of the paper. I have figured out how the fill the graphics with the full breadth of the page with the information on this webpage- How to have a figure touch the edge of the page?.

\documentclass{article}
\usepackage{lipsum}
\usepackage{graphicx}

\begin{document}

%
\newcommand{\dimtorightedge}{%
\dimexpr\paperwidth-1in-\hoffset-\oddsidemargin\relax}
%

\begin{flushleft}
\mbox
{%
\makebox[\dimtorightedge]{}%
\makebox[0pt][r]
{\includegraphics[width=\paperwidth]{logo}}%
}
\end{flushleft}

\section{A test section}
\lipsum[4]

\end{document}


I got the result like this -

However I'm still struggling to align the top side of the graphics (logo) with the top edge of the paper.

Appreciate any help!

• I have not found anything anywhere putting the graphics right to the very top of the page. I want this for the first page for now. But might also want every page afterwards. It does not matter whether it's implemented with the header or in the 'body' of the article. (Of course it's more elegant with header if it's a letter header). Thanks. I can think of an ugly workaround by making a blank pdg page with header with word and then include in TeX. But that's really ugly workaround and hope to see more elegant ways. – Max Jan 9 at 7:36

## 1 Answer

You need to raise the image into the upper margin. This can be done using \raisebox. I used the layout package with the \layout macro to display all length used by LaTeX to create the top of the page. The distance is 1in+\voffset+\topmargin+\headheight+\headsep. You need to use the optional argument to set the new height by subtracting that value from the original height, which is defined as \height here. This also works if put into a header by simply removing \headheight and \headsep from the equation.

Of course you can also my adjustbox package to do all this with less code.

\documentclass{article}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{adjustbox}

\newcommand{\dimtorightedge}{%
\dimexpr\paperwidth-1in-\hoffset-\oddsidemargin\relax}

\newcommand{\dimtotop}{%
\dimexpr\height-1in-\voffset-\topmargin-\headheight-\headsep\relax}

\begin{document}

\clearpage
\begin{flushleft}
\hbox
{%
\makebox[\dimtorightedge]{}%
\makebox[0pt][r]
{\raisebox{0pt}[\dimtotop]{\includegraphics[width=\paperwidth]{example-image}}}%
}
\end{flushleft}

\section{A test section}
\lipsum[4]

\clearpage
\noindent\adjustimage{width=\paperwidth,
lap={\textwidth}{-1in-\hoffset-\ifoddpage\oddsidemargin\else\evensidemargin\fi+.5\paperwidth-.5\width-\csname @totalleftmargin\endcsname}, % adjustbox version v1.2 2019/01/04 provides this as 'pagecenter' key
set height=\height-1in-\voffset-\topmargin-\headheight-\headsep}{example-image}

\section{A test section}
\lipsum[4]

\end{document}


• Thanks Martin. That's exactly what I wanted. Seems like I had not fully understood the command \raisebox. I was also not aware of the \height command - I had overlooked the \height command (and \width, \depth, as well) in the book 'The not so short introduction to LaTeX2e'. – Max Jan 9 at 8:15
• @Max: \height, \width and \depth are defined internally by \raisebox when processing the length values. Also the adjustbox package does the same. – Martin Scharrer Jan 9 at 8:17
• Oh you showed 2 ways of doing it. That's awesome. Thanks! – Max Jan 9 at 8:23
• @Max: The adjustbox update from last week makes the horizontal adjustment easier, just replace the lap=... stuff with a simple pagecenter. I didn't used it yet, as not everyone might have the update yet. – Martin Scharrer Jan 9 at 8:27
• Having learned from Martin's code, I also changed the \dimtorightedge definition by replacing oddsidemargin with\ifoddpage\oddsidemargin\else\evensidemargin\fi to add more flexibility. But I don't see any problem with the simpler definition without changing the default page layout. – Max Jan 9 at 8:39