6

I have been racking my brains over how in bloody hell can you have a different header for the title (or first) page of a document.

I am not asking here how I can not have a header by clearing the page style for this page using \thispagestyle{plain} or something of the sort but how can I have a different header just for the very first page.

Please help as I have a deadline to meet.

So far, I have not been able to find anything useful on TeX.SE.

Here is some of my code to give you some idea of what I want to achieve:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage[margin=2.5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{amsfonts}
\usepackage{fancyhdr}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{csc}
\pagestyle{fancy}
\fancyhead[L]{**Left Header for all pages**}\fancyhead[R]{**Right Header for all pages**}
\lhead{**Left Header for just the first page**}
\rhead{**Right Header for just the first page**}
\title{Problem Set 1}
        \author{MyBloodyName}
\date{January 31, 2017}
\begin{document}
    \maketitle
    \newpage
    Easier?
\end{document}
1
  • 1
    We have a wuestion: hiw to customize my titlepage, please have a look at it. Also please have a look at the segment title creation of the latex wikibook.
    – Johannes_B
    Feb 1, 2017 at 11:25

3 Answers 3

11

You can use \fancypagestyle to define a new page style and \thispagestyle to use it for only the current page:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage[margin=2.5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{amsfonts}
\usepackage{fancyhdr}
\usepackage{hyperref}
\usepackage{graphicx}
%\usepackage{csc}% unknown package
\pagestyle{fancy}
\fancyhead[L]{**Left Header for all pages**}
\fancyhead[R]{**Right Header for all pages**}
\fancypagestyle{firstpage}{%
  \lhead{**Left Header for just the first page**}
  \rhead{**Right Header for just the first page**}
}
\title{Problem Set 1}
\author{MyBloodyName}
\date{January 31, 2017}
\begin{document}
    \maketitle
    \thispagestyle{firstpage}
    \newpage
    Easier?
\end{document}

Nevertheless, this can only be done, if you do not really use a titlepage but a title head on the first page. If you want a title page, you have to patch the page style into, e.g., the titlepage environment:

\documentclass[12pt,titlepage]{article}
\usepackage{amsmath}
\usepackage[margin=2.5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{amsfonts}
\usepackage{fancyhdr}
\usepackage{hyperref}
\usepackage{graphicx}
%\usepackage{csc}% unknown package
\pagestyle{fancy}
\fancyhead[L]{**Left Header for all pages**}
\fancyhead[R]{**Right Header for all pages**}
\fancypagestyle{firstpage}{%
  \fancyhf{}% clear default for head and foot
  \lhead{**Left Header for just the first page**}
  \rhead{**Right Header for just the first page**}
}
\usepackage{xpatch}
\xapptocmd{\titlepage}{\thispagestyle{firstpage}}{}{}

\title{Problem Set 1}
\author{MyBloodyName}
\date{January 31, 2017}
\begin{document}
    \maketitle
    Easier?
\end{document}
2
  • Thanks so much! I'd been at it for hours! For the unknown package csc, I have a csc.sty file for it. Would you also happen to know how to install the package to TeX Live? I can't find the directory for the packages.
    – HKT
    Feb 1, 2017 at 22:31
  • @HKT Installation of packages is another question and should not be a comment to this answer. Feb 2, 2017 at 10:21
2

\maketitle is pretty limited, it is a hard coded title including the head and foot (empty).

You can design your own titlepage from scratch. A few explanations can be found in How to custmize my titlepage and the LaTeX wikibook. Have a look at the bottom of the wikibook page, you can find some links with example title pages there.

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage[margin=2.5cm,headheight=15pt]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{amsfonts}
\usepackage{fancyhdr}
\usepackage{graphicx}
%\usepackage{csc}
\pagestyle{fancy}
\fancyhead[L]{**Left Header for all pages**}
\fancyhead[R]{**Right Header for all pages**}
\title{Problem Set 1}
\author{MyBloodyName}
\date{January 31, 2017}
\usepackage{hyperref}
\begin{document}
\begin{titlepage}
    \setlength{\parindent}{0pt}
    \vspace*{-3.8\baselineskip}
    Wombat \hfill Capybara
    \begin{center}
    \vspace{.1\textheight}
    {\huge\bfseries Probem Set 1 \par}
    \bigbreak
    {\bfseries\large Mr. Walter Wombat\par}
    \bigbreak
    January 31, 2017
\end{center}
\end{titlepage}
Easier?
\end{document}
0

If you're using the exam class, you can add a different header and footer by using the following.

\pagestyle{headandfoot}
\header{left}{middle}{right}
\footer{left}{middle}{right}
\firstpageheader{left}{middle}{right}
\firstpagefooter{left}{middle}{right}

Reference: https://www.ctan.org/pkg/exam?lang=en

2
  • Which package/class provides \firstpageheader/\firstpagefooter?
    – Werner
    Jan 18, 2020 at 2:52
  • Thanks, for asking. I was using the exam class and I've update my solution above to include a link to the class.
    – 0p3r4t0r
    Jan 19, 2020 at 12:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .