0

MWE is pretty simple:

\documentclass[twoside]{article}
%\usepackage{titlesec}
\usepackage{fancyhdr}
\begin{document}
\pagestyle{fancy}
\section{tist1}
\subsection{a}
\newpage
\subsection{b}
\end{document}

On the second page, there is the subsection name on the left and the section name on the right.

Now, uncomment the titlesec import, and the behaviour changes: the section name on the left and nothing (actually, a fantom of non-existent chapter name) on the right.

It happens because titlesec redefines \chapter as \relax, though normally it's undefined in article class. The fancyhdr packages has a following check:

\ifx\chapter\@undefined

It fails, and marks are defined as in classes that have chapters. I can work it around with

\let\chapter\undefined

after \usepackage{titlesec}, or by explicitly redefining sectionmark/subsectionmark after \pagestyle{fancy}. But why should I? Is this a bug in titlesec, or setting \chapter to \relax has some purpose?

UPD:

 *File List*
 article.cls    2018/09/03 v1.4i Standard LaTeX document class
  size10.clo    2018/09/03 v1.4i Standard LaTeX file (size option)
titlesec.sty    2016/03/21 v2.10.2 Sectioning titles
fancyhdr.sty    2017/06/30 v3.9a Extensive control of page headers and footers
 ***********
  • What versions of the packages are you using? (Put \listfiles before \documentclass and report the output here.) I get identical output with or without titlesec. – Alan Munn Mar 12 at 2:54
  • @AlanMunn added to the post. – bodqhrohro Mar 12 at 12:02
  • Update fancyhdr; the current version is 2019/01/31 v3.10 – egreg Mar 12 at 12:14
  • @egreg yes, the new version of fancyhdr has a \f@nch@ifundefined macro which handles both undefined and \relax, thanks. But anyway, is there any purpose to set \chapter to \relax instead of undefined in titlesec? – bodqhrohro Mar 12 at 12:31
  • @bodqhrohro That should be asked to the package maintainer. – egreg Mar 12 at 13:06

Your Answer

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

Browse other questions tagged or ask your own question.