开发者

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

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 d开发者_运维百科isplays 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?


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}{}}


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}
}


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


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 ...
}


I'm not sure this will work, because I don't have LaTeX installed on my current machine...

But you could try setting a \markleft command after your \chapter* command like so:

\chapter*{Chapter title goes here}
\markleft{Chapter title goes here}  % content should be added to the \leftmark

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜