174 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 😀 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?

  38. djh

    Is there a way to accomplish the following in Latex?

    3
    FOR OFFICIAL USE ONLY

    I need this to only be on specific the pages that contain this type of information. I have not been able to get this to work.

    Any help will be greatly appreciated.

    • tom

      Hi djh,

      I’m not sure I understand what you are trying to accomplish. Please clarify and provide a minimal working example. Thanks, Tom.

    • tom

      Hi Abel,

      Thanks for your question. I’m not sure what exactly you have in mind. You can find a possible solution here. If this is not what you were looking for, please provide a minimal working example and/or a more concise description.

      Thanks, Tom

      • Abel

        Dear Tom,

        Thank you for the link and sorry for the delay in getting back to you.

        I adapted the StackExhange code to create a colored footer in a one-sided article. However, when the document is printed the location and dimensions of the footer differ from the screen view.

        Here is the code:

        \documentclass[12pt, letterpaper]{article}
        %%%% Printed version does not match screen view. %%%%
        \usepackage[letterpaper, left=2cm, right=2cm, top=1.5cm, bindingoffset=0cm]{geometry}
        \usepackage{fancyhdr}
        \usepackage{titlesec}
        \usepackage{tikz}
        \usepackage{graphicx}
        \usepackage{xcolor}
        \usepackage[T1]{fontenc}
        \usepackage{uarial}
        \renewcommand{\familydefault}{\sfdefault}
        
        \newcommand\epino{\fontsize{12pt}{14.4pt}\selectfont text}
        
        \definecolor{hblue}{rgb}{0.133,0.184,0.337}
        \definecolor{htext1}{rgb}{0.0314,0.294,0.510}
        
        \usetikzlibrary{calc}
        
        \renewcommand{\headrulewidth}{0pt}
        \renewcommand{\footrulewidth}{0pt}
        
        \pagestyle{fancy}
        \fancyhf{}
        \fancyfoot[C]{%
        \begin{tikzpicture}[overlay, remember picture]%
            \fill[hblue] ($(current page.south west)+(.45,.6cm)$) rectangle ($(current page.south east)+(-.6,2.3cm)$);
            \node[anchor=south west, text=white, minimum size=2.8cm, inner xsep=1cm] at (current page.south west) {\epino};
        %    \node[anchor=south east, minimum size=2.875cm, inner xsep=1.3cm] at (current page.south east)
        %     {\includegraphics[width=1.4cm, height=1.6cm]{logo}};
        \end{tikzpicture}
        }
        
        \begin{document}
        
        \begin{flushleft}
        \fontsize{18pt}{21.6pt}\selectfont
        \textcolor{htext1}{\textbf{Some Text}} \\
        \vspace{.5cm}
        \fontsize{14pt}{16.8pt}\selectfont
        \textbf{\underline{More text}} \\ 
        \vspace{2.8pt}
        \fontsize{14pt}{16.8pt}\selectfont
        \textbf{\underline{And more text}} 
        \end{flushleft} 
        
        \end{document}

        Note, I am running MikTeX 2.9 with TeXworks front end.

        Any thoughts?

        Thanks, again.

        Best wishes,

        Abel

      • tom

        Sounds like a hardware problem: Printers are usually not able to print at the very edge of the paper. If your printer can’t do “borderless” printing, perhaps a printing company can help you with that. Hope this helps, Tom.

      • Abel Wolman

        Dear Tom,

        Once again, sorry for not replying sooner. And thank you for your thoughts regarding my code. I can force my printer to print to the edge of the paper, but then the screen version of the PDF is clipped. Btw, my goal is to replicate an MS Word template, which displays and prints correctly.

        Best wishes,

        Abel

      • tom

        Hi Abel,

        It sounds like there is a difference if you print from Word or from your PDF viewer. However, as I can’t replicate the problem, I’m not sure how to help you. Sorry for that.

        Best regards,
        Thomas

  39. Hi, Tom!

    First of all – thank you for your wonderful tutorials, I know, it’s a lot of work behind.
    I have a small task, which seems a little bit too tricky to me, as I’m pretty new to TeX.
    The problem is following: to make a backgrounded footer, with page numbers at strict position. Let me show a couple of image in order to make myself clear:
    http://oi67.tinypic.com/10ptwci.jpg – left page
    http://oi68.tinypic.com/157j2th.jpg – right page
    As you can see, there should be an image in footer’s background and the page number should exactly match the yellow “placeholder”.

    Thank you in advance for your help and I hope this would be interesting to other readers, too.

    Best regards,
    Igor Bannicov.

    • tom

      Hi Igor,

      That’s a cool footer. Below is the code for one side. Please try to do the other side yourself. You can use an if...else conditional statement, which is explained here.

      Best, Tom

      \documentclass{article}
      \usepackage{tikz}
      \usepackage{tikzpagenodes}
      \usetikzlibrary{calc}
      \usepackage{blindtext}
      \usepackage{atbegshi}
      \definecolor{mycolor1}{RGB}{0,204,204}
      \definecolor{mycolor2}{RGB}{102,255,102}
      \newcommand\Footer{%
      \begin{tikzpicture}[remember picture,overlay]
      \fill[mycolor1]
      	([yshift=-40pt]current page text area.south west) -- 
      	([yshift=-40pt]current page text area.south east) --
      	([yshift=-60pt]current page text area.south east) -- 
      	([yshift=-60pt]current page text area.south west) -- cycle;
      \fill[mycolor2]
      	([yshift=-40pt,xshift=-80pt]current page text area.south east) -- 
      	([yshift=-40pt,xshift=-30pt]current page text area.south east) --
      	([yshift=-60pt,xshift=-20pt]current page text area.south east) -- 
      	([yshift=-60pt,xshift=-70pt]current page text area.south east) -- cycle;
      \node at ([yshift=-50pt,xshift=-50pt]current page text area.south east) {\thepage};
      \end{tikzpicture}%
      }
      \pagestyle{empty}
      \begin{document}
      %Titlepage
      %\AtBeginShipoutFirst{\Footer}
      \AtBeginShipout{\Footer}
      \blinddocument
      \end{document}
  40. HI Tom,
    Are there packages that fancyhdr clashes with? I have quite a complex setup for my thesis (i.e. many packages) and I can’t seem to set up fancyhdr in order to put my page numbers left for even pages and right for odd… are there any packages that can cause this behavior?
    List of packages I use:

    \usepackage{geometry}
    \usepackage{fancyhdr}
    \pagestyle{fancy}
    \usepackage{abstract}
    \usepackage[utf8]{inputenc}
    \usepackage{graphicx}
    \usepackage{times}
    \usepackage{latexsym}
    \usepackage[round]{natbib}
    \usepackage{csquotes}
    \usepackage{subcaption}
    \usepackage{caption}
    \usepackage{tocloft}
    \usepackage{sectsty}
    \usepackage{longtable}
    \usepackage{tabulary}
    \usepackage{enumitem,xcolor}
    \usepackage{array}
    \usepackage{setspace}

    Thanks in advance!

  41. I am working with the IEEE Conf format. I am having trouble just showing the copyright in the first page and no other changes anywhere else.

    I have been trying code like the following:

    \usepackage{fancyhdr}
    \usepackage{ifthen}
    %\pagestyle{fancy}
    %--- option 1
    %\fancyfoot[CF]{978-1-5386-5051-6/18/31.00 2018 IEEE}
    %\fancyfoot{}
    % option 2
    %\fancyfoot[CF]{\ifnum\thepage=1 first page \fi}
    %\fancyfoot{}

    But i can’t get to see the footer on page 1.
    I would be greateful for some feedback.

    • Hi Rojas70,

      See the updated code below. Does it do what you wanted? \fancyfoot{} creates an empty footer and overwrites any previous footer definition.

      Best, Tom

      \documentclass[11pt]{article}
      \usepackage{blindtext}
      \usepackage{fancyhdr}
      \usepackage{ifthen}
      \pagestyle{fancy}
      \fancyfoot[CF]{\ifnum\thepage=1 first page \else 978-1-5386-5051-6/18/31.00 2018 IEEE \fi}
      \begin{document}
      \blinddocument
      \end{document}
  42. Karl Tokle

    Is it posible to make an foot rules in two different colors. My company want to have an foot ruler with green and red color.

    Regards

    Karl

    • Hi Karl,

      Can you be a bit more specific, please. Do you want two parallel lines: one green, one red. Or a line with a gradient from green to red. Or green on even pages and red on odd pages?

      Best, Tom.

      • Karl Tokle

        Hi Tom,

        On all pages the line should change from green to red in the middle of the page. No paralell lines no gradient, sme on all pages in the report.

        Regards

        Karl

      • Hi Karl,

        Thanks for getting back to me. See below for a possible solution.

        Best, Tom

        \documentclass[11pt]{article}
        \usepackage{blindtext}
        \usepackage{xcolor}
        \usepackage{fancyhdr}
        \renewcommand{\footrulewidth}{0.4pt}
        \renewcommand{\footrule}{\hbox to \headwidth{\color{green}\leaders\hrule height \footrulewidth\hfill\color{red}\leaders\hrule height \footrulewidth\hfill}}
        \pagestyle{fancy}
        \begin{document}
        \blinddocument
        \end{document}
      • Karl Tokle

        Hi Tom,

        This works very well. I have used laTEX many years, but not very complicated vays.

        I have make my ovn heading with two lines and text. The problem is that I got an extra line in the heading which should not be there. I think this comes from the fancy package.

        Is it possible to send you an pdf file which shows this.

        Regards

        Karl

      • Hi Karl,

        Can you prepare a minimal working example and post it here, please. That would be more useful, since I can then run the code on my system.

        Thanks, Tom

      • Karl Tokle

        Hi Tom,

        If you run this you will se the problems with the heading.

        Regards
        Karl

        \documentclass[11pt]{article}
        \newcommand{\blob}{\rule[0cm]{16cm}{0.5pt}}
        \newcommand\rblob{
          \begin{picture}(0,0)
            \put(-16,0.9){\blob}
            \put(-16,-0.3){\blob}
          \end{picture}}
        \usepackage{xcolor}
        \usepackage{fancyhdr}
        \definecolor{abc}{rgb}{0,0.514,0.337}       % grønn
        \definecolor{def}{rgb}{0.83,0.46,0.21}    % oransje
        \renewcommand{\footrulewidth}{1.4pt}
        \renewcommand{\footrule}{\hbox to \headwidth{\color{abc}\leaders\hrule height
        \footrulewidth\hfill\color{def}\leaders\hrule height
        \footrulewidth\hfill  }}
        \pagestyle{fancy}
        \fancyhf{}
        \chead{\sl  Triaxial compression tests, uniaxial strain pore volume compressibility tests and \ hydrostatic test,   \mbox{6705/10-1 well, Equinor}}
        \lhead{}
        \rhead{}
        \cfoot{\vspace{1mm} RT-103225 }
        \rfoot{\vspace{1mm} Page \thepage \ of 72 }
        \begin{document}
        \fancyhead[RO]{\rblob}
        \addtocounter{page}{2}
        \section{Introduction}
        In order to obtain rock strength of samples from the 6705/10-1 well 5 samples from depth 3233 m and  5 samples from depth 3263 m
        \section{Sample preparation}
             Plugs of 1.5$"$ diameter were drilled from two seal peels at Weatherford Laboratories in Trondheim.
             The samples were  drilled parallel to the
        \end{document}
      • Hi Karl,

        Thanks for the example. I am not sure which line you want to get rid of, so I’ll just tell you for both :-).

        1) To remove the double line on the right, comment out this part: \fancyhead[RO]{\rblob}. It would make sense to move this line up to the preamble anyways. Also, \rhead{…} and \fancyhead[R]{…} are the same in a oneside document. The O in RO stands for odd, so in my opinion using O only makes sense with the twoside documentclass option.
        2) To remove the ‘standard’ single line below your text in the header, use \renewcommand{\headrulewidth}{0pt} in the preamble.

        Hope this helps.

        Best, Tom

      • Karl Tokle

        Hi Tom,

        The

        \renewcommand{\headrulewidth}{0pt}

        solve my problem with the header. I can now make the report with the correct footer. I have used lot of hours to try to solve this problem with the footer.

        Thanks again for your help .

        Regards

        Karl

  43. Edwige

    Hi Tom,

    I am writing a document and I would like the line, and both the number and the name of the section to appear at the right side of the header of each page. Also the line does not fit with the geometry. Here is the code I am using, but it does work as I want.

    \documentclass[10pt,a4paper]{article}
    \usepackage[latin1]{inputenc}
    \usepackage{fancyhdr}
    \setlength{\headheight}{15.2pt}
    \pagestyle{fancy}
    \renewcommand{\sectionmark}[1]{ \markright{#1}{}}
    \renewcommand{\headrulewidth}{1pt}
    \usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
    \title{The title}
    \author{Author here}
    
    \begin{document}
    	\maketitle
    	\newpage
    	\section{Abbreviations}
            The text goes here
    	\newpage
    	\section{This is the second section}
    	The text goes here
    	\newpage
    	\section{New section}
    	The text goes here
    	
    \end{document}

    Please any help will be highly appreciated.

    Best, Edwige.

    • Hi Edwige,

      Thanks much for the nice example, that makes it much easier for me to help. A few things that might be useful:

      • Load geometry before fancyhdr. Otherwise, fancyhdr does not know the the size of the text area. This should fix the line width.
      • I wouldn’t recommend changing \sectionmark. Instead, use \fancyhead[R]{...} as shown in the text. That said, the default for article is number and section name on the right side, at least that’s what I get when I typeset your code.
      • Use \usepackage{showframe} to get an idea of the margins of your document. The boxes visualise the margins.

      Best, Tom

      • Edwige

        Hi Tom,

        Thank you for your help. In fact, I tried as you suggested and the line was fixed. Just that for now the section number and name appear, but the section name is in Upper case. Please how can I write with lower case? This is the code that I have written.

        \documentclass[10pt,a4paper]{article}
        \usepackage[latin1]{inputenc}
        \usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
        \usepackage{fancyhdr}
        \renewcommand{\sectionmark}[1]{\markboth{\sectionname\ \thesection\ #1}{}}
        \setlength{\headheight}{15.2pt}
        \pagestyle{fancy}
        \renewcommand{\headrulewidth}{1pt}
        \title{The title}
        \author{Author here}
        \begin{document}
        	\maketitle
        	\newpage
        \section{Abbreviations}
        	The text goes here
        	\newpage
        \section{This is the second section}
        	The text goes here
        	\newpage
        \section{New section}
        	The text goes here	
        \end{document}

        Best, Edwige.

      • Hi Edwige,

        Great to hear you fixed the issue with the line. There are two ways to suppress uppercase in the header (fancyhdr).

        % Change how the specific heading is typeset (See fancyhdr documentation for more details)
        \fancyhead[R]{\slshape\nouppercase{\leftmark}}
        
        % More drastic: redefine the uppercase macro to do nothing (might change thing in other places too)
        \renewcommand\MakeUppercase[1]{#1}
      • Edwige

        Hi Tom,

        Thank you very much for your help. The issue was fixed with your suggestions.

  44. Edwige

    Hi Tom,

    Another issue is that the text at the header is in italics which I do not want to be like that. Moreover, the subsection title also appears on the left of the header, which I do not want. I want only the section title to appears in normal characters and at the right of the header. Thank you

    Best, Edwige

    • Hi Ewige,

      I can’t test this now, but can you try this?

      \fancyhead[L]{} % Empty left header
      \fancyhead[R]{\nouppercase{\leftmark}} % Without \slshape ("italics")

      Best, Tom

Leave a Reply