Dear All,
I want to have a fixed header (TEXT) in every page including the first one (with elsarticle). With the following I can't get this header in the first page; how can I fix this problem? Your comment is greatly appreciated.
\documentclass{elsarticle}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}
\fancyhead[LE,LO]{TEXT}
amiruw
Page Layout ⇒ Header in every page with elsarticle
Header in every page with elsarticle
Last edited by amiruw1 on Wed Feb 16, 2011 3:35 pm, edited 1 time in total.
NEW: TikZ book now 40% off at Amazon.com for a short time.

Header in every page with elsarticle
You should always provide a complete minimal working example -- as is, we are simply left to guess why the first page is different from the rest, though in this case, it is not too hard to make an educated guess.
Most likely, the plain page style is being applied to the first page, rather than the fancy page style. So you either need to use \thispagestyle{fancy} for the first page, after whatever command is making it plain style (probably \maketitle), or else you need to redefine plain style so it works just like fancy. So after all of the above, do:
See sec. 7 of the fancyhdr documentation.
Most likely, the plain page style is being applied to the first page, rather than the fancy page style. So you either need to use \thispagestyle{fancy} for the first page, after whatever command is making it plain style (probably \maketitle), or else you need to redefine plain style so it works just like fancy. So after all of the above, do:
Code: Select all
Code, edit and compile here:
\fancypagestyle{plain}{%\fancyhead{}\fancyhead[LE,LO]{TEXT}\renewcommand{\headrulewidth}{0.4pt}% or whatever}
Header in every page with elsarticle
Thanks for your reply. Unfortunately it didn't work out. I also used the following alternative approach but the problem is still the same; that is, the header is missed in the first page:
My first page is as follows:
Code: Select all
Code, edit and compile here:
\usepackage{fancyhdr}\fancyhead{TEXT}\usepackage{lastpage}\pagestyle{fancy}\lhead{TEXT} \chead{}\rhead{\scriptsize \thepage}\lfoot{}\cfoot{}\rfoot{}
Code: Select all
Code, edit and compile here:
\documentclass{elsarticle}%\usepackage{natbib}%\usepackage {graphicx}\usepackage{threeparttable}\usepackage{amsmath}\usepackage{amsfonts}\usepackage{amssymb}\usepackage[nodots]{numcompress}\usepackage{lineno}%\usepackage{fancyhdr}\fancyhead{TEXT}\usepackage{lastpage}\pagestyle{fancy}\lhead{TEXT} \chead{}\rhead{\scriptsize \thepage}\lfoot{}\cfoot{}\rfoot{}%\renewcommand{\headrulewidth}{0.0pt}%\usepackage{colortbl}\usepackage{float}\usepackage{subfigure}\usepackage{longtable}%\usepackage{url}\usepackage[hyphens]{url}\usepackage[dvips=true,bookmarks=true,breaklinks=true]{hyperref}\usepackage{breakurl}%\newcommand{\eg}{\text{e.g.,}~}\newcommand{\ie}{\text{i.e.,}~}\newcommand{\etc}{\text{etc.}~}%\renewcommand\floatpagefraction{.9}\renewcommand\topfraction{.9}\renewcommand\bottomfraction{.9}\renewcommand\textfraction{.1}\renewcommand{\dbltopfraction}{0.9}\setcounter{totalnumber}{4}
Header in every page with elsarticle
An excellent example of why minimal working example is so important. (Unfortunately, you still didn't provide one, since you didn't post a complete document, since yours cuts of before \end{document}, and you also use two packages that are not available as part of standard LaTeX installation -- numcompress and lineo. I had to comment these out to test your code. See the Post on Avoidable Mistakes.) But they don't have anything to do with your problem (or so I'd guess), so they shouldn't have been in your sample anyway.
However, both of my suggestions work perfectly. One is to put \thispagestyle{fancy} right after whatever command is changing the pagestyle for the first page. In this case, that is the frontmatter environment. So if you put \thispagestyle{fancy} right after \end{frontmatter}, it works just fine. (Or does in my test.)
The other option is to change the pagestyle used on that page. I assumed it was plain, since that is what it would be for a normal document class. However, for the elsarticle document class, the pagestyle there is called "pprintTitle"; this is specific to that documentclass, and hence, without a full document of your code, it was impossible to get it right. However, it seems to work fine if you put:
in the preamble.
In the future, please keep in mind how important minimal examples are, and read the page linked above about how to create one. It really helps make it easier for people to provide help!
However, both of my suggestions work perfectly. One is to put \thispagestyle{fancy} right after whatever command is changing the pagestyle for the first page. In this case, that is the frontmatter environment. So if you put \thispagestyle{fancy} right after \end{frontmatter}, it works just fine. (Or does in my test.)
The other option is to change the pagestyle used on that page. I assumed it was plain, since that is what it would be for a normal document class. However, for the elsarticle document class, the pagestyle there is called "pprintTitle"; this is specific to that documentclass, and hence, without a full document of your code, it was impossible to get it right. However, it seems to work fine if you put:
Code: Select all
Code, edit and compile here:
\fancypagestyle{pprintTitle}{%\lhead{TEXT} \chead{}\rhead{\scriptsize \thepage}\lfoot{}\cfoot{}\rfoot{}\renewcommand{\headrulewidth}{0.0pt}}
In the future, please keep in mind how important minimal examples are, and read the page linked above about how to create one. It really helps make it easier for people to provide help!
Re: Header in every page with elsarticle
Thanks very much; I appreciate your time and help.
As you suggested, putting \thispagestyle{fancy} right after \end{frontmatter} solved the problem.
amiruw1
As you suggested, putting \thispagestyle{fancy} right after \end{frontmatter} solved the problem.
amiruw1
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Header in every page with elsarticle
Then please mark the topic (not the last post) accordingly.amiruw1 wrote:[…] As you suggested, putting \thispagestyle{fancy} right after \end{frontmatter} solved the problem. […]
Best regards and welcome to the board
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10