[Tex/LaTex] How to use pagenumbering in the document

header-footerpage-numberingtable of contents

In my Master thesis, I would like to have the title page without any page number and an acknowledgments section and the table of contents with roman numbers. The rest of the document should be numbered arabic.

I have tried this, to have roman numbers for the Table of contents and normal numbers for the rest.

\documentclass[12pt,ngerman,openany]{report}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{cite}
\usepackage[a4paper]{geometry}
%\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
%\usepackage{ngerman}{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{float}
\selectlanguage{ngerman}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{url}
\usepackage{epstopdf}
\usepackage{scrhack}
\usepackage{listings}
\usepackage{caption}
\titleformat{\chapter}{\rmfamily\huge}{\textbf\thechapter.}{25pt}{\huge\textbf}
\defcaptionname{ngerman}{\lstlistingname}{Code}
\defcaptionname{ngerman}{\lstlistlistingname
}{Codeverzeichnis}

\lstloadlanguages{R} 
\lstset{% general command to set parameter(s) 
  basicstyle=\sffamily\footnotesize, % print whole listing small 
  keywordstyle=\sffamily\footnotesize\bfseries, % ubold black keywords 
  identifierstyle=, % nothing happens 
  commentstyle=\sffamily\footnotesize\slshape, % green comments 
  stringstyle=\sffamily\footnotesize, % typewriter type for strings 
  showstringspaces=false, % no special string spaces 
  numbers=left, 
  numberstyle=\sffamily\footnotesize, 
  stepnumber=1, 
  numbersep=10pt, 
  showspaces=false, 
  showtabs=false, 
  frame=lines, 
  morecomment=[l]{\%}, 
  float=htbp, 
  numberbychapter=true 
} 

\begin{document}
\let\cleardoublepage\clearpage


\pagenumbering{roman} 
\tableofcontents 
\clearpage 
\vspace*{75mm}
\chapter{Einleitung}
\section{Motivation}
bla bla bla
\section{Ziel}

bla bla
\chapter{Stand der Technik zur Mustererkennung}
\section{Die Zeitreihen}
bla bla
\subsection{Beschreibung}
bla bla
\subsection{Erklärung}

bla bla

\subsection{Vorhersage}
bla bla
\subsection{Kontrolle}
bla bla
\section{Feature Extraktion}
bla bla
\subsection{Autokorrelation}
\subsection{Was ist Autokorrelation?}
bla bla


\subsection{Autokorrelation und Zeitreihen}
bla bla

\subsubsection{Zeitreihe-Diagramm}

bla bla
\subsubsection{Lagged Streudiagramm}
bla bla

\subsubsection{Autocorrelation-Function (Korrelogramm)}
bla bla
\subsection{Spektralanalyse}
\subsection{Was ist Spektral-Analyse}
bla bla
\end{document}

Best Answer

\pagenumbering{style} changes the appearance of \thepage to match style and resets the page count to one (\@one). This change in the page number can be noticed with the shipout of the next page, which is in fact the page currently typeset.

Now, where to put the \pagenumbering command? A good idea is to place this immediately after a chapter command.

\documentclass{report}
\usepackage{blindtext}
\usepackage{showframe}
\begin{document}
\chapter{standard counting}
\blindtext[8]
\chapter{roman counting}
\pagenumbering{roman}
\blindtext[5]
\end{document}

All works perfectly fine. But now, what does happen if we take the same example, but use twoside? Package showframe helps us determine what left and right pages are. The marginparcolumn is always on the outer side.

\documentclass[twoside]{report}
\usepackage{blindtext}
\usepackage{showframe}
\begin{document}
\chapter{standard counting}
\blindtext[8]
\chapter{roman counting}
\pagenumbering{roman}
\blindtext[5]
\end{document}

As you may notice, two odd (right) pages follow each other, making it very hard to bind the final output. The chapter command issues a clearpage by default (cleardoublepage if option openright is used) which isn't enough in this case. But now, we can't issue the needed cleardoublepage after chapter has been issued. That would make no sense. But we can use cleardoublepage before chapter. If the pagenumbering command is issued before or after chapter doesn't make a difference now.

\documentclass[twoside]{report}
\usepackage{blindtext}
\usepackage{showframe}
\begin{document}
\chapter{standard counting}
\blindtext[8]
\cleardoublepage
\chapter{roman counting}
\pagenumbering{roman}
\blindtext[5]
\end{document}

Is there anything to say about titlepages?

Yep, the standard classes and the KOMA-classes differ in their behaviour.

\documentclass{report}
%\documentclass{scrreprt}
\usepackage{showframe}
\title{How does pagenumbering work?}
\author{\TeX.SX}
\begin{document}
\maketitle
\chapter*{What pagenumber do we get here?}
pagenumber: \thepage
\end{document}

As we can see by running this example with the standard report, the titlepage is not counted, the next page has page number 1.
The KOMA-class differs, the titlepage is counted, the next page gets number 2.

Changing the example to twoside both classes number the pages in the same way. There is a simple reason for that, odd pages are always right-hand pages.

Why are all examples using report and its KOMA counterpart?
The behaviour described is defined in the titlepage environment. article doesn't use a titlepage per default, books use titlepage, but are printed twoside by default.

The same are working for memoir as well. But it should be mentioned, that the title of a standard memoir class uses the pagestyle title which is an alias for plain. So the titlepage gets (visibally) numbered by default.

What about pagenumbering in articles and books? If you want to change the pagenumbering in an article, you should consider switching to a class with chapters. book provides the frontmatter, mainmatter and backmatter mechanism, taking care of pagenumbering and some other stuff.

Related Question