Page LayoutFancyhdr: Calling the part and chapter names

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
sultan1919
Posts: 4
Joined: Fri Apr 29, 2011 7:23 pm

Fancyhdr: Calling the part and chapter names

Post by sultan1919 »

Hey everyone. This is the first time I've ever posted to any sort of forum, so please excuse me if I make any novice mistakes.

I'm using fancyhdr and would like to make the following appear in italics at the top left of each page:

"Part <part #>, Ch. <ch #>: <part short name> / <chapter short name>" - e.g.:

"Part I, Ch. 1: Introduction / Literature Review"

Right now I'm doing this via, e.g.:

"\fancyhead[L]{\textit{Part \thepart, Ch. \thechapter: <manually entering in part name> / <manually entering in chapter name>}"

and just re-entering this with the new info every time there's a chapter or part change.

I was wondering if there's a way to call the part (short) name and chapter (short) name so that I don't have to manually re-enter at each change (similar to the way "\thepart" and "\thechapter" call the part and chapter numbers respectively automatically)?

My guess was that preamble etc. info wasn't necessary for this sort of question but if you need that, please let me know.

Any direction would be much appreciated - thanks!

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

Stefan Kottwitz
Site Admin
Posts: 10330
Joined: Mon Mar 10, 2008 9:44 pm

Fancyhdr: Calling the part and chapter names

Post by Stefan Kottwitz »

Hi,

welcome to the board!

You could use \leftmark and \rightmark. These are used by LaTeX to store such short titles. They can be modified using commands such as \chaptermark and \partmark. You can read about this in the fancyhdr manual: 9 The scoop on LaTeX’s marks.

Stefan
LaTeX.org admin
sultan1919
Posts: 4
Joined: Fri Apr 29, 2011 7:23 pm

Re: Fancyhdr: Calling the part and chapter names

Post by sultan1919 »

Thanks for the reply. I actually had looked at that documentation before, but I couldn't tell if there was a simple command to literally just call the short name of a chapter/part - do you know of one? From what I understand, \chaptermark{} is used to define a very short title for the current chapter - though I could have that wrong...?

Basically I've used \chapter[xxx]{yyy} to define each given chapter, and I'm hoping to pull the <xxx> for the header but didn't know if there's a command (like "\thechapter" for the chapter number) that would just spit out the <xxx>.

Thanks again.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10330
Joined: Mon Mar 10, 2008 9:44 pm

Fancyhdr: Calling the part and chapter names

Post by Stefan Kottwitz »

\chaptermark and \sectionmark are defined by classes or packages. It can work like this:
  1. You write \chapter[xxx]{yyy}
  2. \chapter automatically calls \chaptermark with xxx and uses yyy for the heading in the body text
  3. \chaptermark applies some formatting to xxx and puts it into \leftmark
  4. fancyhdr puts \leftmark into the header as you specified it
So you could just use \leftmark, or redefine \chaptermark as you desire.

Stefan
LaTeX.org admin
Post Reply