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 would like have a section listed next to the page number in the upper right on odd pages like this:

Code: Select all

2.4 sometext     pagenumber    
And upper left on even pages like this.

Code: Select all

pagenumber       2.4 sometext
how can I do this?
Last edited by jaybz on Thu May 12, 2011 7:51 pm, edited 3 times in total.

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

Frits
Posts: 169
Joined: Wed Feb 02, 2011 6:02 pm

section with page number

Post by Frits »

First, you have to pick a documentclass that supports two-sided layouts. For example:

Code: Select all

\documentclass[twoside]{article}
Then, the fancyhdr package will allow you to customize the headers/footers of even and odd pages separately. For example:

Code: Select all

\usepackage{fancyhdr}
\pagestyle{fancy}

\fancyhead[LE,RO]{\leftmark}				% sectiontitle
\fancyhead[CE,CO]{\thepage}				% pagenumbering
\fancyhead[RE,LO]{}							% empty
\fancyfoot[C]{}								% empty
(Hopefully the codes are without errors, since I'm currently not able to test them)
howtoTeX.com - Your LaTeX resource site (Tips, Tricks, Templates and more!)
Follow howtoTeX on twitter
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

section with page number

Post by localghost »

Another package that manages page styles (and in addition much more) is titlesec.

Code: Select all

\documentclass[11pt,a4paper,twoside,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[includehead,nofoot,margin=3cm]{geometry}
\usepackage[pagestyles,raggedright]{titlesec}
\usepackage{blindtext}

\newpagestyle{main}{%
  \sethead[\thepage][][\thesection\quad\sectiontitle]{\thesection\quad\sectiontitle}{}{\thepage}
  \headrule
}
\pagestyle{main}

\begin{document}
  \blinddocument
\end{document}
The blindtext package is only for creating dummy text thus not part of the solution.


Best regards and welcome to the board
Thorsten
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

Re: section with page number

Post by jaybz »

Frits, can you give a minimum working example please.
localghost, I don't understand, where do I actually insert my text? Could you remove the \blinddocument and put in some text as I showed please.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

section with page number

Post by localghost »

jaybz wrote:[…] I don't understand, where do I actually insert my text? Could you remove the \blinddocument and put in some text as I showed please.
Where is the problem? Did you test my example? Just replace this command with the content you want to write (sections, subsections, …). The command only creates a whole document for demonstration purposes in order to check whether all settings are right (see package manual). This is a common practise instead of tediously inserting some text. Therefore I remarked that the package is not part of the solution.
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

section with page number

Post by jaybz »

Yes I tested it and looked at the manual and removed the \blinddocument but I still can't figure out the syntax. I'm aware of several common packages the problem is the manuals have no working examples. If I could just read and understand the manual I wouldn't have to ask here. Everybody just wants to post "Oh just use the XXX.. package" and post a link to it. The manuals are terrible especially for beginners, I don't understand them.
Where do I place my text to replace your:

Code: Select all

1 Heading on level 1 (section)                     1
With this minus the horizontal line

Code: Select all

                             2.3 polynomials       1
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

section with page number

Post by localghost »

jaybz wrote:[…] I'm aware of several common packages the problem is the manuals have no working examples. If I could just read and understand the manual I wouldn't have to ask here. Everybody just wants to post "Oh just use the XXX.. package" and post a link to it. […]
Posting questions here is OK (of course). But you can't always expect to get a full elaborated example. Especially in the case when you have not been proactive and at least presented a minimal example (like here). You should always be aware of the fact that those who try to give help just don't have the time to build complete examples on their own and instead refer to manuals which explain things best. And these manuals are still the best source for information (and always will be).
jaybz wrote:[…] The manuals are terrible especially for beginners, I don't understand them. […]
For the majority of the manuals I can't share this opinion. However, there are some exceptions. But the fact that you don't understand manuals will turn out to be a big hurdle when working with LaTeX.

Here is another complete example. I don't know if it will help since it is only a slightly modified version to the one I gave earlier. It now explicitly creates a section and subsection and uses the \blindtext command which creates a short paragraph of text. And although you don't like hear that, it is clearly explained in the manual.

Code: Select all

\documentclass[11pt,a4paper,twoside,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[includehead,nofoot,margin=3cm]{geometry}
\usepackage[pagestyles,raggedright]{titlesec}
\usepackage{blindtext}

\newpagestyle{main}{%
  \sethead[\thepage][][\thesection\quad\sectiontitle]{\thesection\quad\sectiontitle}{}{\thepage}
}
\pagestyle{main}

\begin{document}
  \section{Your section title here}
    \blindtext

  \subsection{Your subsection title here}
    \blindtext
\end{document}
I'm still the opinion that you can find out the basic usage of the involved packages by reading their manuals.
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

section with page number

Post by jaybz »

Ok this is almost what I need but how can I change the page number and still keep it at the top right?

Code: Select all

\documentclass[11pt]{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
\headheight 15pt
\rhead{\thepage}
\chead{\hspace*{70mm}  2.3 Polynomials}
%\lhead{}
%\rfoot{}
%\cfoot{}
%\lfoot{}
\renewcommand{\headrulewidth}{0pt}
\begin{document}
This is some text here.
\end{document}
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

Re: section with page number

Post by jaybz »

This is the last part of what I need for my document could someone please help me with this?
Thanks
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

section with page number

Post by localghost »

I'm still not sure what you are after. But since you have chosen fancyhdr for your headers, the solutions from another topic might help [1]. The running title is close to the page number, which is shifted into the margin.

[1] View topic: Page numbers "beside" headers
Post Reply