3

Okay so I am writing a report where in the header, my teacher is requiring that I put both the page number and my last name in the upper-left hand corner of each page (excluding the title page). Now I have managed to put the page number in the upper-left hand corner using

\pagestyle{myheadings}

but this doesn't solve my issue of putting my last name right next to the page number. Help?

10

The documentation of the fancyhdr package will be extremely helpful to you. Essentially, you need to do the following:

\documentclass{article}
\usepackage{fancyhdr}
    \fancyfoot{}
    \lhead{Yourname, \thepage}
    \pagestyle{fancy}
\usepackage{lipsum}
\begin{document}
\lipsum
\end{document}

Since your title page is the only one that's different, you can just say \thispagestyle{empty} on your title page, and you'll get no headers or footers.

If fancyhdr's default of a header rule bothers you, put in \renewcommand{\headrulewidth}{0pt} to kill it.

  • Sorry one more thing to add. So I added the fancyhdr to my doc, but there is an underlining below that takes up the top of the page. How do I get rid of this? – joshj2398 May 26 '15 at 3:15
  • With \fancyfoot{} nothing goes in those brackets. unless you want to put something there. If you don't want anything there, they should be left blank. If you want something in your footer, you put it in there. \thepage is a macro. You don't put in the page number, no, LaTeX will print whatever the correct page number is. The function of \lipsum is provided by the lipsum package and it prints the text of lorem ipsum (google it if you're unfamiliar). You can see that our original poster includes the appropriate pagestyle in their example. \pagestyle{fancy} – Au101 May 26 '15 at 3:15
  • The rule in the header is also in the fancyhdr documentation. Something like \setlength{\headrulewidth}{0pt} should do it, but confirm that in the manual. I'm away from my desktop at the moment. texdoc fancyhdr. – dgoodmaniii May 26 '15 at 3:20
  • That didn't work. when I added that command, it just added "0.4pt0pt" to my text for some weird reason. – joshj2398 May 26 '15 at 3:26
  • 1
    The macro \headrulewidth needs to be reset via a \renewcommand instruction. E.g., \renewcommand{\headrulewidth}{0pt}. – Mico May 26 '15 at 3:33
2

Another possibility is using scrlayer-scrpage. I guess that your document is oneside:

\usepackage{scrlayer-scrpage}
\clearpairofpagestyles
\addtokomafont{pagehead}{\upshape}
\ihead*{Yourname, \pagemark}

With the article class you have to use \maketitle\thispagestyle{empty} to get an empty title page.

Oneside article:

\documentclass{article}
\usepackage{scrlayer-scrpage}
\clearpairofpagestyles
\addtokomafont{pagehead}{\upshape}
\ihead*{Yourname, \pagemark}

\author{Yourname}
\title{Title}

\usepackage{blindtext}% dummy text
\begin{document}
\maketitle\thispagestyle{empty}
\blinddocument
\blinddocument
\end{document}

Oneside report:

\documentclass{report}
\usepackage{scrlayer-scrpage}
\clearpairofpagestyles
\addtokomafont{pagehead}{\upshape}
\ihead*{Yourname, \pagemark}

\author{Yourname}
\title{Title}

\usepackage{blindtext}% dummy text
\begin{document}
\maketitle
\blinddocument
\blinddocument
\end{document}

Note, that the header appears also an chapter pages. To remove the header from the chapter pages simple use \ihead{...} instead \ihead*{...}.


If your document is twoside an the header should be an the left hand side on both the even and the odd pages than you have to use

\usepackage{scrlayer-scrpage}
\clearpairofpagestyles
\addtokomafont{pagehead}{\upshape}
\lehead*{Yourname, \pagemark}
\lohead*{Yourname, \pagemark}

Twoside report:

\documentclass[twoside]{report}
\usepackage{scrlayer-scrpage}
\clearpairofpagestyles
\addtokomafont{pagehead}{\upshape}
\lehead*{Yourname, \pagemark}
\lohead*{Yourname, \pagemark}

\author{Yourname}
\title{Title}

\usepackage{blindtext}% dummy text
\begin{document}
\maketitle
\blinddocument
\blinddocument
\end{document}

Your Answer

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

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