我的文档到处都使用如下标题。
\section[short]{longlonglong}
标题short
用于页眉和目录。longlonglong
标题仅用于章节标题本身。
我如何longlonglong
在目录中使用标题?我想保留页眉的当前格式。
谢谢你!
更新:
\documentclass[12pt,a4paper]{report}
%\usepackage{../sty/reportpage}
\begin{document}
\pagestyle{reportpage}
\pagenumbering{roman}
\setcounter{page}{1}
\cleardoublepage
\renewcommand{\baselinestretch}{1.25}
\small\normalsize
\tableofcontents
\renewcommand{\baselinestretch}{1}
\small\normalsize
\cleardoublepage
\pagenumbering{arabic}
\setcounter{page}{1}
\chapter[First Chapter]{The first chapter has a long title that only is shown as the chapters headline}
Some irelevant text.
\cleardoublepage
more irelevant text.
\end{document}
答案1
我不会弄乱目录,只是不设置简短版本,而是将标题更改为标题,例如\chaptermark
。
不幸的是您的代码不包含任何要测试的标题,因此我改用了fancyhdr
。
\documentclass[12pt,a4paper]{report}
%\usepackage{../sty/reportpage}
\usepackage{fancyhdr}
\begin{document}
%\pagestyle{reportpage}
\pagestyle{fancy}
\pagenumbering{roman}
\setcounter{page}{1}
\cleardoublepage
\renewcommand{\baselinestretch}{1.25}
\small\normalsize
\tableofcontents
\renewcommand{\baselinestretch}{1}
\small\normalsize
\cleardoublepage
\pagenumbering{arabic}
\setcounter{page}{1}
\chapter{The first chapter has a long title that only is shown as the chapters headline}
\chaptermark{short version}
Some irelevant text.
\cleardoublepage
more irelevant text.
\end{document}
答案2
重新定义\@chapter
或使用补丁来修改写入 ToC 条目的代码,即\addcontentsline
。
report
用途
\ifnum \c@secnumdepth >\m@ne
\refstepcounter{chapter}%
\typeout{\@chapapp\space\thechapter.}%
\addcontentsline{toc}{chapter}%
{\protect\numberline{\thechapter}#1}%
\else
\addcontentsline{toc}{chapter}{#1}%
\fi
所以#1
意味着可选参数,但#2
在这里是需要的。
基本也是如此\@sect
,它使用#7
,必须用 替换#8
。
下面的代码使用开关来修改条目:
假设\uselongtitletrue
在目录中启用长标题,但在标题栏中保留短标题,\uselongtitlefalse
以便使用短标题。
\documentclass[12pt,a4paper]{report}
%\usepackage{../sty/reportpage}
\usepackage{xpatch}
\newif\ifuselongtitle
\uselongtitletrue
\makeatletter
\xpatchcmd{\@chapter}{%
\ifnum \c@secnumdepth >\m@ne
\refstepcounter{chapter}%
\typeout{\@chapapp\space\thechapter.}%
\addcontentsline{toc}{chapter}%
{\protect\numberline{\thechapter}#1}%
\else
\addcontentsline{toc}{chapter}{#1}%
\fi}{%
\ifnum \c@secnumdepth >\m@ne
\refstepcounter{chapter}%
\typeout{\@chapapp\space\thechapter.}%
\addcontentsline{toc}{chapter}%
{\protect\numberline{\thechapter}\ifuselongtitle#2\else#1\fi}%
\else
\addcontentsline{toc}{chapter}{\ifuselongtitle#2\else#1\fi}%
\fi
}{\typeout{Success}}{\typeout{Failure}}
\xpatchcmd{\@sect}{%
\fi #7%
}{\fi\ifuselongtitle#8\else#7\fi}{}{}
\makeatother
\begin{document}
%\pagestyle{reportpage}
\pagenumbering{roman}
\setcounter{page}{1}
\cleardoublepage
\renewcommand{\baselinestretch}{1.25}
\small\normalsize
\tableofcontents
\renewcommand{\baselinestretch}{1}
\small\normalsize
\cleardoublepage
\pagenumbering{arabic}
\setcounter{page}{1}
\chapter[First Chapter]{The first chapter has a long title that only is shown as the chapters headline}
Some irelevant text.
\section[Foo]{Long foo section}
\subsection[Foo]{Long foo subsection}
\cleardoublepage
more irrelevant text.
\end{document}