2

I'm trying to make a header on every page with text above and below the header rule, so that it looks something like this:

                                  header text above line
--------------------------------------------------------
                                  header text below line

[body of page]

Is this possible with fancyhdr? Or is there another way to do this?

I realize this may not be aesthetically pleasing, but I'm trying to emulate another document (not made with LaTeX).

1

Try this, with fancyhdr:

\pagestyle{fancy}
\fancyhead[LE,LO]{~\\\hrulefill\\~}
\fancyhead[CE,CO]{~\\\hrulefill\\~}
\fancyhead[RE,RO]{text above\\\hrulefill\\text below}

If desired, switch left and right. You will need to play with the headheight and the line skips in the header, and related dimensions.

  • This almost works. I end up with two horizontal lines, but I can remove the default one with \renewcommand{\headrulewidth}{0pt}, and then I get the desired result. Thanks! – Eric Sep 18 '16 at 22:29
  • Right! You need to remove the default line. When I use fancyhdr, I start by zeroing or emptying everything and building up from there. – user103221 Sep 18 '16 at 23:12
0

You can set one header item using a tabular with a single paragraph column that is the width of \textwidth:

enter image description here

\documentclass{article}

\usepackage{fancyhdr,lipsum}

\pagestyle{fancy}
\fancyhf{}% Clear header/footer
\renewcommand{\headrulewidth}{0pt}% Remove header rule
\fancyhead[C]{%
  \begin{tabular}{ @{} p{\textwidth} @{} }
    \hfill Header text above line \\
    \hline
    \hfill Header text below line
  \end{tabular}}
\setlength{\headheight}{24.4pt}% Should be at least 24.4pt

\begin{document}

\lipsum

\end{document}
0

Here is a solution with titleps, a tabular environment and booktabs:

\documentclass[12pt,twoside, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{titleps}
\usepackage{array, booktabs, graphicx}
    \usepackage{lipsum}
\newpagestyle{mine}{\renewcommand\arraystretch{0.5}%
\sethead[][\begin{tabular}{@{}>{\raggedright\small\arraybackslash}p{\textwidth}@{}}header text above line\\\midrule header text below line\end{tabular}][]%
{}{\begin{tabular}{@{}>{\raggedleft\small\arraybackslash}p{\textwidth}@{}}header text above line\\\midrule header text below line\end{tabular}}{}
\setfoot{}{\thepage}{}
}
\pagestyle{mine}

\begin{document}

\lipsum

\end{document} 

enter image description here

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.