1

Is there a way to write a header with left- and right-aligned text without using the package Fancyhdr?

6
  • 1
    Sure, you can redefine \@oddhead etc manually. But why don't you want use fancyhdr? Commented Feb 5, 2015 at 12:17
  • 1
    You can use titleps, a companion to the titlesec package.
    – Bernard
    Commented Feb 5, 2015 at 12:35
  • 1
    \makeatletter \newcommand\@oddhead{left\hfill right} is all you need but why not use fancyhdr which does the same, but with a nicer interface? Commented Feb 5, 2015 at 12:51
  • 1
    Package scrlayer-scrpage does a nice job as well. It is part of the KOMA-bundle.
    – Johannes_B
    Commented Feb 5, 2015 at 14:45
  • 1
    There are so many packages that expand the possibilities of the kernel. Invent the wheel every single time? No, that is what packages are for. What would you do without graphicx (and graphics)?
    – Johannes_B
    Commented Feb 5, 2015 at 21:46

1 Answer 1

2

I defined some macros for easier access to the headers. You have to use the twoside option of the documentclass to actually distinguish between odd and even pages (without all pages are treated as odd).

\documentclass[twoside]{article}
% Use some ridicolouosly small paper for demonstration
\usepackage[a6paper]{geometry}

\makeatletter
\newcommand\oddhead[1]{\gdef\@oddhead{\reset@font#1}}
\newcommand\evenhead[1]{\gdef\@evenhead{\reset@font#1}}
\newcommand\oddfoot[1]{\gdef\@oddfoot{\reset@font#1}}
\newcommand\evenfoot[1]{\gdef\@evenfoot{\reset@font#1}}
\makeatother

\oddhead{\hfil Some header on odd pages\hfil}
\evenhead{\hfil Some header on even pages\hfil}
\oddfoot{\hfil Some footer on odd pages\hfil}
\evenfoot{\hfil Some footer on even pages\hfil}

\begin{document}

Odd page

\clearpage

Even page

\end{document}

enter image description here

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .