Generalprefix section/subsection numbering with a letter

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
fetchinson
Posts: 5
Joined: Fri Jul 13, 2007 12:11 pm

prefix section/subsection numbering with a letter

Post by fetchinson »

Hi all,

I am required to have a special numbering of sections and subsections in my document. There needs to be a letter B in front of every section/subsection number, but otherwise the numbering scheme should be the usual one. So it should go like this: B1, B1.1, B1.2, B1.3, B2, B2.1, B2.2, etc, etc, and the letter B should appear also on the table of contents.

How would I go about this?

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

pumpkinegan
Posts: 91
Joined: Thu May 03, 2007 10:29 pm

prefix section/subsection numbering with a letter

Post by pumpkinegan »

Renew the section counter (the subsection does not need to be changed):
\renewcommand{\thesection}{B\arabic{section}}
fetchinson
Posts: 5
Joined: Fri Jul 13, 2007 12:11 pm

Re: prefix section/subsection numbering with a letter

Post by fetchinson »

So easy? Thanks a lot!

It works great, but this solution gave me another problem, please bear with me. At the bottom of every page I need to have the text "Part B 5 of 20" for instance if the page number is 5 and the total number of pages is 20. I achieved this by

\renewcommand{\thepage}{Part B \hspace{11cm} Page \arabic{page} of 20}

After using your solution for the section number prefixing the "Part B 5 of 20" stuff appears in the table of contents for each section, which is not what I need. So the table of contents should use normal page numbering but the bottom of each page should have this "Part B 5 of 20" stuff.

Any ideas?
fetchinson
Posts: 5
Joined: Fri Jul 13, 2007 12:11 pm

Re: prefix section/subsection numbering with a letter

Post by fetchinson »

Actually, I found a solution in case someone else is also interested:

\pagestyle{fancy}
\cfoot[\thepage]{Part B \hfill Page \thepage \hspace{0.05cm} of 20}

The only thing missing is that the total number of pages is hardwired to 20, I guess it's possible to have that filled in automatically. If not that's also okay, I can just add it when the document is ready and I know the total number.
fetchinson
Posts: 5
Joined: Fri Jul 13, 2007 12:11 pm

Re: prefix section/subsection numbering with a letter

Post by fetchinson »

This is also not very difficult it turns out:

\usepackage{lastpage}
\cfoot[\thepage]{Part B \hfill Page \thepage \hspace{0.05cm} of \pageref{LastPage}}

Isn't that great? :)
User avatar
pumpkinegan
Posts: 91
Joined: Thu May 03, 2007 10:29 pm

prefix section/subsection numbering with a letter

Post by pumpkinegan »

fetchinson wrote: \cfoot[\thepage]{Part B \hfill Page \thepage \hspace{0.05cm} of \pageref{LastPage}}
The \hspace is probably not the best thing use do after \thepage (a LaTeX command that eats up the spaces after it). To keep a space after \thepage (and other LaTeX commands) use:

Code: Select all

\cfoot[\thepage]{Part B \hfill Page \thepage\ of \pageref{LastPage}}
fetchinson
Posts: 5
Joined: Fri Jul 13, 2007 12:11 pm

Re: prefix section/subsection numbering with a letter

Post by fetchinson »

Thanks a lot, this indeed works nicely!
Post Reply