Is there a way to write a header with left- and right-aligned text without using the package Fancyhdr?
1 Answer
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}
\@oddhead
etc manually. But why don't you want use fancyhdr?titleps
, a companion to thetitlesec
package.\makeatletter \newcommand\@oddhead{left\hfill right}
is all you need but why not usefancyhdr
which does the same, but with a nicer interface?scrlayer-scrpage
does a nice job as well. It is part of the KOMA-bundle.graphicx
(andgraphics
)?