【问题标题】:LaTeX: update '\leftmark' automatically on '\chapter*{abc123}'LaTeX:在 '\chapter*{abc123}' 上自动更新 '\leftmark'
【发布时间】:2013-02-26 20:23:18
【问题描述】:

在我当前的文档中,必须使用\chapter*-命令添加一些章节,因为我不希望它们成为真正的章节(目录中没有条目,没有章节-数字, ...)。这很好用。

但在我的标题中,我希望显示 chapter-name。我正在使用fancyheaders\leftmark

\fancyhead[RO,LE]{\leftmark}

问题是,对于使用\chapter*-命令添加的章节,\leftmark 没有更新,因此标题仍然显示上一章的章节名称。

因此,我要么需要强制\chapter* 自动更新\leftmark,要么切换到\chapter-命令但阻止出现其他内容(进入toc,...)。但我不知道怎么做!有什么想法吗?

【问题讨论】:

标签: latex


【解决方案1】:

\chapter 等命令的 * 形式不调用标记命令。所以如果你想让你的序言设置标题信息但不编号也不放在目录中,你必须自己发出\markboth命令,例如

\chapter*{abc123\markboth{abc123}{}}

【讨论】:

  • 像魅力一样工作!
【解决方案2】:

我刚刚将章节命令重新定义为我需要的内容,并明确设置了\leftmark。章节命令将无法再使用 leftmark,但我不在乎,因为我在整个文档中使用了我的 \nnchapter\nnsection 命令

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

【讨论】:

    【解决方案3】:

    试试这个:

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

    需要pagebreak 以确保使用新的lefmark

    【讨论】:

      【解决方案4】:

      好吧,我做到了!解决方案是仅在特定块内重新定义 \leftmark !如果你知道的话就很简单;)

      {
          \renewcommand{\leftmark}{ABC123}
          \chapter*{ABC123}
      
          %... and so on ...
      }
      

      【讨论】:

      • 我理解正确吗:您正在为每个 \chapter* 重新定义 \leftmark ??
      【解决方案5】:

      我不确定这是否可行,因为我当前的机器上没有安装 LaTeX...

      但您可以尝试在您的 \chapter* 命令之后设置一个 \markleft 命令,如下所示:

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

      希望这会有所帮助。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-21
      • 1970-01-01
      • 1970-01-01
      • 2017-03-10
      • 1970-01-01
      • 2022-07-12
      相关资源
      最近更新 更多