在目录中使用章节全名

在目录中使用章节全名

因为“长标题”对于标题来说太长了\chapter[short title]{long title}。但是,我想在目录中使用“长标题”。我该怎么做?我正在使用报告类。

以下是代码

\documentclass[11pt]{report}  
\usepackage{amssymb,amsmath}  
\usepackage{verbatim,a4wide}  
\usepackage[cp1250]{inputenc}  
\usepackage[OT4]{fontenc}  
\usepackage[english]{babel}  
\usepackage[section]{placeins}  
\usepackage{amsthm}  
\usepackage{bm}  
\usepackage{graphicx}  
\usepackage{arydshln}  
\usepackage{amsfonts}  
\usepackage{epstopdf}  
\usepackage{caption}  
\usepackage{subfig}  
\usepackage{appendix}  
\usepackage{grffile}  
\usepackage{bbm}  
\usepackage{booktabs}  
\usepackage{multirow}  
\usepackage{rotating}  
\usepackage{hyperref}  
\usepackage{color}  
\usepackage{enumitem}  
\usepackage{listings}  
\usepackage{chngcntr}  
\usepackage[numbers,sort&compress]{natbib}  
\usepackage{mathtools}  
\usepackage{makeidx}  
\usepackage{fancyhdr}  
\usepackage{afterpage}  

\usepackage{xpatch}  

\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}\protect\parbox[t]{0.9\linewidth}{#2}}%  
  \else  
  \addcontentsline{toc}{chapter}{\protect\parbox[t]{0.9\linewidth}{#2}}%  
  \fi  
  \addtocontents{toc}{\protect\addvspace{0.5\baselineskip}}% Some spacing   afterwards
}{}{}  

\makeatother  



\begin{document}  

\thispagestyle{empty}  
\tableofcontents  

\chapter[short title]{long title}  

\end{document}

答案1

这是一种可行的方法,修补\@chapter命令,实际上是在后面,\chapter并用 替换。但是,这应该使用顶部对齐来完成,否则页码将放在段落末尾。#1\addcontentsline#2\parbox

这么长的标题章节条目后应该有一些额外的垂直间距。

更复杂的解决方案将使用另一个可选参数来保存长标题ToC

\documentclass{report}


\usepackage{xpatch}

\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}\protect\parbox[t]{0.9\linewidth}{#2}}%
  \else
  \addcontentsline{toc}{chapter}{\protect\parbox[t]{0.9\linewidth}{#2}}%
  \fi
  \addtocontents{toc}{\protect\addvspace{0.5\baselineskip}}% Some spacing afterwards
}{}{}


\makeatother

\usepackage{blindtext}
\begin{document}
\tableofcontents

\chapter[Short Title]{This is an awful long title which shouldn't be used actually at all}
\section{ A short section}
\chapter[Short Title]{\blindtext}

\end{document}

在此处输入图片描述

更新和原帖一起。‘MWE’

\documentclass[11pt]{report}  
\usepackage{amssymb,amsmath}  
\usepackage{verbatim,a4wide}  
\usepackage[cp1250]{inputenc}  
\usepackage[OT4]{fontenc}  
\usepackage[english]{babel}  
\usepackage[section]{placeins}  
\usepackage{amsthm}  
\usepackage{bm}  
\usepackage{graphicx}  
\usepackage{arydshln}  
\usepackage{amsfonts}  
\usepackage{epstopdf}  
\usepackage{caption}  
\usepackage{subfig}  
\usepackage{appendix}  
\usepackage{grffile}  
\usepackage{bbm}  
\usepackage{booktabs}  
\usepackage{multirow}  
\usepackage{rotating}  
\usepackage{color}  
\usepackage{enumitem}  
\usepackage{listings}  
\usepackage{chngcntr}  
\usepackage[numbers,sort&compress]{natbib}  
\usepackage{mathtools}  
\usepackage{makeidx}  
\usepackage{fancyhdr}  
\usepackage{afterpage}  


\usepackage{xpatch}  



\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}\texorpdfstring{\protect\parbox[t]{0.9\linewidth}{#2}}{#2}}%  
  \else  
  \addcontentsline{toc}{chapter}{\texorpdfstring{\protect\parbox[t]{0.9\linewidth}{#2}}{#2}}%  
  \fi  
  \addtocontents{toc}{\protect\addvspace{0.5\baselineskip}}% Some spacing   afterwards
}{\typeout{Patching was successfull!}}{}  


\usepackage{hyperref}  


\usepackage{blindtext}

\begin{document}  

\thispagestyle{empty}  
\tableofcontents  

\chapter[short title]{Long title}



\end{document}

相关内容