Headers on titlepage using LaTeX

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

Discussion Overview

The discussion revolves around the challenge of adding headers to the title page in LaTeX documents, particularly when using the \maketitle command. Participants explore various methods to achieve this, focusing on the article document class and the use of the fancyhdr package.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant notes that the \maketitle command disables the header on the title page and seeks a solution.
  • Another participant suggests redefining the titlepage environment to include headers, providing a code snippet for modification.
  • A different participant reports that the provided solution does not work for them, mentioning their use of the fancyhdr package and questioning the impact of the page style.
  • One participant clarifies that their solution only works when using the titlepage option with the article class and provides an alternative code snippet that incorporates the fancyhdr package.
  • Another participant expresses appreciation for the shared solution.
  • One participant proposes a simpler one-line hack to disable the command that removes headers on the title page, suggesting it as an easier alternative.

Areas of Agreement / Disagreement

Participants present multiple competing views and solutions for adding headers to the title page, with no consensus on a single method being universally effective.

Contextual Notes

Some solutions depend on specific document class options and the use of particular packages, which may limit their applicability to different setups.

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,412
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
4K
  • · Replies 12 ·
Replies
12
Views
4K
  • · 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