2

I want to add logo in the header of a book. The logo should be either at the left or at the right corner w.r.t odd/even page. Please help me to correct my code:

\documentclass[
  paper=a4, % it's the default anyway
  fontsize=12pt,
  twoside
  ]{book}
\usepackage[paperwidth=7.25in, paperheight=9.5in,bindingoffset=.75in]{geometry}
\usepackage{fancyhdr}
\usepackage{makeidx}         % allows index generation
\usepackage[demo]{graphicx} 
\pagestyle{fancy}
    {%
 \fancyhead[L]{\includegraphics[width=1.5cm,height=1.5cm,keepaspectratio]{logo.eps}}
\fancyhead[R]{\includegraphics[width=1.5cm,height=1.5cm,keepaspectratio]{logo.eps}}}
\setlength{\headheight}{47.0pt}
\addtolength{\topmargin}{-4\baselineskip}
\usepackage{lipsum}
\begin{document}
\lipsum 
\newpage
\lipsum
\end{document}
  • Have you considered reading the fancyhdr documentation for starters? Your use of \chead with a nested \fancyhead is wrong. – Werner Dec 23 '14 at 15:13
  • Use `LO´ for left on odd page and ´RE´ for right on even pages, see the fancy hdr doc on page 6f. – MaxNoe Dec 23 '14 at 15:17
  • @ Werner Yes, Its an error, I have modified it. Please help me next. – user1942348 Dec 23 '14 at 15:19
2

Package fancyhdr uses some deprecated commands in its defaults. But that doesn't matter anymore, after using \fancyhf and clearing the defaults (thanks egreg).

I recommend using package scrlayer-scrpage from the KOMA-bundlea. The syntax is pretty similar. \lehead stands for the left-even head, \rohead for the right-odd head. The naming convention is similar for footers (\lofoot, \cefoot etc).

\documentclass{book}
\usepackage[paperwidth=7.25in,
paperheight=9.5in,bindingoffset=.75in]{geometry}
\usepackage[headsepline]{scrlayer-scrpage}
\usepackage{mwe}
\lehead{\includegraphics[height=1.5cm,keepaspectratio]{example-image-a}}
\rohead{\includegraphics[height=1.5cm,keepaspectratio]{example-image-b}}
\setlength{\headheight}{47.0pt}
\begin{document}
\lipsum[1-20]
\end{document}

Note: book sets the pagenumber in the outer head. Package scrlayer-scrpage will just overwrite that if requested by the user. Package fancyhdr just overwrites the settings of book without user interaction.

  • It's true that fancyhdr uses the deprecated \rm and \sl commands. However, when one does \fancyhf{}, that should always be done when using the package, those commands will have no effect. To the contrary, see tex.stackexchange.com/questions/219225/… for an amusing bug of scrlayer-scrpage. – egreg Dec 23 '14 at 18:12
4

fancyhdr provides Odd and Even-page placement as well as choosing between the Left or Right side of the page. So, for Left-side on Odd pages, use LO, and Right-side on Even pages, use RE:

enter image description here

\documentclass[twoside]{book}
\usepackage[paperwidth=7.25in, paperheight=9.5in,bindingoffset=.75in]{geometry}
\usepackage{fancyhdr,graphicx,lipsum}
\pagestyle{fancy}
\fancyhead[LO]{\includegraphics[width=1.5cm,height=1.5cm,keepaspectratio]{example-image-a}}
\fancyhead[RE]{\includegraphics[width=1.5cm,height=1.5cm,keepaspectratio]{example-image-b}}
\setlength{\headheight}{47.0pt}
\begin{document}
\lipsum[1-20]
\end{document}

Note that the book document class issues \thispagestyle{plain} on the first page of every \chapter. In those instances you'll lose your fancy page style, unless you re-issue \pagestyle{fancy} or redefined plain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.