6

MWE is below:

\documentclass{report}
\usepackage{fancyhdr}
%\newcommand{\currentchapter}{}
%\let\oldchapter\chapter
%\renewcommand{\oldchapter}[1]{\oldchapter{#1}\renewcommand{\currentchapter}{#1}}

%\renewcommand{\sectionmark}[1]{\markright{#1}}

%\renewcommand{\chaptermark}[1]{\markboth{\textbf{#1}}{}} \rhead{\leftmark} 

\fancypagestyle{newstyle}{
\fancyhf{}
\fancyhead[LE]{{\nouppercase{\leftmark}}}
\fancyhead[RO]{{\nouppercase{\rightmark}}}
}
\begin{document}

I want to have

'Introduction'

in place of

'Chapter 1. Introduction'

as the header for my pages inside the document. So, is there a command set I can use instead of \leftmark to get the desired results? Or can I redefine \leftmark in any way to get the desired results?

2
  • Would using \chapter*{Introduction} solve your problem?
    – Ricardo
    May 13 '13 at 17:23
  • Can you please add more information for the example? What's the purpose of \currentchapter?
    – egreg
    May 13 '13 at 17:32
6

The problem with your current (re)definition of \chapter is that it removes the ability to use \chapter*{<title>} or \chapter[<ToC entry>]{<title>}. While this may not be a problem in your case, a general approach/solution would be preferred.

titleps provides built-in access to the titles of sectional units via \chaptertitle, \sectiontitle, etc.:

enter image description here

\documentclass[twoside]{report}
\usepackage{titleps,lipsum}% http://ctan.org/pkg/{titleps,lipsum}
\newpagestyle{newstyle}{
  \setheadrule{.4pt}% Header rule
  \sethead[\chaptertitle]% even left
    []% even centre
    [\thepage]% even right
    {\thepage}% odd left
    {}% odd centre
    {\sectiontitle}% odd right
}

\pagestyle{newstyle}

\begin{document}

\chapter{Introduction}
\lipsum[1-10]

\section{A section}
\lipsum[2-20]

\end{document}

In fact, even though the above does not use fancyhdr, the switch to titleps is fairly straight forward. See titleps for fancyhdr users. The advantage should be obvious, since the interface provided by titleps is clear and avoids hacking into the page marks to extract content.

4
  • Sorry Sorry !!! I was totally exhausted when I posted this question that I was in a hurry and I was not clear enough. I want to use the chapter name in the header and I know that \leftmark gives me the chapter name. but, it also gives me an unwanted word - the chapter number. I just want the chapter name and want to remove the chapter number from the command \leftmark. I have made come edit to the code that I posted above(it was actually the methods I tried to get this result)
    – newbie
    May 13 '13 at 17:59
  • @newbie: But that's exactly what titleps provides in my answer. \chaptertitle gives only the chapter title (no number and no CHAPTER prefix). So no need to be sorry...
    – Werner
    May 13 '13 at 18:03
  • Big thanks.. Thanks for the example pictures also.. LIFESAVER answer.. Works PERFECT
    – newbie
    May 13 '13 at 18:05
  • This is exactly what I need except that I would like centered headers, where should I change the code? Jul 31 '15 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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