Headers on titlepage using LaTeX

  • Context: LaTeX 
  • Thread starter Thread starter TimFys
  • Start date Start date
  • Tags Tags
    Latex
Click For Summary
SUMMARY

The forum discussion addresses the issue of displaying headers on the title page in LaTeX, specifically when using the \maketitle command. Users discovered that redefining the titlepage environment is necessary to maintain headers on the title page. The solution involves using the \makeatletter and \makeatother commands to access internal LaTeX macros, and modifying the \thispagestyle command to use 'fancy' instead of 'empty'. This method is effective for documents using the article class and the fancyhdr package.

PREREQUISITES
  • Familiarity with LaTeX document classes, particularly the article class.
  • Understanding of the fancyhdr package for header and footer customization.
  • Knowledge of LaTeX commands such as \maketitle, \thispagestyle, and \makeatletter.
  • Basic experience with LaTeX document structure and environments.
NEXT STEPS
  • Explore advanced LaTeX header configurations using the fancyhdr package.
  • Learn about customizing the titlepage environment in LaTeX documents.
  • Research LaTeX document classes and their specific header behaviors.
  • Investigate other LaTeX packages that enhance document formatting and styling.
USEFUL FOR

LaTeX users, academic writers, and document designers looking to customize title pages and headers in their documents.

TimFys
Messages
2
Reaction score
0
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?
 
Physics news on Phys.org
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:
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!
%
 
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

  • screendump.png
    screendump.png
    2.2 KB · Views: 2,400
That's really cool. Thank you so much!
 
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}
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 23 ·
Replies
23
Views
3K
  • · Replies 36 ·
2
Replies
36
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K