Text FormattingCenter Page Numbers only on first Page of new Section

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
isharp2
Posts: 23
Joined: Fri Feb 11, 2011 2:06 am

Center Page Numbers only on first Page of new Section

Post by isharp2 »

hi,

I would like to center page numbers on the first page of a new section, and then for every page thereafter, put the page number in the upper-right hand corner.

I saw a similar post on here for a thesis, but the resolution used a class file that I could not understand, and I am already needing to customize my latex document, since this is also a thesis.


thanks.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

5gon12eder
Posts: 126
Joined: Sun Feb 13, 2011 8:36 pm

Center Page Numbers only on first Page of new Section

Post by 5gon12eder »

You would do this by selecting the appropriate pagestyle. For the following, I'll assume, that you want to use plain for pages on which a new section starts and headings for other pages. Feel free to define arbitrary page styles, conveniently by using a package like fancyhdr.

All you have to do is to declare headings as the default page style by putting

Code: Select all

\pagestyle{headings}
in your preamble and then switch the style for the section-opening-pages via

Code: Select all

\thispagestyle{plain}
at the appropriate places.

To get your stuff working reliably, you should take care of page breaks. The simplest thing would be to add a \clearpage before each section. Since you want a different page style, you'll probably feel comfortably with each section beginning on a new page.

Using the \gpreto macro from the etoolbox package, you can set this up in your preamble and needn't insert the code at each \section by hand.

See the following code for a working example:

Code: Select all

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[latin]{babel} % just loaded to get the
\usepackage{blindtext}    % ``lorem ipsum'' text...
\usepackage{etoolbox}

\makeatletter
\gpreto\section{\clearpage\thispagestyle{plain}}
\makeatother

\pagestyle{headings}

\begin{document}
  \section{This is a Section}
  \blindtext
  \subsection{This is a Subsection}
  \blindtext[10]
  \subsection{This is Another Subsection}
  \blindtext[15]
  \section{This is a Section}
  \blindtext
  \subsection{This is a Subsection}
  \blindtext[10]
  \subsection{This is Another Subsection}
  \blindtext[15]
  \section{This is a Section}
  \blindtext
  \subsection{This is a Subsection}
  \blindtext[10]
  \subsection{This is Another Subsection}
  \blindtext[15]
\end{document}
Alternatively, you may consider using the report document class and make your \sections \chapters.

Best
I'm using pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian).
Post Reply