1

I am working on a long document with many chapters, using report class.

I would like to have three different versions of certain section titles (long for document, medium for TOC, and short for header). I am using package fancyhdr, so I followed instructions in a nice FAQ (also given in this question: How to use short subsection title in header but not in table of contents?).

\section[TOC_title]{Full_title\sectionmark{Header_title}}
\sectionmark{Header_title}

(I believe that the idea is that the inside-title sectionmark takes care of the page the section starts on, and the outside one deals with the subsequent pages.)

This all worked fine. However, because my doc is double-spaced, I also used titlesec to shrink down some whitespace around chapter and section titles.

Now I get the TOC_title header on the page the section starts on (wrong), and then the (correct) Header_title header on subsequent pages. Obviously I would like to fix this.

I suspect that fancyhdr is a bad idea long-term and I should switch to another header package, but I don't want to mess with the current document. I also don't want to let go of titlesec right now because it really has helped a lot with the doublespaced whitespace, and the issue I am having is minor in comparison.

Is there a way to fix this using titlesec? I have tried reading the documentation but I am getting very confused. I would be very grateful for someone who already knows this package to make a suggestion.

This question has been asked before in How do I put a short title in the header but a long title in the toc (clashing of titlesec package with sectionmark)?. But the only answer suggests KOMA-script; I suspect that this is some other family of packages that I am not going to learn right now.

Let me also add that my dissertation is due tomorrow, so I will not have time to put together a small working example today. I am interested in solving this issue both today and long-term, so I can come back and do this later if necessary. But in the meantime, I would appreciate any answers today very much!

UPDATE (May 1, 2015): Here's a minimal working example. The Ponysec header on its first page is correct if \usepackage{titlesec} is commented out and not otherwise. The Carouselsec header uses Ulrike Fischer's minihack and works either way.

\documentclass{report}
\usepackage{fancyhdr}
\usepackage{titlesec}
\newcommand{\funnysection}[3]
     {\let\orisectionmark\sectionmark
     \renewcommand\sectionmark[1]{}%
     \section[{#2}]{{#1}\orisectionmark{{#3}}}
     \orisectionmark{{#3}}
     \let\sectionmark\orisectionmark}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%% BEGIN DOCUMENT    %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\tableofcontents
\pagestyle{fancy}

\chapter{Mychapter}
\section{Cactussec (UNIVERSION)}
No header on this page.
\clearpage
\section[Ponysec (TOC)]{Ponysec (main)\sectionmark{Ponysec (header)}}
\sectionmark{Ponysec (header)} 
Desired header here is "Ponysec (header)".
\clearpage
Desired header here is "Ponysec (header)".
\clearpage
\funnysection{Carouselsec (main)}{Carouselsec (TOC)}{Carouselsec (header)}
Desired header here is "Carouselsec (header)".
\clearpage
Desired header here is "Carouselsec (header)".
\end{document}

If the right solution (for me, who doesn't really know what KOMA/KONA/script means and yet wants to create decent typeset documents today, this week, this month despite this massive ignorance) is to use titleps instead of fancyhdr, I would still love to find out how to do that.

  • Welcome to TeX SX! A minimal example showing the problem would help us to help you. – Bernard Apr 29 '15 at 20:27
  • It's not really minimal, but there's an example in tex.stackexchange.com/questions/131763/…?. User wasarga was having the exact same problem. I can add a more compact example tomorrow. – sibilant Apr 30 '15 at 1:02
  • KOMA-script a versatile bundle of classes and packages for LaTeX2e. – Johannes_B May 1 '15 at 21:24
  • Well, this question hasn't really received enough attention, but it also has zero net upvotes, so rather than starting a bounty, I will accept @ulrikefischer's solid and increasingly appealing answer. – sibilant May 15 '15 at 13:38
5

You can try something like this to fool titlesec:

\let\orisectionmark\sectionmark
\renewcommand\sectionmark[1]{}%
\section[TOCtitle]{Fulltitle\orisectionmark{Headertitle}}
\orisectionmark{Headertitle}
\let\sectionmark\orisectionmark

EDIT

Some Remarks regarding the comments: You didn't provide a minimal example so most of it was guessing. titlesec calls internally \sectionmark{TOCtitle} so early that your own \sectionmark commands are too late. So I'm redefining \sectionmark to nothing so that titlesec can no longer set a mark and use a copy \orisectionmark to set your marks. Replacing the middle \orisectionmark's with \sectionmark should not work -- after all the command is defined to do nothing.

I don't know why you don't want to use the KONA-classes but imho a solution with titlesec would involve to drop fancyhdr and to use titleps instead. I'm quite sure that Javier implemented somewhere a way to set the marks correctly but as you already found out his documentations are not easy to read and finding something that works often involves a lot of trial and error and reading the code.

  • It works. This is a really great solution for tonight. But I put it directly around the sectionheader -- is that the only way it will work? I also can't quite parse what's happening, however. Is \orisectionmark a preexisting command? or is it just a placeholder saving sectionmark while you muss around with it? -- cont'd – sibilant Apr 30 '15 at 0:42
  • cont'd -- and if so, did you mean \let\orisectionmark\sectionmark \renewcommand\sectionmark[1]{}% \section[TOCtitle]{Fulltitle\sectionmark{Headertitle}} \sectionmark{Headertitle} \let\sectionmark\orisectionmark (that is, the 2 "orisectionmark"s right after the section declaration should actually be "sectionmark"s) -- because that's actually what worked for me. – sibilant Apr 30 '15 at 0:43
  • And of course I would love a better solution for the future (i.e., not involving KOMA-script). Does titlesec, which seems like such a thought-out package, really not provide for this triple tier of section titles? – sibilant Apr 30 '15 at 0:48
  • I registered so I could upvote your answer (why do I need such a crazy secure password for this site of all sites???), which is why my name changed. – sibilant Apr 30 '15 at 0:52
2

Using KOMA-script, there would be no problem :-)

\documentclass[headings=optiontoheadandtoc]{scrartcl}
\usepackage[automark]{scrlayer-scrpage}
\usepackage{blindtext}
\begin{document}
\tableofcontents
\section[tocentry={platypus dancing till morning},%
head={dancing platypus}]%
{The platypus went on dancing till the mornig sun rose
over the hills}
\blindtext[5]
\end{document}

annaTocHeadTitles

  • Are you being cruel only to be kind?... – sibilant Apr 30 '15 at 0:32
  • To be honest, i haven't read the complete question. There is a whole bunch of packages out there, extending the standard classes with this and that. And there are memoir and KOMA provinding many of these things just out of the box. – Johannes_B Apr 30 '15 at 10:19

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.