[Tex/LaTex] Title and author in header without fancyhdr

header-footer

I'm trying to have the author names and title appear on alternating pages, respectively, in the center of the header. In addition I would like to have even numbered pages on the left in the header and odd numbered pages on the right in the header – Starting from page 2. I would like to avoid using the package fancyhdr as I do no want any line separating the header from the body.

Best Answer

You have several possibilities:

1) Using titleps

\documentclass[twoside]{article}
\usepackage{titleps}
\usepackage{lipsum}

\newpagestyle{mystyle}{
\sethead[\thepage][\Author][]{}{\Title}{\thepage}
}
\pagestyle{mystyle}

\author{First Author \and Second Author}
\title{The title}

\makeatletter
\newcommand\Author{First Author---Second Author}
\let\Title\@title
\makeatother

\begin{document}

\maketitle
\lipsum[1-20]

\end{document}

2) Using fancyhdr (with \renewcommand\headrulewidth{0pt} there will be no rule in the header):

\documentclass[twoside]{article}
\usepackage{fancyhdr}
\usepackage{lipsum}

\fancyhf{}
\fancyhead[LE,RO]{\thepage}
\fancyhead[CE]{\Author}
\fancyhead[CO]{\Title}
\renewcommand\headrulewidth{0pt}
\pagestyle{fancy}

\author{First Author \and Second Author}
\title{The title}

\makeatletter
\newcommand\Author{First Author---Second Author}
\let\Title\@title
\makeatother

\begin{document}

\maketitle
\lipsum[1-20]

\end{document}

3) Without packages:

\documentclass[twoside]{article}
\usepackage{lipsum}

\author{First Author \and Second Author}
\title{The title}

\makeatletter
\newcommand\Author{First Author---Second Author}
\let\Title\@title
\def\ps@mystyle{%
      \let\@oddfoot\@empty\let\@evenfoot\@empty
      \def\@evenhead{\makebox[0pt][l]{\thepage}\hfill\Author\hfill}%
      \def\@oddhead{\hfill\Title\hfill\makebox[0pt][l]{\thepage}}%
      \let\@mkboth\markboth}
\makeatother
\pagestyle{mystyle}

\begin{document}

\maketitle
\lipsum[1-20]

\end{document}

Addendum:

In comments, it has been requested a solution without using the twoside class option:

\documentclass{article}
\usepackage{lipsum}

\author{First Author \and Second Author}
\title{The title}

\makeatletter
\newcommand\Author{First Author---Second Author}
\let\Title\@title
\def\ps@mystyle{%
      \let\@oddfoot\@empty\let\@evenfoot\@empty
      \def\@oddhead{%
       \ifodd\value{page}\relax
          \hfill\Title\hfill\makebox[0pt][l]{\thepage}%
      \else
          \makebox[0pt][l]{\thepage}\hfill\Author\hfill%
      \fi%
      }%
      \let\@mkboth\markboth}
\makeatother
\pagestyle{mystyle}

\begin{document}

\maketitle
\lipsum[1-20]

\end{document}