Page Layoutsection with page number

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

section with page number

Post by jaybz »

I think I need to just manually set the title and page number of each page because it's too complex. I just want this with no horiz. lines and alternating for left and right pages.

Code: Select all

        2.3 primes    pagenum

Some text text text text text
text text text text text text
...
It might continue sequentially for 10 pages then jump several sections:

Code: Select all

    4.1 factorials    pagenum

Some text text text text text
text text text text text text
...

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

section with page number

Post by localghost »

jaybz wrote:[…] I just want this with no horiz. lines and alternating for left and right pages. […]
Does this mean that you have a two-sided document? Because in your example you provided code for a one-sided document. Would be good if you could clarify that once and for all. With fancyhdr for a two-sided document you could this (not tested).

Code: Select all

\fancyhf{}                                                % clear all headers and footer
\fancyhead[LE,RO]{\nouppercase{\leftmark}\qquad\thepage}  % subsection title and page number in header
\pagestyle{fancy}
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

section with page number

Post by jaybz »

Ok this almost works. I notice that when going from page 1 to page 2 the "text body" is being shifted down a line for some reason.

Code: Select all

\documentclass[a4paper,11pt,Final]{article}
\usepackage[english]{babel}
\usepackage{fancyhdr}
\usepackage{lipsum}
\begin{document}
\thispagestyle{fancy}
\setcounter{page}{124}
\renewcommand{\headrulewidth}{0pt}
\rhead{\Large{2.3 POLYNOMIALS \hspace{7mm}}{\thepage}}
\cfoot{}
\rfoot{}
\lfoot{}
\lipsum[1]
\newpage
\fancyhf{} % clear all header and footer fields
\thispagestyle{fancy}
\setcounter{page}{189}
\renewcommand{\headrulewidth}{0pt}
\lhead{\Large{{\thepage}\hspace{7mm}}4.3 FACTORIALS}
\lipsum[1]
\end{document}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

section with page number

Post by localghost »

You should listen to the compiler and what it is telling you in the log file.

Code: Select all

Package Fancyhdr Warning: \headheight is too small (12.0pt): 
 Make it at least 18.0pt.
 We now make it that large for the rest of the document.
 This may cause the page layout to be inconsistent, however.
I think this is a clear message. And especially the last line.

Do you seriously want to determine the header for each section by hand? That is not the way to write with LaTeX and what I would call good practice. For this purpose usually the \leftmark command is inserted into the header.
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

section with page number

Post by jaybz »

Yes it must be done by hand because it will change. The first 10 pages might be:

Code: Select all

124  2.3 POLYNOMIALS
And the next 8 pages:

Code: Select all

149  4.2 FACTORIALS
Then the next 11 pages:

Code: Select all

225  5.1 FUNCTION GRAPHING
And in each section it alternates between the odd and even pages.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

section with page number

Post by localghost »

jaybz wrote:Yes it must be done by hand because it will change. […]
But this can be done automatically as described earlier.
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

Re: section with page number

Post by jaybz »

I'm just going to do it manually. It's just too is too time consuming and complicated to figure out how to use hancyhdr. I just don't get it. :?
Post Reply