考虑以下 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
等应该被隐藏,则将计数器设置tocdepth
为0
,但是,这可能在中完成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}