Page LayoutCustom Header for ToC

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
bondmatt
Posts: 2
Joined: Sun Jun 09, 2013 2:05 am

Custom Header for ToC

Post by bondmatt »

New LaTeX user here.

I am writing a LaTeX file to produce a report. Every page must have the company logo, etc. in the header. The header looks good on the title page but the next page, the ToC, has no header. I have been unable to figure out why.

I have reviewed a few topics on these forums for similar issues but I was not able to get the solution to work for me. I have tried this.

Code: Select all

\nopagebreak[4]
\addtocontents{toc}{\protect\thispagestyle{fancy}}
Any assistance would be greatly appreciated!

My code stripped of irrelevant content:

Code: Select all

\documentclass{report}

\usepackage[letterpaper,top=0.25in,bottom=0.5in,hmargin=0.3in,headheight=0.5in]{geometry}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{fancyhdr}
\usepackage{lastpage}

\pagestyle{fancy}

\usepackage[dvips]{graphicx}

\begin{document}

%\renewcommand{\headrulewidth}{0.5pt}

\lhead \noindent \includegraphics*[width=7.6in, keepaspectratio=true]{header_Schukra_LP}
\\[0.8in]

\noindent \includegraphics*[width=7.6in, keepaspectratio=true]{Test_report_op_sound_test} 
\\[0.6in]

\normalsize

\renewcommand{\footrulewidth}{0.4pt}

\cfoot{\thepage\ of \pageref{LastPage}}

\pagebreak

\lhead \noindent \includegraphics*[width=7.6in, keepaspectratio=true]{header_Schukra_LP}
\tableofcontents

\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Custom Header for ToC

Post by localghost »

The first page of the ToC (as well as of LoF and LoT) is a chapter page which uses the plain page style. Section 7 of the fancyhdr manual exactly describes how to redefine it. Furthermore you are using the \lhead command from the package completely wrong. Please refer to the package manual which describes in detail and with many examples how to declare a fancy page style. A Forum Search should also yield ready-to-use solutions in this regard. Without seeing an example of the desired result it is difficult to give specific help here. For that you should attach the company logo to your next post by upload to the forum server.


Remarks:
  • The dvips option to graphicx is superfluous.
  • Weird page geometry. Think about choosing a more suitable type area.

Best regards and welcome to the board
Thorsten
bondmatt
Posts: 2
Joined: Sun Jun 09, 2013 2:05 am

Custom Header for ToC

Post by bondmatt »

Edit: I was able to solve my issue by changing the document class from report to article.
localghost wrote:The dvips option to graphicx is superfluous.
If I remove this my graphics do not appear.
localghost wrote:Furthermore you are using the \lhead command from the package completely wrong.
If you could explain this I would appreciate it. What I have works for some reason. I don't find the fancy header manual very useful for what I am doing (just putting a graphic in the header).

Thank you for the suggestions. I figured there is likely a simple solution out there but I am in over my head with LaTeX at the moment. I am just trying to make my way through the not so short guide to LaTeX right now.

I would not be surprised if what I have is somewhat odd. I used the GrindEQ Word add-on to output my document as LaTeX code. The result is terrible. However, what I have posted here (and what I am currently working with) is significantly modified from what was output by the add-on.

I think I should also have mentioned that I am using MiKTeX with the XeLaTeX typesetter.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Custom Header for ToC

Post by localghost »

bondmatt wrote:[…] I was able to solve my issue by changing the document class from report to article.[…]
That's not a real solution but an evasion of the problem
bondmatt wrote:[…] If I remove this my graphics do not appear. […]
I doubt that. Packages like graphicx do best in choosing the correct driver on their own. Furthermore XeLaTeX accepts EPS, JPG, PNG and PDF as format for external graphics files. But unfortunately you neither didn't tell us what the format of your company logo is nor did you attach it to one of your posts to make your example compilable for others.
bondmatt wrote:[…] If you could explain this I would appreciate it. What I have works for some reason. I don't find the fancy header manual very useful for what I am doing (just putting a graphic in the header). […]
Then you have to learn how to extract relevant information from a manual and apply this to your problem. Compared with others, the fancyhdr manual is one of the simplest manuals around. Such a package is very useful here because without it you wouldn't manage at all to get a kind of logo into the document header.

What you are trying to achieve is usually done as shown in the below code. Note that this example is for pdfTeX because the demo option for graphicx does not work with XeTeX for some reason. But you can click on "Open in writeLaTeX" to see the output instantly.

Code: Select all

% !TeX program = pdflatex
\documentclass[11pt]{report}
\usepackage[T1]{fontenc}  % <<< drop this when compiling with XeLaTeX
\usepackage[
  letterpaper,
  includeheadfoot,
  margin=0.8in,
  headheight=105pt
]{geometry}
\usepackage[demo]{graphicx}  % <<< drop `demo` option in actual document
\usepackage{lastpage}

\usepackage{fancyhdr}
\fancyhf{}
\chead{\includegraphics*[width=\headwidth,keepaspectratio=true]{header_Schukra_LP}}
\cfoot{\thepage\ of \pageref{LastPage}}
\renewcommand{\footrulewidth}{0.4pt}
\fancypagestyle{plain}{%
  \chead{\includegraphics*[width=\headwidth,keepaspectratio=true]{header_Schukra_LP}}
  \cfoot{\thepage\ of \pageref{LastPage}}
}
\pagestyle{fancy}

\usepackage[toc]{blindtext}

\begin{document}
  \blinddocument
\end{document}
bondmatt wrote:[…]I would not be surprised if what I have is somewhat odd. I used the GrindEQ Word add-on to output my document as LaTeX code. The result is terrible. However, what I have posted here (and what I am currently working with) is significantly modified from what was output by the add-on. […]
I completely consent to that. This code is rubbish. And you should think about writing the code on your own instead of relying on bad export results which cause more problems than they solve.
bondmatt wrote:[…]I think I should also have mentioned that I am using MiKTeX with the XeLaTeX typesetter.
As already mentioned, the above example should also work with XeLaTeX after dropping the fontenc package and using fontspec to specify fonts and their attributes.


Remarks:
  • Special characters (blank spaces, underscores, accented characters, …) should be avoided in the path and the name of external files. They can cause problems.
Post Reply