138 Comments

  1. ez

    Thanks, this was exactly what I was looking for. If you have time could you leave a comment explaining how to change the header font size and margins? I’d appreciate it.

    • Hi
      I need to add a foot text in each page of my paper.
      I have typed in the preamble:

      \usepackage{fancyhdr}
      \pagestyle{fancy}
      \fancyfoot{}
      \fancyfoot[LE,LO]{MY TEXT}
      \renewcommand{\footrulewidth}{0.4pt}

      But it doesn’t work. Can you give me a little help please?
      Thanks in advance.
      Cordially,
      D.K.

      • Dear D.K.,

        The sample you pasted works perfectly in my environment, so I think there’s nothing wrong with it. What you could try is if you are using different packages, change their order. Sometimes they need to be included in the correct order for them to work in combination with others.
        If you post the error you get and maybe some more of your preamble, I might be able to reproduce it and help you.

        Best regards,
        Tom

      • sarvesh

        Dear tom, i have a difficulty of showing the header and footer in latex environment with copyright information on first page as shown below; please help me to sort out this problem. I want to run my header and footer information for all pages and want to display the “@copyright IEEE” content below the footer on extreme leftside at first page only as depicted below:-
        ……………………………………………………………………………………
        2011 International Conference on ICIIP
        ….
        ….
        ….
        ….
        ….
        ….
        ….

        Proceedings of the 2011ICIIP 2011
        978-1-61284-860-0/11/$26.00 ©2011 IEEE
        ……………………………………………………………………………………

      • Hi Saravesh,

        Below is a minimal example. You should be able to customize it for your needs. Basically, I define a new page style (titlepage) for the title page and change it back to fancy for the following pages. Hope it helps. Cheers, Tom.

        \documentclass[11pt]{article}
        \usepackage[english]{babel}
        \usepackage{fancyhdr, blindtext}
        \fancypagestyle{titlepage}{
        \fancyhead[L]{2011 International Conference on ICIIP}
        \fancyfoot[L]{Proceedings of the 2011 ICIIP 2011\\
        978-1-61284-860-0/11/\$26.00 ©2011 IEEE}}
        \fancyhead{}
        \fancyfoot{}
        \fancyhead[L]{2011 International Conference on ICIIP}
        \renewcommand{\headrulewidth}{0pt}
        \renewcommand{\footrulewidth}{0pt}
        \begin{document}
        \begin{titlepage}
        \thispagestyle{titlepage}
        \blindtext
        \end{titlepage}
        \pagestyle{fancy}
        \blindtext
        \end{document}
      • Sarvesh

        Dear Tom, Thanks for the reply. I was trying my best to fix up the issue in my IEEE conf latex template But could not able to do it as you have suggested for article documents.
        I want to do the same excise (as in article documents) on this code..

        bare_conf.tex removed by Tom.

        What would be the latex command for the above code. Please help me out.

        Thanks & Regards
        Sarvesh

      • Hi Sarvesh,

        Please don’t copy-paste hundreds of lines of code into your comment. It would have been sufficient to provide a link to where you got the code from. Michael Shell, the author of the tex-file you use provides an FAQ on his website which has the perfect solution for your question (see “Q: I need to get rid of the page numbers. How do I disable or customize the headers and footers?”).

        Best,
        Tom.

      • Sarvesh

        Dear Tom,
        Thanks for your guidance and kind support to fix up the problem.
        Thanks & Regards
        Sarvesh

      • If you’re using the geometry package, I suggest (for testing purposes) increasing the top margin separately to a big measure (like 100pt, for instance). For me, it looked like fancyhdr wasn’t working, but actually the header was out of the page limits so I couldn’t see it. Setting a bigger top margin made the header appear and then I could adjust the said margin to a suitable measure (55pt, in my case).

  2. @ez

    To answer your question:
    First for the margins, you can access them through the following commands:

    \fancyheadoffset[]{} and \fancyfootoffset[]{}

    E.g. to change the width of a two-sided document’s header to the outer maximum (you need the calc-package for the addition):

    \fancyheadoffset[LE,RO]{\marginparsep+\marginparwidth}

    The font size can be changed directly where you define the header/footer.
    E.g. to decrease the font size of the page numbering you would use:

    \fancyfoot[RO, LE] {\footnotesize \thepage}

    Check the fancyhdr documentation for more details on that topic:
    http://www.ctan.org/tex-archive/macros/latex/contrib/fancyhdr/fancyhdr.pdf

    Cu,
    Tom.

  3. Bikash

    I am writing my thesis template and would like to include image(logo) in the header. I tried several options, but none of them worked. Could anybody suggest me the way to insert image in the header section? I would be very grateful.

    Another problem is the line spacing in the footer. I want to have different line spacing (less than the main text).

    Thanks

  4. Hi Bikash,

    Including an image in your header is possible using the fancyhdr package.
    E.g. if you’d like to have a logo in the top-right corner, you would use:

    \fancyhead[RO,RE]{\includegraphics[width=3cm]{picture.jpg}}

    Concerning the text spacing in the footer, the only solution I can propose, even though not very nice, is the following:

    \fancyfoot[LE,RO]{1st line\vspace{-2mm}\\ 2nd line}

    You can find a documentation of the fancyhdr package here.

    Cheers,
    Tom

  5. Kent

    I have been using fancyhdr package for a while but have knocked my head in to a problem which I can’t solve:
    In a large document, using “BOOK” style, no header/footer is displayed on the chapter page it self. I have tried to redefine the “Plain” setup (which is called when chapter is included):

    \fancypagestyle{plain}
      \fancyhead...
    
       BODY
      \fancfoot ...
    \pagestyle{plain}

    The problem is that I don’t know the “BODY” formatingen of a normal CHAPTER page. I simply want the CHapter to look as a chapter but adding a centered header and footer on these pages as well.

    Any simple solutions ? Have read the fancyhd doc and I have not figured out any thing yet. I find it unnecessary to add the KOMA script package simply for this. Any help would be appreciated.

    K

  6. Hi Kent,

    Actually, what you did is correct, using

    \fancypagestyle{plain}

    Now if you want to modify the forced fancy-plain-pagestyle, you can add your own definitions as follows:

    \fancypagestyle{plain}{%
    \fancyfoot[C]{\thepage}
    %etc.
    }

    Cheers,
    Tom

  7. Kent

    Tom,
    I do agree with you here but then I have to dig out the formating of the Chapter page, to make the correct heading sizes and make the page look like a Chapter start page.
    I did however fin something which might help others. It’s much easier, but not something I have found documenter.

    It goes like this :

    \usepackage{fancyhdr}
    \pagestyle{fancyplain}  %Note the \fancyplain command !!!
    \renewcommand{\chaptermark}[1]{\markboth{#1}{}}
    \renewcommand{\sectionmark}[1]{\markright{#1}{}}

    Then “normal formating of \lhead,\chead but with a twis:

    \lhead[\fancyplain{E}{EE}]  {\fancyplain{O}{OO}}

    E:”Text”-forced into “plain” pages aka first page of Chapter etc- Even pages
    EE: Text”-for all the other pages – Even pagenumber

    Note the \lhead[ ] { } combination of different brackets !

    O: Text”-pforced into “plain” pages aka first page of Chapter etc- Odd pages
    OO: ext”-for all the other pages – Even pagenumber

    \chead[\fancyhead{}{}]{\fancyplain{}{}}
    \cfoot [ ] { }
    .
    .
    \renewcommand{\headrulewidth}{0.4pt}
    \renewcommand{\footrulewidth}{0.4pt}

    If you read Piet van Oostrums document there is nothing mentioned about “\fancyplain”. Nor do you find it documented in The Latex Companinon where both refers to the re-definition of the “Plain” style.
    I’m not sure if this is something which is elementary obvious for either the Authors of the “Companion” book or Mr Oostrum, but I think it would be worth a sentence or two in both documents.

    Note that you need to document each of the \lhead, \chead....\rfoot to eventually “blank” each part of the header\footer positions. If not, LaTeX apply the normal fancy fields in each position, where for instance \rightmark would give you ONLY the text from the expected fields in the document (No Subsection number etc) but also all the others. So use \rfoot[\fancyplain{}{}]{\fancyplain{}{}} to blank for instance right corner.

    Hope it helps for those who would like to add “something” on the first page of each Chapter,Tableofcontents,Listoftables etc
    If it’s well known, OK, if not spread the word wherever you see people having these problems.

    I found this out by reading the old documentation of the now not supported \fancyheader documentation – the older version of \fancyhdr.

    Regards

    Kent

    • yusuf

      I tried a lot to impletement your code but failed. I want to skip header only on the starting page of chapter. on all other pages header should be displayed.
      i am using fancyhdr.
      I have wasted hours together on this but badly stuck on this.
      can you please help.

      • Hi Yusuf,

        I would expect this to be the normal behavior. You should not get any header on the first page of every chapter by default. Please send a minimal example so I can have a look at it.

        Thanks, Tom.

  8. Penguin Knight

    Thanks for this very helpful information. I still have one technical problem and hope to share with you all:

    I am trying to set up a page with left margin 1.5″, and all other margins 1.0″. I did this without problem using the geometry package like this:

    \usepackage{geometry}
      \geometry{hmargin={1.5in,1in},vmargin={1in,1in}}

    However, for the page number, the specification requires me to put it on top right of each page, 0.75″ from the top and right margin. Using fancyhdr, I did manage to move it horizontally with \fancyheadoffset[HR]{0.25in}. However, I cannot find a way to snug it down to 0.75″ from the top while still preserving the 1″ top margin for the text.

    Any insight would be appreciated.

    Here is the whole format codes I used:

    \usepackage{geometry}
      \geometry{hmargin={1.5in,1in},vmargin={1in,1in}}
    \usepackage{fancyhdr}
      \pagestyle{fancy}
      \renewcommand{\headrulewidth}{0pt}
      \fancyhead{}
      \fancyfoot{}
      \rhead{\thepage}
      \fancyheadoffset[HR]{0.25in}

    Thanks a lot.

    • Tessellation

      Dear Penguin and respondents,

      This was a very helpful question & set of answers.

      I had a problem where the header didn’t seem to be centered in line with the body text which had an extra large margin on the outer side (ie large on the right, for a right facing page, and vice versa for a left hand page.)

      I had tried using \fancyheadoffset with the R or L subcommand which didn’t seem to work.

      However \fancyheadoffset[HR]{0.0in} worked very well and must have reset the offset (caused indirectly by some other command?) that was causing the lack of centering…

      A bit clunky but important to get the exam paper submitted in time.
      Does anyone have any insight on how this margin had been set to a non-zero quantity? (ie what commands can do this?)

      Cheers,
      Tessellation

      • Hi there!

        Thanks for your comment. Please provide a minimal working example and I will be very happy to take a look at what you have described above.

        Best, Tom.

  9. Hi there,

    You can control the vertical space for the header using the commands below.

    Space between page border and header (1in + space). You can also use someting negative if you like the space to be below 1 inch.

    \setlength\voffset{-0.25in}

    Height of the actual header.

    \setlength\headheight{12pt}

    Separation between header and text.

    \setlength\headsep{25pt}

    If you want to change other margins of the header or footer, please refer to the fancyhdr documentation on page 3.

    Cheers,
    Tom.

    • Just clear the header using \fancyhead{}. By omitting the content, you actually suppress it. You can also set the \headrulewidth to zero.

      Cheers,
      Tom.

  10. James

    Does anyone know how to get fancyhdr to do some special magic only on the first and/or last header / footer of the document? I’d like to add some information only on the first header and (something different) on the last footer.

  11. Marta

    Hi!

    Thanks for the tutorial :D I need to add a note at the end of my document that is not part of my document itself. It should be a page without header and footer… is it possible to do it?

    Thanks!

    • Hello!

      Try to add the following command after your section command to omit page style for your notes page:

      \thispagestyle{empty}

      Cheers,
      Tom.

    • Hi Sama,

      I suggest you use fancyhdr, making it easily to define what you need. Let me give you a code example that goes into the preamble:

      \usepackage{fancyhdr}
      \setlength{\headheight}{15.2pt}
      \pagestyle{fancy}
      \lhead{}
      \chead{}
      \rhead{\fancyplain{}{\textit{\leftmark}}}

      I took this from the Wikibooks LaTeX Page Layout website.

      Cheers, Tom

  12. Alem

    Hi all
    I got this strange looking problem. My tex files do not compile in one of my pc’s where i have installed all the necessary packages. They are ok when i remove the bibliography part and compile them. The strange thing is that they do compile with another pc which has just the same compiler, editor and the likes with the bibliography command included . Any help please?

    • Hmmm, honestly, I don’t know. Hard to say without seeing the code. Have you tried deleting all the files except the source files and rerun latex. Also, if you are using bibitems within you Latex document, you may want to try using a bibtex file.

      Tom.

  13. gda

    Hi! very useful information, congratulations Tom. I have a problem: I’m using “book ” and i wrote this custom:

    \fancyhf{}
    \fancyhead[LE,RO]{\bfseries\thepage}
    \fancyhead[LO]{\bfseries\rightmark}
    \fancyhead[RE]{\bfseries\leftmark}

    so, everytime a chapter ends on an odd page, a new even page (blank of course) is added. I dont want this to happens of course. What can i do?

    thank you

    pf: by the way, if i put “oneside” in documentclass, the above commands dont work for Odd pages (the Odd pages act as if they were even)

    • Hi!

      I suggest you use either of the following:

      \let\cleardoublepage\clearpage

      in your preamble, or

      \documentclass[openany]{book}

      Either should work, but it’s always good to have a backup :-).

      Cheers, Tom.

  14. Robin

    What if I dont want to use fancyhdr? I want to write a custom class. I want define the footer style there. How can I do that without using any package?

    • Hi Robin,

      Hmmm, why would you not want to use any package? You can still use packages in your custom class (I found this custom class example with fancyhdr on Ankur’s blog).
      However, if you really don’t want to use packages, you can use the page counter, the chapter/section reference and commands like \hrule in your custom class to define whatever header/footer you like to have.

      Let me know if you have more specific questions.

      Thanks, Tom.

  15. raja

    Hi Tom,
    Your inputs are really helpful.

    I am using Fancy header. Is it possible to get chapter name and section name in even and odd pages using onesided page format.

    I have created a document in one side format. To create header, I changed the document format from onesided to twosided. Format of the document changed but with problems(i.e. In onesided page it is good but in twosided page it was not good.)

  16. Prakash

    Hello!
    Will any body tell me how to write chapter information on right hand and section in formation on left hand on even page and reverse on the odd page.

    Thank You.
    Prakash

    • That should be the default behavior using:

      \usepackage{fancyhdr}
      \pagestyle{fancy}

      If you need to define it yourself, use:

      \fancyhead{}
      \fancyhead[RO,LE]{\rightmark}
      \fancyhead[LO, RE]{\leftmark}

      Cheers, Tom.

  17. Benoit

    Hi,
    I wanted to know if it was possible to frame the headers and the footers with the fancyhdr package. I have looked and looked but I didn’t find.
    I have tried
    \fancyhead{\fbox}
    but it frames the different parts of the header separately… Should I use an other package ?
    Please help me I’m a bit desperate !

    Thank you,
    Benoit

    • Hi Benoit,

      It’s not great, but it’s a start. Hope it helps. Cheers, Tom.

      \documentclass[a4paper]{report}
      \usepackage{fancyhdr}
      \pagestyle{fancy}
      \fancyhf{}
      \fancyhead{%
      \fbox{\parbox[t][\headheight]{\textwidth}{$\;$}}}
      \fancyfoot{%
      \vspace{-15pt}
      \fbox{\parbox[t][\footskip]{\textwidth}{$\;$}}}
      \fancyfoot[C]{\thepage}
      \begin{document}
      bla
      \end{document}
      • Benoit

        Hi Tom,

        Thanks for your answer, however it seems there is a problem with this code because the header keeps growing in height, finally eating irrevocably the totality of the page… but I may have found a solution using the tikz package ! I find it’s not very elegant but in the end I get what I wanted which is already a good thing. I put it so that it may help someone else :

        \documentclass[a4paper]{report}
        \usepackage{tikz}
        \usepackage{fancyhdr}
        \usepackage{calc}
        %
        \newcommand*\tikzhead[0]{%
        \begin{tikzpicture}[remember picture, overlay]
        \draw (-0.25,-0.65) rectangle (\linewidth+0.25cm, 0.5cm);
        \end{tikzpicture}}
        
        % the same can be used for the footer
        
        \pagestyle{fancyplain}
        \fancyhf{}
        \lhead{\tikzhead
        %my left header
        }
        \chead{
        % my central header
        }
        ...

        The trick is to put the tikzpicture only in the left part of the header/footer. Really hope it may help someone !

      • Hi Benoit, thanks for posting this solution. I corrected the things you mentioned and it works fine now. Thanks again, Tom.

  18. Gaurang

    Dear Tom
    I want to put footer on title page of IEEE format in LaTeX and other different footer on other pages. What is the LaTeX command for it?

    • Hi Susanna,

      Just set the width of the line to zero:

      \renewcommand{\headrulewidth}{0pt}
      \renewcommand{\footrulewidth}{0pt}

      Best, Tom

  19. Kyle

    Hi,

    I’ve used the fancyfoot command to put a footer on a poster but was wondering how to get rid if the page number?

    For my document I have used \pagestyle{empty} but when I use \fancyfoot it puts the page number back

    Any help would be great

    Thanks,

    Kyle

    • Hi Kyle,

      I suppose you are using maketitle. It interferes and changes the pagestyle after you set it to empty. First I thought you could use:

      ...
      \maketitle
      \thispagestyle{empty}
      ...

      However, since you need a footer, you could redefine the plain page style, making it really plain and set the footer as needed:

      \documentclass{article}
      \usepackage{fancyhdr}
      \fancypagestyle{plain}{ %
      \fancyhf{}
      \fancyfoot[C]{Draft}
      \renewcommand{\headrulewidth}{0pt}
      \renewcommand{\footrulewidth}{0pt}}
      \begin{document}
      	\title{Title}
      	\author{Article Author}
      	\maketitle
      	The article starts here
      \end{document}

      From Wikibooks.

      Best, Tom.

    • Hi there! I found this relatively simple piece of code that may work for you. Hope it helps, Tom.

      \documentclass{article}
      \usepackage{fancyhdr}
      \renewcommand{\thispagestyle}[1]{} % do nothing
      \begin{document}
      \pagestyle{fancy}
      \lhead{\textit{leftheader}}
      \rhead{} %empty
      \title{article title}
      \author{article author}
      \maketitle
      The article starts here
      \end{document}
  20. Esther

    Dear Tom,

    On my special Pages (Table of contents, begin of chapter) the page number appears centered at the bottom of the page. I want it to appear at the top right of the page and therefore use this:

    \fancypagestyle{plain}{ % redefining plain pagestyle
    \fancyhf % clear all headers and footers fields
    \fancyhead{}
    \fancyfoot{}
    \rhead{\thepage}
    \renewcommand{\headrulewidth}{0pt}
    }

    This does not work. I also tried to use:

    \fancyhead[R]{\thepage}

    This also doesn’t work. The page number appears on the top left.
    What can I do?

    • Dear Esther,

      Try the following code and let me know if it doesn’t work:

      \usepackage{fancyhdr}
      ...
      \pagestyle{fancy}
      \fancyhead{}
      \fancyfoot{}
      \fancyhead[R]{\thepage}
      \renewcommand{\headrulewidth}{0pt}

      Best, Tom

      • Esther

        Dear Tom,

        When I try this my page numbers still appear on the bottom center.

        Also, now my ‘normal page’ headers change from mentioning the Chapter to mentioning the section in my chapter.
        I have \pagestyle{headings} written in my file.

        Thanks for your reply.
        Esther

      • Esther

        I have fixed this, but it is still a strange thing that the former codes did not work. I used:

        \fancypagestyle{plain}{
        \fancyhf
        \lhead{}
        \chead{}
        \rhead{\thepage}
        \renewcommand{\headrulewidth}{0pt}
        }
      • Hi Esther,

        Thanks for the update. I didn’t see that you are actually redefining the pagestyle plain. So after that, you would have to set it (\pagestyle{plain}), which I’m sure you do. Another possibility would be to use fancy and change it according to your needs (see my previous answer).

        Best, Tom.

  21. Nitin

    Hi Tom,

    I am writing master thesis and have to place a logo in footer on all the pages except the title page. I tried with fancyhdr but it misses the logo on every chapter’s first page or content page etc. How to force the footer logo on every page except the title page?

    Thanks in advance,
    Regards, Nitin

    • Hi Nitin,

      Here is some code that should do what you need. It redefines the pagestyle plain, which is what LaTeX uses for the first page of a chapter. Give it a try.

      \documentclass[a4paper]{report}
      \usepackage{fancyhdr, graphicx, blindtext}
      \fancypagestyle{plain}{%
      	\fancyhf{}%
      	\fancyfoot[C]{\thepage}%
      	\fancyhead[R]{\includegraphics[width=1cm]{test}}
      	\renewcommand{\headrulewidth}{0pt}
      	\renewcommand{\footrulewidth}{0pt}
      }
      \title{This is my title}
      \begin{document}
      \maketitle
      \tableofcontents
      \pagestyle{plain}
      \chapter{First chapter}
      \Blindtext
      \end{document}

      Another possibility would be to add the logo to the background, using the eso-pic package, for example. See here for more details.

      Best, Tom.

  22. Marcin

    How to change the length of the decorating line in heading in LaTeX? I would like to have it as long as my text on the page? Kind wishes

    • Hey Marcin,

      I would expect the line to have the same length as the text. This post shows how to display page margins. Does the header and text box have the same width? You can change the margins using the geometry package. In case that doesn’t solve your problem, please provide a minimal working example.

      Cheers, Tom.

  23. Hi Tom,

    That was a neat article. However, when I use the following in my preamble, I’m just getting a plain straight line as my header and the page number displayed at the bottom center of my page.

    \documentclass{book}
    \usepackage[paperwidth=5in,paperheight=7in]{geometry}
    \usepackage{fancyhdr}
    \pagestyle{fancy}

    I thought the default fanyhdr trait was to print the name of the chapter as the header. But in my case nothing is being printed.

    I wanted to have the name of the corresponding chapters as the headers of each page in my book. How can I achieve that?

    Thank you.

    • Update: The titles of the chapters/sections were not coming in the header because I had starred them (/section*). In order to achieve what I wanted, I removed all the stars and added the following to the preamble:

      \setcounter{secnumdepth}{0}

      Solved.

  24. Hassan

    hello Tom,
    I am writing my masters thesis. I am using the fancyhdr package. Single sided report document class. I get the section name and number on the left header and the chapter number/name on the right header. I want to change the font size (and i dont want it in italics, its italics by default), because they over write each other. Please if you could help. Its urgent. Waiting. Thanks.

    • Hi Hassan,

      Thanks for your question. The code below shows how to change the font size for your fancy header. You can play with the numbers. I used 9 with a baseline-skip of 11 (~1.2x).

      You may also find this post helpful. By the way, the fancyhdr documentation is extensive and includes lots of examples.

      Best, Tom.

      \documentclass[11pt, oneside]{report}
      \usepackage{fancyhdr, blindtext}
      \fancyhf{}
      \fancyhead[L]{\fontsize{9}{11}\selectfont \rightmark}
      \fancyhead[R]{\fontsize{9}{11}\selectfont \leftmark}
      \fancyfoot[C]{\thepage}
      \pagestyle{fancy}
      \begin{document}
      \tableofcontents
      \blinddocument
      \end{document}
      • Hassan

        Thank you so much for your reply. I have another problem. I try to set the page counters but i am having problems with it. I have abstract, acknowledgements, list of figures, list of tables.. i want them to be numbered in Romans (i,ii,iii,..).. i have succeeded in doing that with this \pagenumbering{roman}
        \setcounter{page}{1}

        but there are two problems, I dont see the page numbers on
        abstract, acknowledgements page.. and in the table of contents, it shows both abstract and acknowledgements on teh same page i.e. page number i. I have also used \newpage after abstract.. for acknowledgements i am using this..

        \renewcommand{\abstractname}{Acknowledgements}
        \begin{abstract}
        …my text goes here…
        \end{abstract}

        please if you could help me with the problem. Thank you in advance.

      • Hi Hassan,

        The code below will produce the desired result. The abstract environment internally calls \thispagestyle{empty}, which is why you have to set the page number manually.

        \documentclass{report}
        \usepackage{blindtext}
        \title{Title}
        \begin{document}
        \maketitle
        \pagenumbering{roman}
        \begin{abstract}
        \thispagestyle{plain}
        \blindtext
        \end{abstract}
        \renewcommand{\abstractname}{Acknowledgements}
        \begin{abstract}
        \thispagestyle{plain}
        \setcounter{page}{2}
        \blindtext
        \end{abstract}
        \setcounter{page}{3}
        \tableofcontents
        \listoffigures
        \listoftables
        \cleardoublepage
        \setcounter{page}{1}
        \pagenumbering{arabic}
        \chapter{Introduction}
        \Blindtext
        \end{document}

        Alternatively, you can use:

        \chapter*{Acknowledgements}
        \addcontentsline{toc}{chapter}{Acknowledgements}

        instead of diverting abstract from its intended use.

        Cheers, Tom.

  25. Nir

    Hey.

    I’m trying to put chapter name in the format:

    Chapter 1 – Introduction

    or something similar in the top left corner. Writing:

    \fancyhead[LO,LE]{\thechapter}

    Just gives me the chapter number. How can i fix this?

  26. atefeh

    Please help!!

    I am writing up my chemistry thesis in Latex using

    \usepackage{fancyhdr}
    \pagestyle{fancy}

    How can I define a fixed term for some of my sections and not all!! My exact problem is that the header is in capital letters, which is fine! but since in chemistry the formatting makes a huge impact on the meaning. I have to be consistent.

    many many thanks

    Hajar

    • Do you mean some chapter or section headings contain terms that need to be printed in small letters? Could you give me an example?

      Thanks, Tom.

      • atefeh

        yes thats right! for eg.,
        Synthesis of nEG Analouges, that appear in a capital letter!

        many thanks for taking the time and help in advance

      • Hey! There is indeed a relatively simple solution. \lowercase{} forces the text to be in small letters in a capital letter environment. See below!

        Best, Tom.

        \documentclass[11pt]{report}
        \usepackage{fancyhdr, blindtext}
        \pagestyle{fancy}
        \begin{document}
        \tableofcontents
        \chapter{Synthesis of nEG Analouges}
        \Blindtext
        \chapter{S\lowercase{ynthesis of n}EG A\lowercase{nalouges}}
        \Blindtext
        \end{document}
      • Valerie

        Hi,

        I have a similar problem but the other way round- the header is written in capital letters (which is good) but I have some abbreviations in the titles of my chapters and I would like that they stand out, i.e. that they are written in a larger case than the rest of the text. Is that possible ? For e.g. “AR detection”.

        Thanks in advance,
        Best regards,
        Valerie

      • tom

        You can use \uppercase to produce upper-case letters in a similar way as \lowercase in the previous example.

        If this doesn’t solve your problem, please provide a minimal working example.

        Cheers, Tom

      • Valerie

        Hi,

        Here is a minimal working example:

        \documentclass[a4paper,11pt,twoside]{report}
        
        \usepackage{fancyhdr}
        \fancyhead[LE,RO]{\thepage}
        \fancyhead[RE]{\small \leftmark}
        \fancyhead[LO]{\small \rightmark}
        
        \usepackage{blindtext}
        
        
        \begin{document}
        
        \pagestyle{fancy}
        
        \chapter{Introduction}
        
        \section{This is a long section name that I want to shorten for the header}
        \sectionmark{\uppercase{AR} detection}
        
        \Blindtext
        \Blindtext
        
        \end{document}

        As you can see, the title of the section is too long and I use \sectionmark to make a shorter name. However, the \uppercase does not work.

        Thanks for your help :)

      • tom

        Thanks for the example. To make “AR” stand out, you could increase the font size as you already suggested or alternatively write it in bold face:

        \sectionmark{{\large AR} detection} % large font size
        \sectionmark{{\Large AR} detection} % larger font size
        \sectionmark{{\bf AR} detection} % bold face
      • Valerie

        Thanks a lot for your help! It didn’t work with \sectionmark{{large AR} detection} but \sectionmark{{\large{AR}}s detection} worked fine! Have a nice day :)

  27. Aida Kazagic

    Hi,

    I would like to have larger spacing between the header and the text. I have tried various solutions but cannot make any of them work as I want. :-( The code I am using is:

    \usepackage{fancyhdr}
    \setlength{\headheight}{15pt}
    \pagestyle{fancyplain}
    \renewcommand{\chaptermark}[1]{\markboth{#1}{}}
    \renewcommand{\sectionmark}[1]{\markright{#1}{}}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
    \fancyhf{}
    \rhead{\fancyplain{}{\textit{\rightmark}}}
    \rfoot{\thepage}

    Also, do you know how I can get both the section nr and name printed in the header? I thought that I would get that with the command \rightmark, but only the section name appears.

    Thanks in advance.
    Best regards, Aida

    • Hi Aida,

      Thanks for your comment. To increase the space between header and text, use the variable headsep rather than headheight. See the figure on wikibooks site about page layout for all variable names.
      rightmark is correct, but you are redefining sectionmark. Just remove those lines and it works. See the minimal working example below.

      Cheers, Tom.

      \documentclass[11pt]{report}
      \usepackage{fancyhdr}
      \usepackage{showframe}
      \usepackage{blindtext}
      \addtolength{\headsep}{15pt}
      \pagestyle{fancyplain}
      %\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
      %\renewcommand{\sectionmark}[1]{\markright{#1}{}}
      \renewcommand{\headrulewidth}{0pt}
      \renewcommand{\footrulewidth}{0pt}
      \fancyhf{}
      \rhead{\fancyplain{}{\textit{\rightmark}}}
      \rfoot{\thepage}
      \begin{document}
      \blinddocument
      \end{document}
  28. Hiya, thanks for this! it’s fixed what I’ve been trying to do for ages, however I’m now getting a “Package fancyhdr warning” saying \headheight (12.0pt) is too small; make it at least 34.97pt……what is it that I change for this as I’ve tried changing my font size, my textheight size, the textsize in the header and I can’t get rid of the error message? Thanks for any help
    Natalie

  29. Durlindana

    Hi Tom,
    I also need to display only chapters in the header, and I saw your advice for Sama. It works, but I have just one problem: the header line doesn’t finish at the beginning of the left margin of the page. How can I correct this?

    Maybe that’s because I changed the default margin size of LaTex…

    • Hi Durlindana,

      Thanks for your comment. How do you change the default margin size? Do you use the geometry package? Please give a minimal working example.

      Thanks,
      Tom.

  30. Alice

    Hi, I used the command for displaying only chapters in the header, but the header line stops before the right margin. How can I correct this?

  31. EmilLask

    Hi,

    I don’t understand why the vertical position of the footer changes from page 1 to page 2.
    Can you help me?

    Thanks Emil

  32. S.Karim

    hi all……
    I am writting a thesis in latex, I have almost done all the setting except one problem that I wana to remove only header not footer from only first page of each chapter, for other pages setting must remain same, how this could be done???
    using:
    \usepackage{titlesec}
    \usepackage{fancyhdr}

      • S.Karim

        Hi Tom,
        I tried alot but in vain, actually i want

        For other chapter pages:

        \pagestyle{fancy}
        \fancyhead[LE,RO]{\slshape \rightmark} %%%%  headings
        \fancyhead[LO,RE]{\slshape \leftmark}   %%%%  headings
        \lfoot{Author:~\textbf{\thesisname}}
        \cfoot{\thepage}
        \rfoot{\thesistitle}
        \renewcommand{\headrulewidth}{0.4pt}
        \renewcommand{\footrulewidth}{0.4pt}

        For 1st page of each chapter i have tried following codes:

        \thispagestyle{fancy}  % also \thispagestyle{plain}
        \fancyhead[LE,RO]{}
        \fancyhead[LO,RE]{}
        \lfoot{Author:~\textbf{\thesisname}}
        \cfoot{\thepage}
        \rfoot{\thesistitle}
        \renewcommand{\headrulewidth}{0pt}
        \renewcommand{\footrulewidth}{0.4pt}

        But it repeats for all pages.

        thanks,

      • Thanks for the code examples. So what I suggest is to create a special chapter-page-style. I reused your code and modified the chapter command by adding \thispagestyle after the chapter call. It’s somewhat complicated, because one has to take care of starred and non-starred version of the chapter command.

        Let me know if anything is unclear.

        Cheers, Tom

        \documentclass[11pt]{report}
        
        \usepackage{fancyhdr, blindtext}
        
        \def\thesisname{Someone}
        \def\thesistitle{Some thesis title}
        
        \fancyhead[LE,RO]{\slshape \rightmark} %%%%  headings
        \fancyhead[LO,RE]{\slshape \leftmark}   %%%%  headings
        \lfoot{Author:~\textbf{\thesisname}}
        \cfoot{\thepage}
        \rfoot{\thesistitle}
        \renewcommand{\headrulewidth}{0.4pt}
        \renewcommand{\footrulewidth}{0.4pt}
        
        \fancypagestyle{chapterstyle}{%
        	\fancyhead[LE,RO]{}
        	\fancyhead[LO,RE]{}
        	\lfoot{Author:~\textbf{\thesisname}}
        	\cfoot{\thepage}
        	\rfoot{\thesistitle}
        	\renewcommand{\headrulewidth}{0pt}
        	\renewcommand{\footrulewidth}{0.4pt}
        }
        
        %Redefine chapter by adding special first chapter page page-style
        \makeatletter
        	\let\stdchapter\chapter
        	\renewcommand*\chapter{%
        	\@ifstar{\starchapter}{\@dblarg\nostarchapter}}
        	\newcommand*\starchapter[1]{\stdchapter*{#1}\thispagestyle{chapterstyle}}
        	\def\nostarchapter[#1]#2{\stdchapter[{#1}]{#2}\thispagestyle{chapterstyle}}
        \makeatother
        
        \pagestyle{fancy}
        
        \begin{document}
        \tableofcontents
        \chapter{Some chapter}
        \Blindtext
        \chapter*{Some non-numbered chapter}
        \Blindtext
        \end{document}
  33. Hugo Silva

    Hello im trying to use my fancyfoot in every page, but that just not happen, just appear in the first page, fancyhead appear in all pages working fine.

    \fancyhead{}
    \fancyhead[CO]{\includegraphics{BON}}
    \fancyfoot{}
    \fancyfoot[CO]{Confidencial}
    \footskip=12pt
    
    \pagestyle{fancy}
    • Hi Hugo,

      Set the page style first and make the changes after. If that doesn’t solve the problem, please post a minimal working example.

      Thanks, Tom.

      • Your example works for me.

        \documentclass[11pt]{report}
        \usepackage{fancyhdr,blindtext}
        \fancyhead{}
        \fancyhead[CO]{\rule{0.1\textwidth}{0.05\textwidth}}
        \fancyfoot{}
        \fancyfoot[CO]{Confidencial}
        \pagestyle{fancy}
        \begin{document}
        \blinddocument
        \end{document}
  34. katy

    Hello Guys,

    I am using Bookclass and created several book chapters (each has its own author). Each book chapter need to have a heading on the first page of the chapter with the name of the book series and year. On the remaining pages of each chapter: even pages have the running title of the chapter and odd pages have authors names. So that is all fine. Now when I try to combine these in one MasterDocument things gets very messy. So far I tried the following in the preamble of the masterdocument:

    \usepackage{fancyhdr}
    \pagestyle{fancy}
    \newcommand{\firstpagehead}[1]{Book Series name 2014}
    \newcommand{\shortauthor}[1]{ Authors et al}
    \newcommand{\runtitle}[1]{Running title}
    
    \fancyhf{}
    \fancyhead[CO]{\ifthenelse{\value{page}=1}{\firstpagehead}{\shortauthor} }
    \fancyhead[CE]{\ifthenelse{\value{page}=1}{}{\runtitle}}
    \fancyhead[LE,RO]{\ifthenelse{\value{page}=1}{}{\textnormal\thepage}}
    
    \renewcommand{\headrulewidth}{0.5pt}
    \renewcommand{\footrulewidth}{0pt}
    \addtolength{\headheight}{0.5pt}
    \setlength{\footskip}{0in}
    \renewcommand{\footruleskip}{0pt}
    \fancypagestyle{plain}{%
    \fancyhead{}
    \renewcommand{\headrulewidth}{0pt}
    }

    I also tried to put the following lines after table of contents and before each chapter to reset the above three commands

    \renewcommand{\firstpagehead}[1]{Book Series name 2014}
    \renewcommand{\shortauthor}[1]{ new Authors et al}
    \renewcommand{\runtitle}[1]{new Running title}

    The above three renewed commands did not work. I am also struggiling on how to define the first page of each chapter?

    Help is most appreciated.

    • Hi Katy,

      Thanks for your question. Unless you reset the page number after every chapter, the condition on page will only work for the first page. I got a similar question, see here for how to have a different header/footer on the first page of a chapter. Furthermore, it might be a good idea to create a macro that redefines all the commands and creates a chapter, e.g.:

      \newcommand{\mychapter}[3]{%
      \renewcommand{\firstpagehead}[1]{#2}
      \renewcommand{\shortauthor}[1]{#3}
      \chapter{#1}}
      ...
      \mychapter{Chapter title}{First page head}{Short author}

      HTH, Tom

  35. Fred

    Dear all,

    I am currently finishing my phd thesis for the publication process. Everything works out perfectly so far, but I would like to have the page numbering in the header in Italic and not in normal . Can anyone please help me?

    Thank´s a lot in advance!

    BR
    Fred

    • Hi Fred,

      I removed your code, since it was rather long and you explained your issue well enough. By adding the line which is highlighted, the page number will appear in italics throughout the document.

      Let me know if that’s not what you were looking for.

      \documentclass{book}
      \usepackage{fancyhdr, blindtext}
      \pagestyle{fancy}
      \fancyhf{}
      
      \fancyhead[LE,RO]{\thepage}
      \fancyhead[RE]{\slshape\nouppercase{\rightmark}}
      \fancyhead[LO]{\slshape\nouppercase{\leftmark}}
      
      %redefine page number
      \def\thepage{\textit{\arabic{page}}}
      
      \begin{document}
      \Blinddocument
      \end{document}
  36. Fred

    Dear Tom,

    thanks a lot for your response. Unfortunately your proposal does not work :( Do you know a second way of solving the problem?

    Kind regards
    Friedrich

    • Dear Fred,

      Please provide some more details on what exactly doesn’t work with the solution. Ideally, you’d provide a minimal working example illustrating the problem.

      Thanks, Tom

  37. Robert

    I have a few pages I have gathered several chapters (appendices) for a special purpose, suppressing their initialization of a new page by putting: \let\clearpage\relax . Now I have a problem of the runinng header — namely, since on almost every page there is at least one new chapter (appendix) and all of them are treated as the first page of the chapter (appendix). So all the page numbers are put in the center of the bottom line. I would like to put a running header for all this squeezed chapters to be “Squeezed chapters”. But when I interveene with \fancyfoot{} — to clear the page number in the footer — I cannot reinstall it properly in the rest of my document (book.cls). That is, when I put: \fancyfoot[C]{\thepage} — it does appear, but not only on the first page of chapter, but on all of them, meaning that the automatism of the plain vs. fancy headings is lost! It seems that anything I do with the commands that you suggest, I loose that automatism. I use the \begingroup and \endgroup to localize the settings, but it does not help. Any suggestions?

Leave a Reply