LaTeX Headers on titlepage using LaTeX

  • Thread starter Thread starter TimFys
  • Start date Start date
  • Tags Tags
    Latex
AI Thread Summary
The discussion focuses on resolving the issue of missing headers on the title page when using LaTeX, specifically with the \maketitle command. Users share solutions involving the redefinition of the titlepage environment to enable headers on the title page. Key suggestions include modifying the \thispagestyle command to use "headings" or "fancy" instead of "empty" and ensuring proper placement of the \pagestyle command after \begin{document}. A simpler one-line hack is also proposed to disable the command that prevents headers on the first page, allowing for consistent header usage throughout the document. The conversation highlights the importance of understanding LaTeX's internal commands and the flexibility of the fancyhdr package for customizing headers.
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,382
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
Views
2K
Replies
12
Views
3K
Replies
7
Views
3K
Replies
3
Views
2K
Replies
5
Views
3K
Replies
4
Views
3K
Back
Top