我有未编号的章节标题(使用\chapter*
),但我仍然需要一个可选参数来表示标题的较短版本,用于标题。当我写入时\chapter*[Short title]{Long title}
失败。我需要重新定义所有内容还是有某种方法可以用其他命令来定义短标题?
以下是标准类的最小示例book
:
\documentclass{book}
\begin{document}
\chapter*[A short version of the title]{A very very very very very very
very very very long title that doesn't fit in my header}
Bla bla.
\end{document}
给出
答案1
以下重新定义\chapter
以适应可选星号或可选项的使用*
。在的情况下\chapter*
,可选参数用于设置标题详细信息:
\documentclass{book}
\usepackage{xparse,lipsum}
\makeatletter
\let\oldchapter\chapter
\RenewDocumentCommand{\chapter}{s o m}{% \chapter*[<opt>]{<man>}
\IfBooleanTF{#1}
% \chapter*
{\IfValueTF{#2}
% \chapter*[..]{...}
{\oldchapter*{#3}%
%\addcontentsline{toc}{chapter}{\protect\numberline{}#3}% Add regular title to ToC
%\addtocontents{lof}{\protect\addvspace{10\p@}}% Space between chapters in LoF
%\addtocontents{lot}{\protect\addvspace{10\p@}}% Space between chapters in LoT
\markboth{#2}{}% Set marks based on optional argument
}
% \chapter*{...}
{\oldchapter*{#3}}}
% \chapter
{\IfValueTF{#2}
% \chapter[..]{...}
{\oldchapter[#2]{#3}}
% \chapter{...}
{\oldchapter{#3}}}%
}
\makeatother
\begin{document}
\chapter*
[A short version of the title]
{A very very very very very very very very very long title that doesn't fit in my header}
\sloppy\lipsum[1-50]
\end{document}
例如,如果您想向目录添加内容,一些额外的细节已被注释掉。新章节标记的格式\chapter*[<header>]{<main title>}
已被省略(默认为\MakeUppercase
),但您可以添加:
\markboth{\MakeUppercase{#2}}{}