Creating headers and footers in Latex can be done by using the package “fancyhdr”. This is a short introduction, showing the most important features of the package. If you know “fancyhdr” and are looking for something particular, refer to the fancyhdr-documentation.
First of all, you need to tell Latex to use the package:
\usepackage{fancyhdr}
and change the style from “plain” to “fancy”:
\pagestyle{fancy}
You will now the get the default fancy pagestyle which adds a line at the top of every page, except for some exceptions (title-page, abstract, new chapter in report).
Default fancyhdr page style:
Above the line, Latex will print headings:
Book/report
Left-hand side: section
Right-hand side: chapter
Note: if you use the optional documentclass argument “twoside”, Latex will alter the position of the section and chapter. (e.g. \documentclass[twoside]{report}, also introducing non-symmetric margins).
Article
For acticles, Latex will print the section only (chapters cannot be used with articles).
The footer only includes the page number which is centered by default.
Custom fancyhdr page style:
Even though fancyhdr has a default page style, you are free to define headers/footers yourself , which is not too difficult after all.
First you need to clear the default layout:
\fancyhead{}
\fancyfoot{}
There are seven letters you need to know before you can define your own header/footer:
E: Even page
O: Odd page
L: Left field
C: Center field
R: Right field
H: Header
F: Footer
Now it’s time to start defining your own layout. The definitions are added to the preamble:
\fancyhead[CO,CE]{---Draft---}
\fancyfoot[C]{Confidential}
\fancyfoot[RO, LE] {\thepage}
The decorative lines can be changed by increasing/decreasing their thickness (0pt means no line):
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
Note: According to the fancyhdr-documentation, the default layout is produced by the following commands:
\fancyhead[LE,RO]{\slshape \rightmark}
\fancyhead[LO,RE]{\slshape \leftmark}
\fancyfoot[C]{\thepage}
\headrulewidth 0.4pt
\footrulewidth 0 pt
December 1st, 2007 at 6:51 pm
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.
December 4th, 2007 at 7:09 pm
Good job, very helpful. Thanks.
June 12th, 2010 at 5:59 pm
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.
June 19th, 2010 at 10:13 am
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
January 15th, 2012 at 3:42 pm
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
……………………………………………………………………………………
January 17th, 2012 at 11:16 am
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 tofancyfor 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}January 30th, 2012 at 6:17 am
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
January 31st, 2012 at 10:34 am
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.
January 31st, 2012 at 5:01 pm
Dear Tom,
Thanks for your guidance and kind support to fix up the problem.
Thanks & Regards
Sarvesh
February 1st, 2012 at 2:39 am
Dear Sarvesh,
You are welcome. I hope you were able to adapt the code for your needs.
Best, Tom.
April 6th, 2011 at 12:34 am
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).
December 8th, 2007 at 2:02 pm
@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.
March 5th, 2008 at 4:40 pm
Thanks! Fantastic tutorial!!!
April 23rd, 2008 at 2:53 pm
Great! Thank you.
Tapani
June 23rd, 2008 at 8:34 pm
i actually saved this to del.icio.us. thank you so much!
June 25th, 2008 at 11:23 am
I always wanted to know how to format headers/footers
Great tutorial!
September 27th, 2008 at 7:14 pm
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
September 29th, 2008 at 7:40 pm
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
October 10th, 2008 at 10:39 pm
[...] Header and Footer in LaTeX – Explained [...]
October 13th, 2008 at 9:47 am
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
October 14th, 2008 at 9:47 pm
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
October 15th, 2008 at 4:03 pm
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,\cheadbut 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....\rfootto eventually “blank” each part of the header\footer positions. If not, LaTeX apply the normal fancy fields in each position, where for instance\rightmarkwould 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
\fancyheaderdocumentation – the older version of\fancyhdr.Regards
Kent
August 15th, 2011 at 3:13 pm
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.
August 18th, 2011 at 3:52 pm
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.
October 16th, 2008 at 7:18 pm
Hi Kent,
Thanks for your explanations, I appreciate your feedback.
Good luck with your work,
Tom
October 18th, 2008 at 10:19 pm
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.
October 12th, 2012 at 9:44 am
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
October 13th, 2012 at 5:20 pm
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.
October 21st, 2008 at 7:37 pm
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.
January 30th, 2009 at 10:06 am
Thanks for a great introduction. I have been looking for simple instructions how to modify the headers and footers.
March 10th, 2009 at 1:26 pm
That was exactly what I needed. Thanks
March 25th, 2009 at 12:05 pm
thanks guy.. very usefull tutorial…
April 16th, 2009 at 4:44 pm
thanks for your explanations! really helpful! cheers
May 1st, 2009 at 4:17 am
Ah, you can do dates with \today
August 30th, 2009 at 3:24 pm
Thank you very much for this very helpful guide.
September 18th, 2009 at 8:27 am
hmm
im quite a new user to latex, and would like to know how i would suppress headers, but not footers?
May 8th, 2010 at 9:04 pm
Just clear the header using
\fancyhead{}. By omitting the content, you actually suppress it. You can also set the\headrulewidthto zero.Cheers,
Tom.
January 5th, 2010 at 3:01 pm
very helpful, many thanks.
February 6th, 2010 at 9:48 am
good very good…….we got information from this which is belongs to latex………thank u……….
April 3rd, 2010 at 1:54 am
Excellent! Thanks
April 13th, 2010 at 11:15 am
Many thanks…really very useful tutorial….
April 20th, 2010 at 9:35 am
Thank you for the great tutorial!!
October 2nd, 2010 at 2:38 pm
well done! thanks!
October 10th, 2010 at 8:18 pm
[...] Headers & Footers in LaTeX – How to define headers within a LaTeX document by using Fancyhdr [...]
October 15th, 2010 at 2:54 am
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.
November 22nd, 2010 at 3:55 pm
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!
December 20th, 2010 at 2:14 pm
Hello!
Try to add the following command after your section command to omit page style for your notes page:
\thispagestyle{empty}Cheers,
Tom.
February 6th, 2011 at 9:51 am
Hello
i need to have just chapters in header , and none section.
can anybody help me? please
thanks
February 9th, 2011 at 4:05 pm
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
February 9th, 2011 at 9:41 pm
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?
February 16th, 2011 at 2:51 am
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.
February 16th, 2011 at 7:33 am
It is a mysterious problem. I upgraded for Miktex 2.9 and it worked fine finally.
February 18th, 2011 at 6:11 am
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)
February 18th, 2011 at 8:01 am
Hi!
I suggest you use either of the following:
in your preamble, or
\documentclass[openany]{book}Either should work, but it’s always good to have a backup
.
Cheers, Tom.
February 20th, 2011 at 3:35 pm
thank you tom!! it works perfectly. Do you why it happens?
cheers, gda
May 23rd, 2011 at 6:04 pm
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?
May 28th, 2011 at 8:44 am
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
\hrulein your custom class to define whatever header/footer you like to have.Let me know if you have more specific questions.
Thanks, Tom.
June 20th, 2011 at 10:50 am
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.)
June 28th, 2011 at 2:13 am
Raja, please provide a minimal example to illustrate the problem. Thanks, Tom.
July 2nd, 2011 at 7:44 am
Hi Tom,
I moved to doublepage. I used \raggedbottom to avoid extra spaces.
June 25th, 2011 at 4:30 pm
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
June 28th, 2011 at 3:15 am
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.
July 5th, 2011 at 6:19 am
Thank you
August 6th, 2011 at 7:25 pm
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
August 18th, 2011 at 5:28 pm
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}August 19th, 2011 at 8:10 am
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 !
August 19th, 2011 at 8:27 am
Hi Benoit, thanks for posting this solution. I corrected the things you mentioned and it works fine now. Thanks again, Tom.
November 18th, 2011 at 6:03 pm
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?
November 20th, 2011 at 5:12 am
Hi,
Have a look at Michael Shell’s site. It shows how to add footers to an
IEEEtrandocument.Cheers, Tom.
December 5th, 2011 at 10:02 pm
I want to write my text in every page without line. Help me please…
Thank you.
December 6th, 2011 at 6:20 am
Hi Susanna,
Just set the width of the line to zero:
\renewcommand{\headrulewidth}{0pt} \renewcommand{\footrulewidth}{0pt}Best, Tom
February 6th, 2012 at 1:57 pm
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
February 7th, 2012 at 3:13 am
Hi Kyle,
I suppose you are using
maketitle. It interferes and changes thepagestyleafter you set it toempty. First I thought you could use:... \maketitle \thispagestyle{empty} ...However, since you need a footer, you could redefine the
plainpage 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.
February 7th, 2012 at 11:43 am
thanks for your help Tom
cheers,
Kyle
February 6th, 2012 at 2:44 pm
Hi,
I want to add footer in the first page. How can I do???
Thankyou
February 7th, 2012 at 2:44 am
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}February 7th, 2012 at 4:04 am
Dear Tom
Thank you so much.
^_____________^
March 14th, 2012 at 2:53 pm
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?
March 15th, 2012 at 6:14 am
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
March 15th, 2012 at 10:03 am
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
March 15th, 2012 at 7:09 pm
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} }March 16th, 2012 at 8:53 am
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 usefancyand change it according to your needs (see my previous answer).Best, Tom.
March 16th, 2012 at 9:51 pm
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
March 18th, 2012 at 4:26 pm
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.
March 27th, 2012 at 8:04 am
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
March 28th, 2012 at 3:34 am
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.
June 27th, 2012 at 1:18 pm
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.
June 27th, 2012 at 3:06 pm
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.
June 28th, 2012 at 7:25 am
Thanks for posting your solution, appreciate it. Best, Tom.
October 4th, 2012 at 4:08 pm
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.
October 6th, 2012 at 9:54 am
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}November 6th, 2012 at 6:19 pm
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.
November 9th, 2012 at 7:42 am
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
abstractfrom its intended use.Cheers, Tom.
November 5th, 2012 at 11:29 am
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?
November 9th, 2012 at 8:01 am
Hi!
You could redefine \chaptermark as follows:
\usepackage{fancyhdr} \pagestyle{fancy} \renewcommand{\chaptermark}[1]{% \markboth{\chaptername \ \thechapter\ -- #1}{}}See the fancyhdr documentation for more details.
HTH, Tom.
November 12th, 2012 at 12:18 pm
Thank you Tom.. you are a life saver
keep up the good work. Cheers.
November 14th, 2012 at 11:39 pm
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
November 20th, 2012 at 3:28 am
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.
November 20th, 2012 at 10:14 am
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
November 20th, 2012 at 10:30 am
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}November 20th, 2012 at 10:55 am
great job!!! worked like a magic!!
thank you ever so much!
November 21st, 2012 at 12:53 am
You are very welcome. Tom.
November 16th, 2012 at 5:12 pm
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
November 20th, 2012 at 3:11 am
Hi Aida,
Thanks for your comment. To increase the space between header and text, use the variable
headseprather thanheadheight. See the figure on wikibooks site about page layout for all variable names.rightmarkis correct, but you are redefiningsectionmark. 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}November 20th, 2012 at 3:15 pm
Great! Thank you very, very much
Best regards, Aida
November 21st, 2012 at 12:53 am
Great, I’m glad I could help! Best, Tom.
November 20th, 2012 at 6:21 pm
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
November 20th, 2012 at 7:32 pm
It’s ok, it was due to me trying to position my entire header in the centre of the allocated space.
November 21st, 2012 at 12:54 am
Thanks for following up. Cheers, Tom.
November 27th, 2012 at 12:21 pm
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…
December 8th, 2012 at 5:35 am
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.
November 28th, 2012 at 6:01 pm
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?
December 3rd, 2012 at 3:20 pm
Hi! Please provide a minimal working example for me to see what you did. Thanks, Tom.
December 18th, 2012 at 11:57 am
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
December 21st, 2012 at 4:07 pm
Hi,
I assume you are talking about the page number which is in the center on page one and then moves to the side. The answers here to this question should give you a good idea on how to change the page style on page 1.
HTH, Tom.