隐藏目录中的子条目但不隐藏标题

隐藏目录中的子条目但不隐藏标题

考虑以下 MWE:

\documentclass[ms, 12pt]{kfupm_thesis}
\usepackage{apptools, etoolbox}
% code to fix TOC appendix format, irrelevant for this question
\makeatletter
\patchcmd{\@chapter}{\protect {CHAPTER }}{\ifappendix{APPENDIX }\else{CHAPTER }\fi}{}{}
\makeatother

\begin{document}

\tableofcontents

\chapter{First Chapter}
\section{BLA}
\subsection{BLA-BLA}

\chapter{Second Chapter}
\section{BLA}
\subsection{BLA-BLA}

\appendix
\chapter{Parameters}
\section{BLA}
\subsection{BLA-BLA}

\end{document} 

生成以下目录:

在此处输入图片描述

仅在目录中,我想保留标题APPENDIX A PARAMETERS但隐藏其所有子条目,即A.1 BLA和。您能建议一种方法来做到这一点吗?可以从此 dropbox 获取A1.1.1 BLA-BLA类文件kfupm_thesis.cls关联,运行 MWE 所需。

答案1

这是一个解决方案。不是很优雅:重新定义\addcontentsline,但它有效:

\documentclass[ms, 12pt]{kfupm_thesis}
\usepackage{apptools, etoolbox}
% code to fix TOC appendix format, irrelevant for this question
\makeatletter
\patchcmd{\@chapter}{\protect {CHAPTER }}{\ifappendix{APPENDIX }\else{CHAPTER }\fi}{}{}
\AtAppendix{%
\def\addcontentsline#1#2#3{%
  \ifstrequal{#2}{section}{\relax}{%
   \ifstrequal{#2}{subsection}{\relax}{\addtocontents{#1}{\protect\contentsline{#2}{#3}{\thepage}}}
   }}%
   }%
\makeatother

\begin{document}

\tableofcontents

\chapter{First Chapter}
\section{BLA}
\subsection{BLA-BLA}

\chapter{Second Chapter}
\section{BLA}
\subsection{BLA-BLA}

\appendix
\chapter{Parameters}
\section{BLA}
\subsection{BLA-BLA}

\chapter{Other Parameters}

\end{document} 

在此处输入图片描述

答案2

如果sections等应该被隐藏,则将计数器设置tocdepth0,但是,这可能在中完成place,即在之后写入\setcounter{tocdepth}{0}文件。.toc\appendix

0代表\chapter\section将会1等,因此0将限制到目录级别,\chapter仅包括、通常\part\chapter将会出现。)

\documentclass[ms, 12pt]{kfupm_thesis}
\usepackage{apptools, etoolbox}
% code to fix TOC appendix format, irrelevant for this question
\makeatletter
\patchcmd{\@chapter}{\protect {CHAPTER }}{\ifappendix{APPENDIX }\else{CHAPTER }\fi}{}{}
\makeatother


\begin{document}

\tableofcontents

\chapter{First Chapter}
\section{BLA}
\subsection{BLA-BLA}

\chapter{Second Chapter}
\section{BLA}
\subsection{BLA-BLA}

\appendix
\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}

\chapter{Parameters}
\section{BLA}
\subsection{BLA-BLA}

\end{document}

在此处输入图片描述

更新

LoT适用于工作和LoF其他用途的版本。

\documentclass[ms, 12pt]{kfupm_thesis}
\usepackage{apptools}
\usepackage{etoolbox}
% code to fix TOC appendix format, irrelevant for this question
\makeatletter
\patchcmd{\@chapter}{\protect {CHAPTER }}{\ifappendix{APPENDIX }\else{CHAPTER }\fi}{}{}
\pretocmd{\listoffigures}{\addtocontents{lof}{\protect\setcounter{tocdepth}{1}}}{}{}
\pretocmd{\listoftables}{\addtocontents{lot}{\protect\setcounter{tocdepth}{1}}}{}{}
\makeatother


\begin{document}

\tableofcontents
\listoffigures
\listoftables

\chapter{First Chapter}
\section{BLA}
\subsection{BLA-BLA}

\chapter{Second Chapter}
\section{BLA}
\subsection{BLA-BLA}

\appendix
\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}

\chapter{Parameters}

\begin{figure}
\caption{A figure}
\end{figure}
\section{BLA}
\subsection{BLA-BLA}

\begin{table}
\caption{A table}
\end{table}

\end{document} 

相关内容