使用宏将章节添加到附录列表

使用宏将章节添加到附录列表

我有一个论文模板。它有附录列表,作为单独的目录页。

在此处输入图片描述

但我想在这个附录列表中添加一些部分,例如,

A Chapter One of Appendix
  A.1 Section One
  A.2 Section Two
B Chapter Two of Appendix
  A.1 Section One
  A.2 Section Two

这是我使用的模板“style.cls”。抱歉,有点乱。我从一个很大的模板文件中提取了它。

%% This passes any other options on to the 'report' class.
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}%
 \typeout{Unknown option: passing ``\CurrentOption"
  option on to the standard LaTeX report class.}}
% This command tells LaTeX to simply process the class options.
\ProcessOptions
%
%% This control structure calls the standard LaTeX report.cls class.
%% The base font size should be 10pt unless using the submit option.
\LoadClass[letterpaper,12pt,oneside]{report}


\RequirePackage{setspace}

\RequirePackage[printonlyused]{acronym}

\newcommand*{\frntpg}{ %
 % Check the number of columns.
 \newpage
 % Regular headers and footers
 \thispagestyle{plain}
}


%% ---- TABLE OF CONTENTS ----------------------------------------------
% This sets the formatting for chapter entries in the table of contents.
\renewcommand*\l@chapter[2]{ %
 % First add some vertical space.
 \vskip 1ex plus 1pt minus 1pt
 % Format the spacing and use dots between title and number.
 \@dottedtocline{1}{0em}{1.0em} %
 % This sets the formatting for the chapter name and page number.
 {\textbf{#1}}{\textbf{#2}} %
 % Add some space below, too.
 \vskip 1ex}

% These lines set the spacing for other table of contents entries.
\renewcommand*{\l@section}{\@dottedtocline{2}{2.5em}{2em}}
\renewcommand*{\l@subsection}{\@dottedtocline{3}{5.0em}{2.8em}}
\renewcommand*{\l@subsubsection}{\@dottedtocline{4}{7.5em}{3.5em}}

% Number of section layers to show in table of contents
\setcounter{tocdepth}{3}
% Number of subsection layers to allow in document
\setcounter{secnumdepth}{3}

% This sets the formatting of the table of contents.
\renewcommand*{\tableofcontents}{%
 % Move to new page.
 \newpage %
 % Add a pdf anchor.
 \phantomsection %
 % Add a bookmark manually for the table of contents.
 \pdfbookmark[0]{Table of Contents}{\thepage} %
 % Use front page styling.
 \frntpg %
 % Larger upper margin for first page of table
  \begin{minipage}{0.8\textwidth} \vspace{1in} \end{minipage} \\ %
 % Add the title
 \centerline{\large\bf TABLE OF CONTENTS} %
 % Add some space after the title.
 \vspace{2ex} %
 % Start the automatic table of contents features.
 \begin{singlespace} %
  \@starttoc{toc}\if@restonecol\twocolumn\fi %
 \end{singlespace} %
}


%% ---- LIST OF APPENDICES ---------------------------------------------
% This sets the formatting for appendices in the list.
\newcommand*{\l@appendix}{\@dottedtocline{1}{0em}{2.5em}}

% This sets the formatting of the list of appendices page.
\newcommand*{\listofappendices}{%
 % Move to new page.
 \newpage %
 % Add this page to the table of contents.
 \phantomsection\addcontentsline{toc}{chapter}{List of Appendices} %
 % Anchor for pdf
 \phantomsection %
 % Use front page styling.
 \frntpg %
 % Larger upper margin for first page of table (thesis only)
  \begin{minipage}{0.8\textwidth} \vspace{1in} \end{minipage} \\ %
 % Add the title
 \centerline{\large\bf LIST OF APPENDICES} %
 % Add some space after the title.
 \vspace{1ex} %
 % Start the automatic table of contents features.
 \begin{singlespace} %
  \@starttoc{loa}\if@restonecol\twocolumn\fi %
 \end{singlespace} %
}

% Renew the command that starts the appendices.
\renewcommand{\appendix}{ %
 % Move to new page.
 \clearpage %
 % Renew the counters.
 \renewcommand*{\thechapter}{\Alph{chapter}} %
 % Start over the chapter counter.
 \setcounter{chapter}{0} %
 % Add a pdf anchor.
 \phantomsection %
 % Add the page to the table of contents.
 \addcontentsline{toc}{chapter}{Appendices}
 % Stop adding sections to the table of contents.
 \addtocontents{toc}{\setcounter{tocdepth}{1}} %
 % Header for appendices.
 \renewcommand{\@chapapp}{APPENDIX} %
 % Renew the chapter and section labels.
 \let\@chapter\@chapter@appendix %
}

% Make a special chapter command for appendices.
\def\@chapter@appendix[#1]#2{ %
 % Increase the chapter letter.
 \refstepcounter{chapter} %
 % Print a line to the .log file.
 \typeout{\@chapapp\space\thechapter.} %
 % Hopefully this works.
 \phantomsection %
 % Add a bookmark manually.
 \pdfbookmark[0]{#1}{#2} %
 % Add to the list of appendices rather than toc.
 \addcontentsline{loa}{chapter}{\protect\numberline{\thechapter}#1} %
 % Save the chapter number.
 \chaptermark{#1} %
}

%
%% ---- LINKS ----------------------------------------------------------
% This loads a package that allows extra colors for links.
\RequirePackage[usenames,dvipsnames]{color}
\RequirePackage[pagebackref=true]{hyperref}

 \hypersetup{ %
  colorlinks=true, %
  pdfstartview={FitH}, %
  citecolor=DarkGreen, %
  linkcolor=Black, %
  urlcolor=Blue %
 }



%% ---- INITIALIZATION -------------------------------------------------
% Commands to be placed after \begin{document}
\AtBeginDocument{ %
 % Insert the table of contents.
 \tableofcontents %
 % Insert the list of appendices.
 \listofappendices
 \newpage %
}

以下是测试文本:

\documentclass{style}

%% DOCUMENT AREA
\begin{document}


\chapter{First Chapter}   

\chapter{Second Chapter}   

\section{First Section}

\section{Second Section}

\subsection{First Subsection}


\subsection{Second Subsection}


\subsection{Third Subsection}  


\subsection{Fourth Subsection}   

\subsection{Fifth Subsection}

\section{Third Section}

\subsection{First Subsection}


\subsection{Second Subsection}


\subsection{Third Subsection}

\subsection{Fourth Subsection}

\chapter{Third Chapter}

\section{First Section}

\section{Second Section}

\appendix
\chapter{First Chapter of Appendices}  

\section{First Section of Appendices}

\section{Second Section of Appendices}

\chapter{Second Chapter of Appendices}    

\section{First Section of Appendices}

\section{Second Section of Appendices}

\chapter{Third Chapter of Appendices} 


\end{document}

请指导我如何修改以添加部分。


后续问题:我按照@Werner 提供的说明修改了代码。谢谢!如果我有参考书目,它现在也会出现在 LoA 中。此外,附录中的图表也会出现在 LoA 中,我希望它们分别出现在 LoF 和 LoT 中。

在此处输入图片描述

样式.cls:

%% This passes any other options on to the 'report' class.
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}%
 \typeout{Unknown option: passing ``\CurrentOption"
  option on to the standard LaTeX report class.}}
% This command tells LaTeX to simply process the class options.
\ProcessOptions
%
%% This control structure calls the standard LaTeX report.cls class.
%% The base font size should be 10pt unless using the submit option.
\LoadClass[letterpaper,12pt,oneside]{report}


\RequirePackage{setspace}

\RequirePackage[printonlyused]{acronym}

\newcommand*{\frntpg}{ %
 % Check the number of columns.
 \newpage
 % Regular headers and footers
 \thispagestyle{plain}
}


%% ---- TABLE OF CONTENTS ----------------------------------------------
% This sets the formatting for chapter entries in the table of contents.
\renewcommand*\l@chapter[2]{ %
 % First add some vertical space.
 \vskip 1ex plus 1pt minus 1pt
 % Format the spacing and use dots between title and number.
 \@dottedtocline{1}{0em}{1.0em} %
 % This sets the formatting for the chapter name and page number.
 {\textbf{#1}}{\textbf{#2}} %
 % Add some space below, too.
 \vskip 1ex}

% These lines set the spacing for other table of contents entries.
\renewcommand*{\l@section}{\@dottedtocline{2}{2.5em}{2em}}
\renewcommand*{\l@subsection}{\@dottedtocline{3}{5.0em}{2.8em}}
\renewcommand*{\l@subsubsection}{\@dottedtocline{4}{7.5em}{3.5em}}

% Number of section layers to show in table of contents
\setcounter{tocdepth}{3}
% Number of subsection layers to allow in document
\setcounter{secnumdepth}{3}

% This sets the formatting of the table of contents.
\renewcommand*{\tableofcontents}{%
 % Move to new page.
 \newpage %
 % Add a pdf anchor.
 \phantomsection %
 % Add a bookmark manually for the table of contents.
 \pdfbookmark[0]{Table of Contents}{\thepage} %
 % Use front page styling.
 \frntpg %
 % Larger upper margin for first page of table
  \begin{minipage}{0.8\textwidth} \vspace{1in} \end{minipage} \\ %
 % Add the title
 \centerline{\large\bf TABLE OF CONTENTS} %
 % Add some space after the title.
 \vspace{2ex} %
 % Start the automatic table of contents features.
 \begin{singlespace} %
  \@starttoc{toc}\if@restonecol\twocolumn\fi %
 \end{singlespace} %
}


%% ---- LIST OF APPENDICES ---------------------------------------------
% This sets the formatting for appendices in the list.
\newcommand*{\l@appendix}{\@dottedtocline{1}{0em}{2.5em}}

% This sets the formatting of the list of appendices page.
\newcommand*{\listofappendices}{%
 % Move to new page.
 \newpage %
 % Add this page to the table of contents.
 \phantomsection\addcontentsline{toc}{chapter}{List of Appendices} %
 % Anchor for pdf
 \phantomsection %
 % Use front page styling.
 \frntpg %
 % Larger upper margin for first page of table (thesis only)
  \begin{minipage}{0.8\textwidth} \vspace{1in} \end{minipage} \\ %
 % Add the title
 \centerline{\large\bf LIST OF APPENDICES} %
 % Add some space after the title.
 \vspace{1ex} %
 % Start the automatic table of contents features.
 \begin{singlespace} %
  \@starttoc{loa}\if@restonecol\twocolumn\fi %
 \end{singlespace} %
}

% Renew the command that starts the appendices.
\renewcommand{\appendix}{ %
 % Move to new page.
 \clearpage %
 % Renew the counters.
 \renewcommand*{\thechapter}{\Alph{chapter}} %
 % Start over the chapter counter.
 \setcounter{chapter}{0} %
 % Add a pdf anchor.
 \phantomsection %
 % Add the page to the table of contents.
 \addcontentsline{toc}{chapter}{Appendices}
 % Stop adding sections to the table of contents.
 %\addtocontents{toc}{\setcounter{tocdepth}{1}} %
 % Header for appendices.
 \renewcommand{\@chapapp}{APPENDIX} %
 % Renew the chapter and section labels.
 \let\@chapter\@chapter@appendix %
 \let\oldaddcontentsline\addcontentsline% Copy \addcontentsline
 % Force \addcontentsline to ALWAYS add to List of Appendices
 \renewcommand{\addcontentsline}[1]{\oldaddcontentsline{loa}}%
}

% Make a special chapter command for appendices.
\def\@chapter@appendix[#1]#2{ %
 % Increase the chapter letter.
 \refstepcounter{chapter} %
 % Print a line to the .log file.
 \typeout{\@chapapp\space\thechapter.} %
 % Hopefully this works.
 \phantomsection %
 % Add a bookmark manually.
 \pdfbookmark[0]{#1}{#2} %
 % Add to the list of appendices rather than toc.
 \addcontentsline{loa}{chapter}{\protect\numberline{\thechapter}#1} %
 % Save the chapter number.
 \chaptermark{#1} %
}

%% ---- LIST OF TABLES -------------------------------------------------
% This sets the format for the table entries.
\renewcommand*{\l@table}{\@dottedtocline{1}{0em}{2.5em}}

% This sets the formatting of the list of tables page.
\renewcommand*{\listoftables}{%
 % Move to new page.
 \newpage %
 % Add this page to the table of contents.
 \phantomsection\addcontentsline{toc}{chapter}{List of Tables} %
 % Use front page styling.
 \frntpg %
 % Larger upper margin for first page of table
  \begin{minipage}{0.8\textwidth} \vspace{1in} \end{minipage} \\ %
 % Add the title
 \centerline{\large\bf LIST OF TABLES} %
 % Add some space after the title.
 \vspace{1ex} %
 % Start the automatic table of contents features.
 \begin{singlespace} %
  \@starttoc{lot}\if@restonecol\twocolumn\fi %
 \end{singlespace} %
}

%% ---- BIBLIOGRAPHY ---------------------------------------------------
% Save the original bibliography command.
\let\@tex@bibliography\bibliography

% Change the bibliography header.
\renewcommand*{\bibname}{\centerline{\large BIBLIOGRAPHY}}

% Create a new command for the bibliography.
\renewcommand*{\bibliography}[1]{ %
  % Switch to single spacing
  \singlespacing %
 % Move to new page.
 \clearpage %
 % Create a pdf anchor.
 \phantomsection %
 % Add to table of contents.
 \addcontentsline{toc}{chapter}{Bibliography} %
 % Load the bibliography.
 \@tex@bibliography{#1} %
}
%
%% ---- LINKS ----------------------------------------------------------
% This loads a package that allows extra colors for links.
\RequirePackage[usenames,dvipsnames]{color}
\RequirePackage[pagebackref=true]{hyperref}
 \hypersetup{%
  colorlinks=true, %
  pdfstartview={FitH}, %
  citecolor=DarkGreen, %
  linkcolor=Black, %
  urlcolor=Blue %
 }

%% ---- INITIALIZATION -------------------------------------------------
% Commands to be placed after \begin{document}
\AtBeginDocument{ %
 % Insert the table of contents.
 \tableofcontents %
 \listoftables
 % Insert the list of appendices.
 \listofappendices
 \newpage %
}

文本:

\documentclass{style}

%% DOCUMENT AREA
\begin{document}


\chapter{First Chapter}

\chapter{Second Chapter}

\section{First Section}

\section{Second Section}

\subsection{First Subsection}


\subsection{Second Subsection}


\subsection{Third Subsection}


\subsection{Fourth Subsection}

\subsection{Fifth Subsection}

\section{Third Section}

\subsection{First Subsection}


\subsection{Second Subsection}


\subsection{Third Subsection}

\subsection{Fourth Subsection}

\chapter{Third Chapter}

\begin{table}[!hbt]
  \centering
  \caption{Dimensions.}
  \footnotesize
  \begin{tabular}{lr}
  \hline
    Length & 152.4 mm \\
    Width &  12.7 mm\\
    Thickness &  3.0 mm\\
  \hline
  \end{tabular}
\end{table}

\section{First Section}

\section{Second Section}

\appendix
\chapter{First Chapter of Appendices}

\section{First Section of Appendices}

\section{Second Section of Appendices}

\chapter{Second Chapter of Appendices}

\section{First Section of Appendices}

\section{Second Section of Appendices}

\begin{table}[!hbt]
  \centering
  \caption{Dimensions.}
  \footnotesize
  \begin{tabular}{lr}
  \hline
    Length & 152.4 mm \\
    Width &  12.7 mm\\
    Thickness &  3.0 mm\\
  \hline
  \end{tabular}
\end{table}

\chapter{Third Chapter of Appendices}

\begin{table}[!hbt]
  \centering
  \caption{Dimensions.}
  \footnotesize
  \begin{tabular}{lr}
  \hline
    Length & 152.4 mm \\
    Width &  12.7 mm\\
    Thickness &  3.0 mm\\
  \hline
  \end{tabular}
\end{table}

\bibliographystyle{aiaa}
% Give this command the relative path to the .bib file.
\bibliography{tex.bib}
\end{document}

答案1

关于您的宏,我相信这是阻止显示部分标题的部分;

% Stop adding sections to the table of contents.
\addtocontents{toc}{\setcounter{tocdepth}{1}} %

更改这里的数字应该可以让你更好地控制目录的深度;

\addtocontents{toc}{\setcounter{tocdepth}{2}}

将给出附录章节和部分标题。

.tex 文件的 MWE 示例将会提供更多帮助。

您不应该需要该宏,因为它似乎会导致您不想要的格式问题,下面的代码应该为您提供所需的输出(尽管任何小节标题也将被括起来,但\subsection*{#}可以缓解这个问题);

\documentclass[10pt]{book}

\begin{document}

\tableofcontents

\appendix

\chapter{Appendix 1}
\section{Appendix 1 Section 1}
\subsection{Appendix 1 Subsection 1}

\section{Appendix 2 Section 2}
\subsection{Appendix 2 Subsection 1}

\end{document}

这使;

附录表

答案2

在 的定义结束时\appendix,我们想改变元素写入目录的方式。事实上,我们希望将它们写入 ToC,而不是写入 LoA(附录列表)。我们可以通过在当前定义末尾添加这段代码来强制执行此操作:

\let\oldaddcontentsline\addcontentsline% Copy \addcontentsline
% Force \addcontentsline to ALWAYS add to List of Appendices
\renewcommand{\addcontentsline}[1]{\oldaddcontentsline{loa}}%

以上代码复制了 的原始定义\addcontentsline并将其覆盖为类似于\addcontentsline{loa},无论您使用\addcontentsline{toc}还是其他方式调用它。这确保了通常会出现在 ToC 中的所有内容现在都会出现在 LoA 中。

其次,由于没有什么之后\appendix将进入目录,我们可以删除

% Stop adding sections to the table of contents.
\addtocontents{toc}{\setcounter{tocdepth}{1}}

因为它现在是多余的。上面的代码实际上改变了节级及以下的所有 ToC 相关条目,使其从 ToC 相关内容中排除。因此保留它必然会避免\section在 LoA 中打印 s。

\listofappendices以下是针对和 的更新说明\appendix

% This sets the formatting of the list of appendices page.
\newcommand*{\listofappendices}{%
 % Move to new page.
 \newpage %
 % Add this page to the table of contents.
 \phantomsection\addcontentsline{toc}{chapter}{List of Appendices} %
 % Anchor for pdf
 \phantomsection %
 % Use front page styling.
 \frntpg %
 % Larger upper margin for first page of table (thesis only)
  \begin{minipage}{0.8\textwidth} \vspace{1in} \end{minipage} \\ %
 % Add the title
 \centerline{\large\bf LIST OF APPENDICES} %
 % Add some space after the title.
 \vspace{1ex} %
 % Start the automatic table of contents features.
 \begin{singlespace} %
  \@starttoc{loa}\if@restonecol\twocolumn\fi %
 \end{singlespace} %
}

% Renew the command that starts the appendices.
\renewcommand{\appendix}{ %
 % Move to new page.
 \clearpage %
 % Renew the counters.
 \renewcommand*{\thechapter}{\Alph{chapter}} %
 % Start over the chapter counter.
 \setcounter{chapter}{0} %
 % Add a pdf anchor.
 \phantomsection %
 % Add the page to the table of contents.
 \addcontentsline{toc}{chapter}{Appendices}
 % Header for appendices.
 \renewcommand{\@chapapp}{APPENDIX} %
 % Renew the chapter and section labels.
 \let\@chapter\@chapter@appendix %
 \let\oldaddcontentsline\addcontentsline% Copy \addcontentsline
 % Force \addcontentsline to ALWAYS add to List of Appendices
 \renewcommand{\addcontentsline}[1]{\oldaddcontentsline{loa}}%
}

在此处输入图片描述

您的定义\l@appendix没有任何作用。

相关内容