8

I want to have the chapter name and title of the document appear in the header; I know how to do that with fancyhdr and titling, one of the miscellaneous functions of the latter is to preserve the \thetitle command which can be used to extract the title of the document later on.

Now I added on the titlesec package to make the section/chapter headings look better. But here I run into a problem: titlesec seems to be overwriting \thetitle with the contents of \thesection or \thesubsection!

An example to show the problem:

\documentclass{report}
\usepackage{titling}
\usepackage{titlesec}

\newpagestyle{testfancy}{%
  \headrule% 
  \sethead{\thetitle}{}{\chaptertitle}}
\pagestyle{testfancy}

\title{My title}
\author{This author}

\begin{document}
\maketitle

\chapter{A chapter}

some filler text

\newpage

some more filler text

\newpage

\section{Now a section is added}
\end{document}

On page 3, the left header is displayed (as defined and intended) to be the value of \thetitle, which in this case is "My title". On page 4, however, after the new section, the left header now shows as "1.1", the value of \thesection.

Is this conflict documented somewhere? And is there a fix/workaround?

2 Answers 2

8

Kind of hack-ish, but it works. (You might not need titling any more if this is all you were using it for...)

\documentclass{report}
\usepackage{titling}
\usepackage{titlesec}

\let\oldtitle\title
\renewcommand{\title}[1]{\oldtitle{#1}\newcommand{\mythetitle}{#1}}

\newpagestyle{testfancy}{%
  \headrule% 
  \sethead{\mythetitle}{}{\chaptertitle}}
\pagestyle{testfancy}

\author{This author}
\title{My Title}

\begin{document}
\maketitle

\chapter{A chapter}

some filler text

\newpage

some more filler text 

\newpage

\section{Now a section is added}
\end{document}
1
  • Nah, I'm putting together a class file for writing lecture notes, and am using titling to format the output of \maketitle, so I'm not just using it for the one command. Redefining \title does work. Thanks. Oct 11, 2010 at 10:12
4

I don't know if the conflict is documented anywhere, but it is quite clear from reading the source of the two packages. You can replace your use of \thetitle with \mytitle and at some point after \title{My title}, put \let\mytitle\thetitle.

[Edit: I should point out that like frabjous's answer, you don't need the titling package for this. You can use

\makeatletter
\let\mytitle\@title
\makeatother

after your \title{My title} instead.]

Also, when compiling your code, I get the following warning.

Package titlesec Warning: You are using an old interface for page styles
(titlesec)                You could proceed but don't complain if you run
(titlesec)                into errors.

You might want to fix that.

2
  • Unfortunately, I don't know how to =( I am following the manual in the latest release, which does make the comment in a footnote that "The way page styles works have been reimplemented in full in release 2.3. However in most cases you won't notice a difference at all." And this is with the documentation that comes with release 2.8... Oct 11, 2010 at 10:07
  • 1
    In version 2.9 the warning is more meaningful - you forgot the package option pagestyles. Sep 5, 2011 at 13:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .