3

How can I get one image as a header that is not just the header but extends to the top of the page limits and also left and right? I have see this Minipage in Header? but is not to have the image to the top of the page limits, and this How do I put the top of an image at the top of a page but I do not understand what to do

I have tried this but the result is not the expected. When Ι replace width=\textwidth with width=\pagewidth does not work.

\documentclass{article}

\usepackage{kantlipsum}
\usepackage{fancyhdr}
\usepackage[demo]{graphicx}

\usepackage[right=2.5cm,left=2.5cm,top=2.5cm,bottom=2.0cm,total={165mm,243mm},showframe,includeheadfoot]{geometry}

\pagestyle{fancy}

\fancyhead[L]{%
% \centering
% \vspace{-7cm}
  \includegraphics[width=\textwidth,height=2.5cm]{logo.png}
}

% \fancyfoot[L]{\thepage}


\begin{document}
\kant
\end{document}

enter image description here

Update-1 What I want is probably very close to this approach http://www.texample.net/tikz/examples/fancy-chapter-headings/ but not be connected to the chapter but with one image

karathan
  • 2,138
  • 2
  • 17
  • 32

1 Answers1

6

Well the main points to solve things like this are

  1. hide the actually extend of the graphic so that LaTeX thinks it has neither width nor height.
  2. Move it around e.g. with \hspace and \raisebox. Picture environments can be use too.

    \documentclass{article}
    \usepackage{kantlipsum}
    \usepackage{fancyhdr}
    \usepackage[demo]{graphicx}
    
    \usepackage[right=2.5cm,left=2.5cm,top=2.5cm,
              bottom=2.0cm,total={165mm,243mm},showframe,includeheadfoot]{geometry}
    
    \pagestyle{fancy}
    
    \fancyhead[L]{%
      \hspace*{\dimexpr -1in-\oddsidemargin}%
      \makebox[0pt][l]{\normalsize %the [0pt] hides the width
          \raisebox{\dimexpr\headheight-\dp\strutbox
              +1in+\topmargin-\height}[0pt][0pt]{% the [0pt][0pt] hides height and depth
         \includegraphics[width=\paperwidth,height=2.5cm]{logo.png}}}%
    }
    
    
    
    \begin{document}
    \kant
    \end{document}
    
Ulrike Fischer
  • 327,261
  • Great answer. Just for reference here how to do the same using adjustbox: \usepackage[export]{adjustbox} \fancyhead[L]{% {\normalsize \includegraphics[width=\paperwidth,height=2.5cm,lap={0pt}{-1in-\oddsidemargin}, raise={\headheight-\dp\strutbox+1in+\topmargin-\height}{0pt}{0pt}]{example-image}}% } – Martin Scharrer Feb 06 '13 at 17:34
  • I delayed because I did my tests and works extremely! :) – karathan Feb 06 '13 at 17:49
  • Could you give a clarification on "hide the actually extend of the graphic..." . Where exactly happens this inside the code? As you understand I'm not an expert I have lot of work ahead :) – karathan Feb 06 '13 at 18:01
  • @karathan: I added two comments. – Ulrike Fischer Feb 06 '13 at 18:02
  • @UlrikeFischer after addition of your comments I think I get it, definitely an excellent approach – karathan Feb 06 '13 at 18:17