Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LaTeX: update '\leftmark' automatically on '\chapter*{abc123}'

Tags:

latex

In my current document there are some chapters that have to be added with the \chapter*-command because I don't want them to be real chapters (no entry in toc, no chapter-number, ...). This works fine.

But in my header I want the chapter-name to be displayed. I'm using fancyheaders and \leftmark:

\fancyhead[RO,LE]{\leftmark}

The problem is, that for chapters added with the \chapter*-command, \leftmark is not updated and so the header still displays the chapter-name of the previous chapter.

Therefore I either need to force \chapter* to automatically update \leftmark, or I switch to the \chapter-command but prevent the other stuff that comes along (entry in toc, ...). but I don't know how! Any ideas?

like image 835
NATOR Avatar asked Sep 10 '10 10:09

NATOR


4 Answers

The * forms of the \chapter etc. commands do not call the mark commands. So if you want your preface to set the header info but not be numbered nor be put in the table of contents, you must issue the \markboth command yourself, e.g.

\chapter*{abc123\markboth{abc123}{}}
like image 174
xiangyuc Avatar answered Nov 02 '22 13:11

xiangyuc


I just had redefined chapter and section command to what I need and had set the \leftmark explicitly. Chapter commands will not able to use leftmark anymore, but I don't care as I'm using my \nnchapter and \nnsection commands in the whole document

\newcommand{\nnchapter}[1]{
   \phantomsection
   \addcontentsline{toc}{chapter}{#1}\renewcommand{\leftmark}{#1}\chapter*{#1}
}
\newcommand{\nnsection}[1]{
   \phantomsection
   \addcontentsline{toc}{section}{#1}\renewcommand{\leftmark}{#1}\section*{#1}
}
like image 35
Alexander A. Zaytsev Avatar answered Nov 02 '22 14:11

Alexander A. Zaytsev


Try this:

 \let\oldleftmark=\leftmark
    \chapter*{My New Leftmark}
    \renewcommand{\leftmark}{My New Leftmark}
      ...
      Your text
      ...
    \pagebreak
    \chapter{Next Chapter}
    \let\leftmark=\oldleftmark

pagebreak is required to ensure the new lefmark is used

like image 2
elmoke Avatar answered Nov 02 '22 14:11

elmoke


allright, i did it! the solution is to redefine \leftmark only within a specific block! pretty simple if you know it ;)

{
    \renewcommand{\leftmark}{ABC123}
    \chapter*{ABC123}

    %... and so on ...
}
like image 1
NATOR Avatar answered Nov 02 '22 13:11

NATOR