Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to have a header that looks like

<my name>            <Class>             <page number>
<Student number>

However, I can't figure out how to insert the second line. What I've attempted is:

%Page layout here
\documentclass[letterpaper]{article}
\usepackage{lastpage}           %lets me find out how many pages there are

\usepackage{fancyhdr}           %allows me to fiddle with the header and such

\pagestyle{fancyplain}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt} % remove lines as well
\setlength{\headheight}{15.2pt}
\chead{How do I get this to work?}
\rhead{\thepage\ of \pageref{LastPage}} %Add the page numbers to the to right
\lhead{Canageek\\3.14159}
%End footer

\begin{document}
Test
\end{document}

However, as you can see, this causes the essay name and page number to be on the same line as my student number, not up with my name as they should be.

I've found two related questions. The first does some stuff that I think I can avoid, since I don't want everything right-aligned, while the second seems to accomplish it by modifying the second titles, which isn't what I need.

share|improve this question
    
Have you tried adding \\ to the end of \chead and \rhead? –  Silex Oct 6 '12 at 17:06
add comment

1 Answer

up vote 7 down vote accepted

Use a tabular

%Page layout here
\documentclass[letterpaper]{article}
\usepackage{lastpage}           %lets me find out how many pages there are

\usepackage{fancyhdr}           %allows me to fiddle with the header and such

\pagestyle{fancyplain}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt} % remove lines as well
\setlength{\headheight}{24pt}
\chead{How do I get this to work?}
\rhead{\thepage\ of \pageref{LastPage}} %Add the page numbers to the to right
\lhead{\begin{tabular}[t]{@{}l@{}}Canageek\\3.14159\end{tabular}}
%End footer

\begin{document}
Test
\end{document}

A \parbox[t] would have worked the same, this spares us from guessing a length. This also spares us to add things to the other fields that don't belong there.

For the example I'll put back the rule, just to show the correctness of the spacing.

enter image description here

share|improve this answer
    
Your tabular has a bunch of @s and things that Alan's example doesn't, can you explain why? –  Canageek Oct 6 '12 at 17:13
    
@Canageek Try both. You'll see that @{} removes the small indentation. –  egreg Oct 6 '12 at 17:14
    
Now can you explain why using tabluar is more correct then just adding \\ at the end of each line? –  Canageek Oct 6 '12 at 17:20
1  
@Canageek Because you don't have to guess; in this way you're just telling TeX what to do and don't add hacks. –  egreg Oct 6 '12 at 17:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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