First impressions matter—especially in technical, academic, or corporate documents. A bespoke title page sets the tone, while consistent headers and footers guide the reader. Standard LaTeX classes offer only rudimentary title and page style commands, which can leave your document looking generic. By combining the titling
package for precise control over your title page, fancyhdr
for flexible headers and footers, and background
for watermarks or full-page images, you can achieve a truly professional look. This deep-dive tutorial will walk you through ten practical patterns, from minimal setup to advanced PDF metadata, each complete with ready-to-use code snippets and detailed explanations.
This guide assumes you've created basic LaTeX documents before. We’ll cover:
%------------------------------------------------------
% Preamble: Load core packages for titles & pages
\documentclass[12pt,a4paper]{article}
% Title page control
\usepackage{titling}
% Header/footer customization
\usepackage{fancyhdr}
% Backgrounds and watermarks
\usepackage{background}
% Conditional logic
\usepackage{ifthen,xifthen}
% Current file and datetime
\usepackage{currfile}
\usepackage{datetime}
% KOMA-Script page styles
\usepackage{scrlayer-scrpage}
%------------------------------------------------------
Explanation: Begin by selecting your document class (article, report, book, or KOMA-Script equivalent). Load titling
prior to \maketitle
, fancyhdr
for head/foot definitions, and background
for watermarking. Additional utilities like ifthen
, currfile
, and scrlayer-scrpage
round out the toolkit.
% Title formatting hooks
\pretitle{\begin{center}\LARGE\bfseries\fontfamily{phv}\selectfont}
\posttitle{\par\end{center}\vskip 1.5em}
\preauthor{\begin{center}\large}
\postauthor{\end{center}\vskip 1em}
\predate{\begin{center}\small\itshape}
\postdate{\par\end{center}\vskip 2em}
% Document metadata
\title{An In-Depth Study of Thermodynamic Processes}
\author{Dr. Jane E. Researcher \\ Department of Physics, XYZ University}
\date{\today}
\begin{document}
\maketitle
Explanation: The \pre…
and \post…
commands wrap title elements in arbitrary formatting. Here we center the title, switch to a sans-serif font, add vertical space, and italicize the date. No need for a separate titlepage
environment unless multiple pages are required.
fancyhdr
% Clear existing header/footer
\fancyhf{}
% Define left, center, right
\lhead{\includegraphics[height=10pt]{logo-small.png} \enspace \textit{Thermo Analysis}}
\chead{}
\rhead{\thepage/\pageref{LastPage}}
% Footer definitions
\lfoot{Prepared by: \authorname}
\cfoot{\today}
\rfoot{Confidential}
% Rule thickness customization
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0.5pt}
% Apply globally
\pagestyle{fancy}
Explanation: Use \fancyhf{}
to reset defaults, then populate each region. Insert logos via \includegraphics
. Combine page numbers with \pageref{LastPage}
(requires lastpage
package) to show “page X of Y”.
% Define a named pagestyle for chapter starts
\fancypagestyle{chapterstart}{
\fancyhf{}
\lhead{\bfseries Chapter \thechapter: \leftmark}
\rhead{\thepage}
\renewcommand{\headrulewidth}{1pt}
}
% Hook into report/book chapters
\makeatletter
\preto\chapter{\thispagestyle{chapterstart}}
\makeatother
% Section-level override
\makeatletter
\preto\section{\thispagestyle{plain}}
\makeatother
Explanation: Named page styles let you switch layouts automatically at logical boundaries. Here, chapter-opening pages get a bold heading; other sections revert to the plain style (no headers).
\backgroundsetup{
position=current page.center,
angle=0,
scale=1.2,
opacity=0.05,
contents={\includegraphics[width=\paperwidth,height=\paperheight]{watermark.pdf}}
}
% Apply to every page or single pages
% Option A: global
%\BgThispage
% Option B: per-page
\BgThispage % add background on title
\maketitle
% Later: on appendix cover
\clearpage
\BgThispage
\section*{Appendix A: Supplemental Data}
Explanation: The background
package allows you to place images behind text. Adjust opacity
for subtlety. Use \BgThispage
to target specific pages such as covers or annexes.
% Boolean switch for draft mode
\newboolean{draft}
\setboolean{draft}{true} % set to false for final
\ifthenelse{\boolean{draft}}{
% Draft header
\fancyhead[L]{\textcolor{red}{\bfseries DRAFT}}
\fancyhead[R]{\today}
\backgroundsetup{contents={\textsf{\Huge DRAFT}}}
\BgThispage
}{%
% Final header overrides
\fancyhead[L]{\includegraphics[height=10pt]{logo-final.png}}
\fancyhead[R]{\thepage}
}
Explanation: Toggling a boolean at compile-time lets you switch watermarks, header logos, or footer text. This pattern is invaluable for managing review copies vs. publication-ready PDFs.
% Centralized metadata commands
\newcommand{\authorname}{Dr.\ Jane E.\ Researcher}
\newcommand{\docversion}{v3.1.0}
% Build info macro
\newcommand{\buildinfo}{
File: \currfilename\ (\currfilebase) \\
Version: \docversion \\
Compiled: \today\ at \currenttime
}
% Place in footer center
\cfoot{\small\ttfamily\buildinfo}
Explanation: By defining macros for author and version, you only update in one place. The currfile
and datetime
packages automatically populate file names and compile timestamps for traceability.
\usepackage[pdfencoding=auto]{hyperref}
% Set PDF metadata
\hypersetup{
pdftitle={Thermodynamic Processes},
pdfauthor={Dr. Jane E. Researcher},
pdfsubject={Physics Report},
pdfkeywords={thermodynamics, LaTeX, titling, fancyhdr},
pdfpagemode=UseOutlines
}
% Automatically generates bookmarks at sections/chapters
Explanation: The hyperref
package not only handles hyperlinks, but also embeds rich PDF metadata and generates a navigable bookmark tree in PDF viewers. Use pdfpagemode=UseOutlines
to open the bookmark pane by default.
scrlayer-scrpage
for Advanced Layouts
% Use KOMA-Script document class for built-in flexibility
\documentclass[headinclude,footinclude,BCOR=5mm]{scrartcl}
% Load scrlayer-scrpage instead of fancyhdr
\usepackage{scrlayer-scrpage}
\clearpairofpagestyles
% Define header/footer
\ihead{\leftmark}
\chead{}
\ohead{\pagemark}
\ifoot{Dept. of Physics}
\cfoot{\docversion}
\ofoot{\today}
% Enable rule
\setheadsepline{.4pt}
\setfootsepline{.4pt}
% Apply
\pagestyle{scrheadings}
Explanation: KOMA-Script’s scrlayer-scrpage
offers a more integrated approach to page styling with built-in options for binding corrections (BCOR
) and automatic header/footer inclusion. Commands like \ihead
and \pagemark
simplify placement.
\documentclass[12pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{geometry}
\geometry{margin=2.5cm}
% Core packages
\usepackage{titling,fancyhdr,background,ifthen,xifthen,currfile,datetime}
\usepackage[pdfencoding=auto]{hyperref}
\usepackage{lastpage}
% Metadata
\newcommand{\authorname}{Dr.\ Jane E.\ Researcher}
\newcommand{\docversion}{v3.1.0}
\newboolean{draft}
\setboolean{draft}{false}
% Title hooks
\pretitle{\begin{center}\huge\bfseries\sffamily}
\posttitle{\end{center}\vskip 2em}
\preauthor{\begin{center}\Large}
\postauthor{\end{center}\vskip 1em}
\predate{\begin{center}\small\itshape}
\postdate{\end{center}\vskip 1.5em}
% Hypersetup
\hypersetup{
pdftitle={Thermodynamic Processes},
pdfauthor={\authorname},
pdfsubject={Physics Report},
pdfkeywords={thermodynamics, LaTeX, headers},
pdfpagemode=UseOutlines
}
% Fancyhdr configuration (global)
\fancyhf{}
\lhead{\ifthenelse{\boolean{draft}}{\textsf{\bfseries DRAFT}}{\authorname}}
\rhead{\thepage\ of \pageref{LastPage}}
\cfoot{\small\ttfamily Build: \currfilename\ | \docversion}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0.5pt}
\pagestyle{fancy}
% Background for draft
\ifthenelse{\boolean{draft}}{
\backgroundsetup{contents={\textsf{\huge DRAFT}},opacity=0.15}
\AtBeginDocument{\BgThispage}
}{}
\begin{document}
\maketitle
% ... document content ...
\end{document}
Explanation: This comprehensive preamble brings together all techniques: geometry for margins, titling for the title page, fancyhdr for headers/footers, background for optional watermarks, hyperref for PDF metadata, and conditional logic for drafts. It’s a solid template for any technical report or thesis.