# Center footer wrt paper, not margins

Im writing a thesis. The requirements are 1.5in left margin and 1 in right. In addition, the page number must be in the right hand corner except on the first page of every chapter where it must be centered in the footer. Im using the fancyhdr package which centers the footer with respect to the text and not the page. Id like to center the footer so the page number is centered on the page.

\documentclass[12pt]{report}

\usepackage{geometry}
\geometry{a4paper, left=1.5in, right=1in,top=1in, bottom=1in}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\footrulewidth}{0pt}
\fancyfoot{}

\begin{document}

\chapter{Intro}

first page

\pagebreak

second page

\end{document}

• Welcome to TeX.SX! This would look weird, in my point of view – user31729 Jul 23 '15 at 22:16
• Thank you. That may be so but those are the requirements. – Mary Jul 23 '15 at 22:18
• if i understand the requirements page number go to text center not page center – touhami Jul 23 '15 at 22:23
• In addition, the first page must be in the right hand corner except on the first page of every chapter: what does this mean? The first page goes to the right-hand corner of what? Itself? – Bernard Jul 23 '15 at 22:24
• Edited that typo. Also, I submitted it today and was told it must be page center(Which seems to defeat the purpose of the unequal margins). – Mary Jul 23 '15 at 22:26

That a-way? I replaced fancyhdr with titleps from the titlesec bundle, defined a weird page style, and redefined the plain style.

\documentclass[12pt]{report}
\usepackage{titlesec}
\usepackage{geometry}
\geometry{a4paper, left=1.5in, right=1in,top=1in, bottom=1in, showframe, nomarginpar}
\setcounter{page}{900}

\usepackage{titleps}
\newpagestyle{weird}{%
}%
\renewpagestyle{plain}{%
\setfoot{}{\makebox[0pt]{\thepage}\hskip0.5in}{}
}%
\pagestyle{weird}

\setcounter{page}{900}

\begin{document}

\chapter{Intro}
%
first page

\pagebreak %

second page

\end{document}


• @cfr: Not any more. See my updated answer. – Bernard Jul 23 '15 at 23:37
• @Werner: It doesn't affect any more (I think): I (re)defined page styles with titleps. – Bernard Jul 23 '15 at 23:38
• (+1) This seems saner to me. No need to make more trouble for the OP than the thesis office already intend to! ;) – cfr Jul 23 '15 at 23:55

Here is another suggestion using scrlayer. Then you can redeclare plain as a layer pagestyle with only one layer containing the centred page number.

\documentclass[12pt]{report}
\usepackage{geometry}
\geometry{a4paper, margin=1in,
left=2.5in,% enlarged in this example
showframe}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\footrulewidth}{0pt}
\fancyhf{}

\usepackage{scrlayer}
\DeclareNewLayer[
foreground,
foot,
hoffset=0pt,
width=\paperwidth,
contents={\parbox{\layerwidth}{\centering\thepage}}
]{PageMarkCentredToPage}
\RedeclarePageStyleByLayers{plain}{PageMarkCentredToPage}

\begin{document}
\chapter{Intro}
first page
\clearpage
second page
\end{document}


Note that I have also enlarged the left margin to show the effect.

Of course you can also replace fancyhdr by scrlayer-scrpage that is based on scrlayer

\documentclass[12pt]{report}
\usepackage{geometry}
\geometry{a4paper, margin=1in,
left=3.5in,% enlarged in this example
showframe}

\usepackage{scrlayer-scrpage}
\clearpairofpagestyles

\DeclareNewLayer[
foreground,
foot,
hoffset=0pt,
width=\paperwidth,
contents={\parbox{\layerwidth}{\centering\thepage}}
]{PageMarkCentredToPage}
\RedeclarePageStyleByLayers{plain}{PageMarkCentredToPage}

\begin{document}
\chapter{Intro}
first page
\clearpage
second page
\end{document}


Does this work?

\documentclass[12pt]{report}

\usepackage{geometry}
\geometry{a4paper, left=1.5in, right=1in,top=1in, bottom=1in, showframe}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\footrulewidth}{0pt}
\fancyfoot{}
\fancypagestyle{plain}{%
\fancyhf{}%
\renewcommand{\footrulewidth}{0pt}%
\fancyhf[cf]{\thepage\makebox[.25in]{ }}}

\begin{document}

\chapter{Intro}

first page

\pagebreak

second page

\end{document}


• Its fixed the centering issue, but the page number for every page is now in the footer – Mary Jul 23 '15 at 22:51
• @Mary Well, that's what you said you wanted: ... except on the first page of every chapter where it must be centered in the footer. What did I miss? – cfr Jul 23 '15 at 22:52
• @Mary Wait. For every page? That is not true in the MWE I posted so it is hard to know what would cause that. – cfr Jul 23 '15 at 22:53
• Sorry for the typos...Not enough sleep. Anyways, my table of contents section must be number with roman numerals. So I added the following before that section : \pagenumbering{roman} \setcounter{page}{2} \pagestyle{plain} After i removed that it worked. – Mary Jul 23 '15 at 22:59
• @Mary OK. Good - mystery solved. plain will be used automatically for the first pages of chapters (including the ToC) and fancy for the others. Whether the numbers are Arabic or Roman is independent of that, so just switching the numbering as you've now done should be fine. – cfr Jul 23 '15 at 23:04

The following should work after the second compilation (first time around), regardless of the margin dimensions. The principle is to set two markers (using eso-pic) on the first page to capture the x and y coordinates needed on the page (stored using zref's savepos module. Subsequently, the page number for "special pages" (in this case, the plain page style pages, associated with the first page of every \chapter) will be moved into position.

\documentclass[twoside]{report}

\usepackage{geometry,eso-pic,zref-savepos}
\geometry{
margin=1in,
left=1.5in,
right=3in,% Just for this example
showframe}

\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\footrulewidth}{0pt}
\fancypagestyle{plain}{%
\renewcommand{\footrulewidth}{0pt}%
\fancyfoot[C]{\specialthepage}}

% Place reference markers on first page
\AtBeginDocument{%
\AddToShipoutPictureBG*{% Just in the background of first page only
\AtPageCenter{\zsaveposx{page-center}}% At page centre, capture x-pos
\AtTextLowerLeft{\zsaveposy{page-footer}}% At text lower left, capture y-pos
}%
}%

% \specialthepage is issued only on \pagestyle{plain}, which is first page of \chapter
\newcommand{\specialthepage}{%
\AddToShipoutPictureFG*{% Just in foreground of current page only
\hspace*{\zposx{page-center}sp}% Move to horizontal center
\raisebox{\dimexpr\zposy{page-footer}sp-\footskip}{\makebox[0pt]{\thepage}}% Raise to text block lower-left level - footer skip
}%
}
\begin{document}

\chapter{Intro}

first page

\clearpage

second page


In the above example, I've used twoside mode and a bizarre right margin just for show.

• My solution requires only one compilation ;o) – Bernard Jul 23 '15 at 23:40
• @Bernard: Mine requires two, and thereafter only one. So 1 more in total. I know, it's a mess to require that from users. – Werner Jul 23 '15 at 23:41
• My solution seems so simple that I have doubts concerning its general validity… – Bernard Jul 23 '15 at 23:44