Headers on titlepage using LaTeX

  • LaTeX
  • Thread starter TimFys
  • Start date
  • #1
3
0

Main Question or Discussion Point

Hi,

I have struggled for a while trying to get headers on the title page in LaTeX. I have headers on all other pages, but it seems like the \maketitle command disables the header on the first page (the titlepage). Does anyone know how to prevent this?
 

Answers and Replies

  • #2
AlephZero
Science Advisor
Homework Helper
6,994
291
Probably the easiest way is redefine the titlepage environment which is called by \maketitle.

You can find the original titlepage evironment code in the files article.cls, book.cls, etc (depending what format your dociment is in).

In your input file, after the \documentclass and \usepackage lines and before \begin{document}, do this:

Code:
\makeatletter
% copy and edit the original code - this is from article.cls, the others may be slightly different.
\if@compatibility
\renewenvironment{titlepage} % changed from "newenvironment"
    {%
      \if@twocolumn
        \@restonecoltrue\onecolumn
      \else
        \@restonecolfalse\newpage
      \fi
      \thispagestyle{headings}% Changed from "empty"
      \setcounter{page}\z@
    }%
    {\if@restonecol\twocolumn \else \newpage \fi
    }
\else
\renewenvironment{titlepage} % changed from "newenvironment"
    {%
      \if@twocolumn
        \@restonecoltrue\onecolumn
      \else
        \@restonecolfalse\newpage
      \fi
      \thispagestyle{headings}% changed from "empty"
      \setcounter{page}\@ne
    }%
    {\if@restonecol\twocolumn \else \newpage \fi
     \if@twoside\else
        \setcounter{page}\@ne
     \fi
    }
\fi
% End of copied code
\makeatother
\makeatletter is a magic incantation to give you access to internal low-level LaTeX macros, which contain "@" characters in their names.
\makeatother switches you back into "normal user mode" where the LaTeX internals are hidden.
 
Last edited:
  • #3
2
0
Hi,
that looks like a need trick. It does not work for me though. My class is article. Therefore I just copy pasted your link and added it to my code right after the packages before \begin{document}.
Does it matter which page style I use. Now its on fancyhdr.
After \begin{document}, I added
\lhead{\textit{leftheader}}
\rhead{} %empty
\title{article title}
\author{article author}
\maketitle
Should it work like this?
Thanks!
%
 
  • #4
AlephZero
Science Advisor
Homework Helper
6,994
291
Oops! My solution only worked for
\documentclass[titlepage]{article}
and if you are using the fancyhdr package, you need to change
Code:
\thispagestyle{headings}% changed from "empty"
to
Code:
\thispagestyle{fancy}% changed from "empty"
This version works for articles without a title page. Note, I added
Code:
\pagestyle{fancy}
after
Code:
\begin{document}
Code:
\documentclass{article}
\usepackage{fancyhdr}

\makeatletter
% Copied from article.cls
\renewcommand\maketitle{\par
  \begingroup
    \renewcommand\thefootnote{\@fnsymbol\c@footnote}%
    \def\@makefnmark{\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
    \long\def\@makefntext##1{\parindent 1em\noindent
            \hb@xt@1.8em{%
                \hss\@textsuperscript{\normalfont\@thefnmark}}##1}%
    \if@twocolumn
      \ifnum \col@number=\@ne
        \@maketitle
      \else
        \twocolumn[\@maketitle]%
      \fi
    \else
      \newpage
      \global\@topnum\z@   % Prevents figures from going at top of page.
      \@maketitle
    \fi
    \thispagestyle{fancy}\@thanks % was {empty}
  \endgroup
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}
% end of copy
\makeatother

\begin{document}
\pagestyle{fancy}
\lhead{\textit{leftheader}}
\rhead{} %empty
\title{article title}
\author{article author}
\maketitle
The article starts here
\newpage
check the headings work on page 2
\end{document}
It works for me - see the attached screen shot
 

Attachments

  • #5
2
0
That's really cool. Thank you so much!
 
  • #6
AlephZero
Science Advisor
Homework Helper
6,994
291
If you don't want to do anything complicated with the page headers, this one-line hack may be all you need. It completely disables the command that makes a once-only change to the headers on the current page, so the code in "article" that tries to switch off the headers on page one doesn't succeed.

Code:
\documentclass{article}
\usepackage{fancyhdr}

\renewcommand{\thispagestyle}[1]{} % do nothing

\begin{document}
\pagestyle{fancy}
\lhead{\textit{leftheader}}
\rhead{} %empty
\title{article title}
\author{article author}
\maketitle
The article starts here
\end{document}
 

Related Threads on Headers on titlepage using LaTeX

Replies
3
Views
2K
Replies
1
Views
2K
  • Last Post
Replies
10
Views
3K
  • Last Post
Replies
3
Views
888
  • Last Post
Replies
5
Views
4K
Replies
11
Views
11K
Replies
1
Views
2K
  • Last Post
Replies
15
Views
5K
  • Last Post
Replies
3
Views
1K
  • Last Post
Replies
1
Views
3K
Top