3

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.

5

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}
  • Thank you, is there any way of doing the above without having [twoside] after document class? – nonameswereavailable Aug 25 '13 at 3:06
  • 1
    @nonameswereavailable twoside allows to alternate the information on even and odd pages. I updated my answer providing a possible solution without this option (the last example code in my answer). Just out of curiosity, why don't you want to use this option? – Gonzalo Medina Aug 25 '13 at 3:36
  • The [twoside] shift the body slightly to the left or right, depending on whether you're on an even or odd page. I need the body of my text to be uniform, while having the alternating headers. I thought it would be easier modifying the header as opposed to introducing new constraints for the body. I very much appreciate your help. – nonameswereavailable Aug 25 '13 at 3:51
  • 2
    @nonameswereavailable you can keep the twoside option and use the centering option for geometry, as in \documentclass[twoside]{article}\usepackage[centering]{geometry}. – Gonzalo Medina Aug 25 '13 at 4:18
  • @GonzaloMedina, is it possible to avoid requiring the \newcommand\Author{First Author---Second Author} command and address the string in \author{name}? I am hoping that it is possible to pull the name directly without the extra needed step. I have a style file and would like to include the author name in the fancyhr usage. I tried \author{name1} \newcommand\Author{\author} in the .tex file but it does not compile – Vass Mar 9 '18 at 5:46

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.