Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Actually I am using the fancyhdr package, and trying to put the current part name in the right header.

I know that \rightmark and \leftmark are used to represent the current section and chapter heading respectively, but I can not find anything similar to represent the part name.

share|improve this question

5 Answers 5

up vote 8 down vote accepted

That would depend on what type of "part" you are refering to, \chaptername, \sectionname, \thepage, \thesection, \thechapter, etc... See this link for details.

EDIT: In light of your comment, this thread seems to be discussing a solution (note: there is a typo, it must be \renewcommand{\part}..., i.e. a backslash must be added):

For using the parts, you can do the following:

\let\Oldpart\part
\newcommand{\parttitle}{}
\renewcommand{part}[1]{\Oldpart{#1}\renewcommand{\parttitle}{#1}}

and then use \parttitle in the header.

Another alternative is to use the titlesec package which provides commands like \partmark that you can use.

share|improve this answer
    
I am refering to \part - en.wikibooks.org/wiki/LaTeX/… –  umar Mar 14 '11 at 14:16
    
thank you very much - the solution from the thread works! –  umar Mar 14 '11 at 14:44
7  
Note that this redefinition doesn't support the optional argument of \part. –  Martin Scharrer Mar 14 '11 at 15:48
1  
I just installed titlesec for this. However \partmark doesn't do anything for me. I checked their documentation and cannot find the phrase \partmark. –  oldmankit May 1 '13 at 0:35

In the KOMA-classes \part executes a \partmark command which you could use to set either \rightmark or \leftmark to the part title.

But as \part always generates a new page and you probably need the header only on the next page you can also do something simple like this:

\newcommand\partcontent{}
...

\part{Blub}
\renewcommand\partcontent{Blub}

and then use \partcontent in the header.

share|improve this answer
    
+1 for \partmark, which is not mentioned in the KOMA-script manual. –  lockstep Mar 14 '11 at 14:36

Putting the part title into the header is not common, therefore there are no default macros for this.

You could redefine the \part macro to save its argument to e.g. a \parttitle macro which then can be used in the custom defined headers:

\newcommand*\parttitle{}
\let\origpart\part
\renewcommand*{\part}[2][]{%
   \ifx\\#1\\% optional argument not present?
      \origpart{#2}%
      \renewcommand*\parttitle{#2}%
   \else
      \origpart[#1]{#2}%
      \renewcommand*\parttitle{#1}%
   \fi
}
share|improve this answer

You could use \markboth{left headmark}{right headmark}% to put the title into the header. Some classes provide a \partmark command for it, which you could redefine for calling \markboth inside.

Standard classes don't provide \partmark. For example, book.cls even calls \markboth{}{} to remove the header entries when \part is called. You could redefine \part or hook somehow into it.

I would choose an extended class such as those of KOMA-Script instead of reinventing the wheel every time a new feature is required.

Deferring \markboth to the following page could be solved using the afterpage package:

\afterpage{\markboth{}{part title}}
share|improve this answer

I couldn't find a macro that saves the part's title, so I used the etoolbox package to patch the internals within the \part command to do that. Then you just take that save macro and put it wherever.

\documentclass{report}
\title{part name in right mark}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage{etoolbox}

\makeatletter
% patch \@part[#1]{#2} and \@spart (see the class file) to save the part name
\pretocmd{\@part}{\gdef\parttitle{#1}}{}{}
\pretocmd{\@spart}{\gdef\parttitle{#1}}{}{}
\makeatother

\pagestyle{fancy}
\renewcommand{\rightmark}{\parttitle}


\begin{document}


\maketitle
\tableofcontents

\part{First part}

\chapter{first chapter}

\lipsum\lipsum\lipsum

\chapter{second chapter}

\lipsum\lipsum\lipsum

\part{Second part}

\chapter{third chapter}

\lipsum\lipsum\lipsum

\chapter{fourth chapter}

\lipsum\lipsum\lipsum

\end{document}
share|improve this answer
    
a more elegant solution... the marked answer was causing a few problems in another document –  umar May 15 '11 at 11:48
    
@umar: It is perfectly admissible to "un-accept" an answer and accept another one instead. –  lockstep Dec 4 '11 at 20:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.