5

I would like to ask about header of the document.

Here is my code:

\documentclass[a4paper]{book}%
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}


\begin{document}
\tableofcontents

\chapter{Introduction}
\newpage

Pellentesque at quam sit amet sem pharetra imperdiet a eget augue. 

\chapter{Introduction into optical sensoric systems long long}
How to do the header of the document with "Introduction into OSS long long" instead of "Introduction into optical sensoric systems long long" but I want to keep same structure.


\newpage 
\section{Short title}
Mauris ac porttitor arcu, nec euismod diam. 



\newpage
\section{The methods for polarization mode dispersion and their measurement}
How to do the header of document with "The methods for PMD and their measurement" instead of "The methods for polarization mode dispersion and their measurement" but I want to keep same structure.

\end{document}

I try to change header by fancyhdr but I do not know how to keep same structure. This is what I want for \chapter:

I want to get the following for chapter

And this is what I want for \section:

I want the following for section

Thank you in advance

6

NOTE: Edited to put the mark commands after the sectioning commands as indicated by @Werners comments and with a new command for the section.

Put the short titles in a \chaptermark or \sectionmark, respectively. For a chapter this works as the header uses the last chaptermark of the page, i.e. the extra one that we put after the chaptertitle.

\chapter{Introduction into optical sensoric systems long long}
\chaptermark{Introduction into OSS long long}

For the section this doesn't work properly because the header uses the first sectionmark, which is the one that is generated by the \section command. So we could put the \sectionmark before the \section command but this has two disadvantages:

  1. There could be a page break between the \sectionmark command and the \section command. Then the **previous* page would get the section title in its header and the page containing the section would still get the long title.
  2. Subsequent pages would still get the long section title in their header if there are no more sections. This could be overcome by also putting a \sectionmark command after the \section command. This becomes a bit unwieldy.

Therefore we define a new command \mysection with two parameters: the section title and the title to be used for the header. During the processing of the section title it makes the \sectionmark command do nothing. This does not support the optional argument of \section that can be given for the TOC entry. That is also possible but makes the command more complicated.

\newcommand{\mysection}[2]
  {{\renewcommand{\sectionmark}[1]{}
    \section{#1}}\sectionmark{#2}}

\mysection{The methods for polarization mode dispersion and their measurement}
          {The methods for PMD and their measurement}

N.B. If you would use the memoir documentclass instead of book, the \chapter and \section etc. commands have an additional optional parameter where the header can be given.

| improve this answer | |
  • 1
    Dear Piet, thank you, It works very well! You made my day. – Thomas Nov 10 '16 at 15:39
  • Don't issue any mark inside the sectional unit, as this will make its way into the ToC, eventually also making the headers different there. – Werner Nov 10 '16 at 16:19
  • @Werner You are right. You should also give the original title as an optional argument so that this will be used in the table of contents. Or you can change the page headers explicitly in the table of contents. You can also put the marks outside the sectional commands but then there is a chance that they will be separated by a page break (not for a \chapter command as that usually starts at a new page). – Pieter van Oostrum Nov 10 '16 at 16:32
  • Here is a way to get the table of contents without the wrong marks: {\renewcommand\chaptermark[1]{}\renewcommand\sectionmark[1]{} \tableofcontents } – Pieter van Oostrum Nov 10 '16 at 16:37
  • @PietvanOostrum: Disabling marks for the ToC will remove the ToC from setting these, which is not ideal. Rather set the marks outside the sectional unit. LaTeX ensures that there will be no break between the sectional unit title and the subsequent paragraph, so there's not a problem with being separated by a page break. – Werner Nov 10 '16 at 16:39
2

For comparison, in ConTeXt, you can specify the content of the marking and the table of content (called list) to be different from the title of a section head.

\setupheadertexts[section][]
\starttext

\subject{Contents}
\placecontent

\startsection
    [
      title=Section title,
      list=Section title in TOC,
      marking=Section title in headers,
    ]

\input ward

\stopsection
\stoptext

enter image description here

| improve this answer | |

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.