Headers on titlepage using LaTeX

  • LaTeX
  • Thread starter TimFys
  • Start date
  • Tags
    Latex
In summary, the code in "article" that tries to switch off the headers on page one doesn't succeed with this one-line hack.
  • #1
TimFys
3
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
  • #2
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
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
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,284
  • #5
That's really cool. Thank you so much!
 
  • #6
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}
 

What is LaTeX and how is it used for creating headers on titlepages?

LaTeX is a document preparation system that is widely used in the scientific community. It allows for the creation of high-quality documents, especially those with complex mathematical equations. To add headers on a titlepage using LaTeX, you can use the "fancyhdr" package, which provides a simple interface for creating headers and footers.

How do I customize the headers on my titlepage using LaTeX?

To customize the headers on your titlepage, you can use the \fancyhead and \fancyfoot commands provided by the "fancyhdr" package. These commands allow you to specify the content, position, and style of your headers and footers.

Can I have different headers on odd and even pages of my titlepage in LaTeX?

Yes, you can have different headers on odd and even pages of your titlepage using the "fancyhdr" package. You can use the \fancyhead[RO,RE]{content} command to specify the content for the right-hand side (RO) and left-hand side (RE) of the header for odd pages, and similarly for even pages.

Is it possible to have a different header on the first page of my titlepage in LaTeX?

Yes, you can have a different header on the first page of your titlepage using the "fancyhdr" package. You can use the \thispagestyle{fancy} command to apply the defined header to the first page, and then use the \pagestyle{fancy} command to apply it to the rest of the pages.

Can I include images or logos in my titlepage headers using LaTeX?

Yes, you can include images or logos in your titlepage headers using the "fancyhdr" package. You can use the \lhead{\includegraphics[width=2cm]{logo.png}} command to insert an image in the left header, and similarly for the other sides of the header. Make sure to include the "graphicx" package in your document preamble for this to work.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
882
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
697
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
512
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
1K
  • Programming and Computer Science
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
2
Replies
36
Views
808
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
Back
Top