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.

I am attempting to place the document's title on the left side of a header and the chapter's name on the right side of the header. However, I am unable to find how to use the title variable specified in by \title{my title} in the header. Additionally, whenever I use \chaptermark the right section of the header appears blank on all pages.

How do I insert a document's title and the chapter's name into a header?

My tex file contents are pasted below:

\documentclass{report}
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\begin{document}

\rhead{\bfseries \chaptermark}
\lfoot{\thepage\ of \pageref{LastPage}}
\rfoot{My Company}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}

% redefine headers and footers for chapters
\fancypagestyle{plain}{%
 \fancyhf{}
 \rhead{\bfseries \chaptermark}
 \lfoot{\thepage\ of \pageref{LastPage}}
 \rfoot{My Company}
 \renewcommand{\headrulewidth}{0.4pt}
 \renewcommand{\footrulewidth}{0.4pt}
}

\title{My Document Title}
\author{Ryan Taylor}
\date{\today}
\maketitle
\tableofcontents
\chapter{Version Control}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sapien metus, tempus sit amet feugiat id, feugiat in diam. Integer ut nunc eget orci hendrerit ullamcorper nec at enim.

\chapter{Introduction}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sapien metus, tempus sit amet feugiat id, feugiat in diam. Integer ut nunc eget orci hendrerit ullamcorper nec at enim.
share|improve this question

1 Answer 1

up vote 3 down vote accepted

For the title:

\let\oldtitle\title
\renewcommand{\title}[1]{\oldtitle{#1}\def\titletext{#1}}
\lhead{\titletext}

For the chapter name, use \leftmark not \chaptermark (which is the command which is used by \chapter in order to set up the marks).

share|improve this answer
2  
Right. Though you might need to redefine chaptermark if you want to change how \leftmark works, e.g., make it so it doesn't include the chapter number or put it in all caps, e.g.: \renewcommand{\chaptermark}[1]{\markboth{\textbf{#1}}{}} \rhead{\leftmark} should give you the chapter name in bold with nothing else as \leftmark. –  frabjous Aug 25 '10 at 4:20
1  
Slightly off-topic, but I think this is a design bug in LaTeX. The standard classes' \maketitle contain \global\let\@title\@empty. There's very little reason to do this. There should be nothing wrong with \lhead{\@title}. I guess that after \title{foo}, one could write \expandafter\lhead\expandafter{\@title}, but that should probably be unnecessary. –  TH. Aug 25 '10 at 11:07
    
Thanks for the help. This works exactly as I wanted and I learned a a lot more about overriding commands and creating variables to boot. –  Ryan Taylor Aug 25 '10 at 12:12
    
Thank you, TH, your comment was EXACTLY what I wanted to know. –  Denilson Sá Aug 27 '10 at 22:41
    
@TH.: I believe \@title, etc., are cleared for historical reasons due to memory limitations back when LaTeX was first written in the 80s. –  Will Robertson Sep 23 '10 at 11:25

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.