2

Hello I am using a fancyhdr package and I want that the page number appear in the right side of the heading for odd pages and in the left side of the heading for the left side. I alredy used the command \fancyhead[RO,LE]{\thepage} but it does not work. Here is my code:

\documentclass[twoside,12pt]{elsarticle}%
\usepackage{amscd}
\usepackage{thmdefs}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{fancyhdr}
\usepackage[margin=0.5in]{geometry}
\setcounter{MaxMatrixCols}{30}
\providecommand{\U}[1]{\protect\rule{.1in}{.1in}}
\numberwithin{equation}{section}
\newenvironment{proof}[1][Proof]{\noindent\textbf{#1.} }{\ \rule{0.5em}{0.5em}}
\newtheorem{condition}[theorem]{Condition}

\journal{}

\pagestyle{fancy}
\newcommand\shorttitle{------------------------------}
\newcommand\authors{--------------------------}
\fancyhf{}
\renewcommand\headrulewidth{0pt}
\fancyhead[C]{%
\ifodd\value{page}
  \small\scshape\authors
\else
  \small\scshape\shorttitle
\fi }

\fancyhead[RO,LE]{\thepage}

\begin{document}
HELLO!!!!
\end{document}

I think it is something related to the class elsarticle, because if I change to another the class everything works well.

2
  • 3
    If you're submitting an article to an Elsevier journal, they will override such settings before it is published. If you're not, why not use another document class? Apr 19 '13 at 19:12
  • Welcome to TeX.sx!
    – mafp
    Apr 19 '13 at 19:19
5

The elsarticle class doesn't use twoside, so there's no way for fancyhdr to distinguish between the two cases.

Use a trick similar to the one you're using for alternating title and author: if the page number is even, push the page number all the way to the left with \hfill.

On the other hand, if you're submitting the paper to Elsevier, such changes shouldn't be made.

\documentclass[twoside,12pt]{elsarticle}%
\usepackage[margin=0.5in,headheight=14.5pt,includehead]{geometry}
\usepackage{fancyhdr}

\journal{}

\pagestyle{fancy}
\newcommand\shorttitle{------------------------------}
\newcommand\authors{--------------------------}
\fancyhf{}
\renewcommand\headrulewidth{0pt}
\fancyhead[C]{%
\ifodd\value{page}
  \small\scshape\authors
\else
  \small\scshape\shorttitle
\fi }

\fancyhead[R]{\thepage\ifodd\value{page}\else\hfill\fi}

\usepackage{lipsum}

\begin{document}
\lipsum[1-20]
\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.