目录中章节级别的附录

目录中章节级别的附录

我希望我的附录出现在目录中的节级而不是章级。

像这样:

    Appendices
        A  My appendix 1 . . . . . . .
        B  My appendix 2 . . . . . . .

我已尝试过,\settocdepth但是没有用。

我的代码:

    \documentclass[11pt,a4paper]{report}
    \usepackage[english]{babel}     % english language
    \usepackage[latin1]{inputenc}   % accents in source
    \usepackage[T1]{fontenc}        % accents in DVI
    \usepackage{color}              % add color to the text
    \definecolor{bluekeywords}{rgb}{0.13,0.13,1}
    \definecolor{greencomments}{rgb}{0,0.5,0}
    \definecolor{redstrings}{rgb}{0.9,0,0}

    \usepackage{graphicx}           % images in the document
    \usepackage{float}              % containers
    \usepackage{wrapfig}            % wrap text around figure

    \usepackage{vmargin}            % redefine the margins
    \setmarginsrb{2.5cm}{1.5cm}{2.5cm}{1cm}{0cm}{0cm}{0cm}{1cm}

    \usepackage[
    hyperindex=true, % add links in the index
    bookmarks=true,  % show bookmarks bar when displaying the document}{hyperref}
    ]{hyperref}
    \hypersetup{
    colorlinks=true, % colored links
    breaklinks=true, % allows return line in too long links
    urlcolor= blue,  % links color
    linkcolor= blue, % internal links color
    citecolor= blue, % green by defaut, color of citation links (bibliography)
    bookmarksopen=true,
    pdftitle={Cloud 3D Teapot},
    pdfauthor={Jos\'{e} L\'{o}pez C\'{i}vico},
    pdfsubject={Cloud Latency}
    }

    \usepackage{listings}
    \lstset{
    basicstyle=\footnotesize,       % code font size
    numbers=left,                   % place of numbers
    numberstyle=\normalsize,        % numbers font size
    numbersep=7pt,                  % distance between code and its numeration
    backgroundcolor=\color{white},  % background color
    }

    \lstdefinestyle{CSharp}{
      language=[Sharp]C,
      showspaces=false,
      showtabs=false,
      breaklines=true,
      showstringspaces=false,
      breakatwhitespace=true,
      escapeinside={(*@}{@*)},
      commentstyle=\color{greencomments},
      keywordstyle=\color{bluekeywords},
      stringstyle=\color{redstrings},
      basicstyle=\ttfamily
    }

    \lstdefinestyle{XMLc}{
      language=XML,
      showspaces=false,
      showtabs=false,
      breaklines=true,
      showstringspaces=false,
      breakatwhitespace=true,
      stringstyle=\color{bluekeywords},
      keywordstyle=\color{redstrings},
      morekeywords={name, connectionString, providerName},
      commentstyle=\color{greencomments},
      basicstyle=\ttfamily
    }

    \usepackage{titlepic}
    \usepackage{appendix}

    \usepackage{makeidx}
    \usepackage{lmodern}
    \usepackage{kpfonts}

    \begin{document}

    \tableofcontents
    \newpage

    \listoffigures
    \newpage

    \chapter{Test Chapter}
    \section{A Regular Section}

\appendix
\clearpage % or \cleardoublepage
\appendixpage
\addappheadtotoc
% code to show appendices at section level in TOC
\begin{appendices}
    \chapter{Installation requirements}
\chapter{Acronyms}
\end{appendices}

    \end{document}

答案1

更新:使用的文档类是report,因此现在具有实际设置的解决方案是:

\documentclass[11pt,a4paper]{report}
\usepackage[english]{babel}     % english language
\usepackage[latin1]{inputenc}   % accents in source
\usepackage[T1]{fontenc}        % accents in DVI
\usepackage{color}              % add color to the text
\definecolor{bluekeywords}{rgb}{0.13,0.13,1}
\definecolor{greencomments}{rgb}{0,0.5,0}
\definecolor{redstrings}{rgb}{0.9,0,0}

\usepackage{graphicx}           % images in the document
\usepackage{float}              % containers
\usepackage{wrapfig}            % wrap text around figure

\usepackage{vmargin}            % redefine the margins
\setmarginsrb{2.5cm}{1.5cm}{2.5cm}{1cm}{0cm}{0cm}{0cm}{1cm}

\usepackage{listings}
\lstset{
    basicstyle=\footnotesize,       % code font size
    numbers=left,                   % place of numbers
    numberstyle=\normalsize,        % numbers font size
    numbersep=7pt,                  % distance between code and its numeration
    backgroundcolor=\color{white},  % background color
 }

\lstdefinestyle{CSharp}{
      language=[Sharp]C,
      showspaces=false,
      showtabs=false,
      breaklines=true,
      showstringspaces=false,
      breakatwhitespace=true,
      escapeinside={(*@}{@*)},
      commentstyle=\color{greencomments},
      keywordstyle=\color{bluekeywords},
      stringstyle=\color{redstrings},
      basicstyle=\ttfamily
}

\lstdefinestyle{XMLc}{
      language=XML,
      showspaces=false,
      showtabs=false,
      breaklines=true,
      showstringspaces=false,
      breakatwhitespace=true,
      stringstyle=\color{bluekeywords},
      keywordstyle=\color{redstrings},
      morekeywords={name, connectionString, providerName},
      commentstyle=\color{greencomments},
      basicstyle=\ttfamily
}

\usepackage{titlepic}
\usepackage{appendix}

\usepackage{makeidx}
\usepackage{lmodern}
\usepackage{kpfonts}

\usepackage[
    hyperindex=true, % add links in the index
    bookmarks=true,  % show bookmarks bar when displaying the document}{hyperref}
    ]{hyperref}
\hypersetup{
    colorlinks=true, % colored links
    breaklinks=true, % allows return line in too long links
    urlcolor= blue,  % links color
    linkcolor= blue, % internal links color
    citecolor= blue, % green by defaut, color of citation links (bibliography)
    bookmarksopen=true,
    pdftitle={Cloud 3D Teapot},
    pdfauthor={Jos\'{e} L\'{o}pez C\'{i}vico},
    pdfsubject={Cloud Latency}
}

\makeatletter
\newcommand\chapassect{%
\def\@chapter[##1]##2{\ifnum \c@secnumdepth >\m@ne
                         \refstepcounter{chapter}%
                         \typeout{\@chapapp\space\thechapter.}%
                         \addcontentsline{toc}{section}%
                                   {\protect\numberline{\thechapter}##1}%
                    \else
                      \addcontentsline{toc}{section}{##1}%
                    \fi
                    \chaptermark{##1}%
                    \addtocontents{lof}{\protect\addvspace{10\p@}}%
                    \addtocontents{lot}{\protect\addvspace{10\p@}}%
                    \if@twocolumn
                      \@topnewpage[\@makechapterhead{##2}]%
                    \else
                      \@makechapterhead{##2}%
                      \@afterheading
                    \fi}%
}
\makeatother

    \begin{document}

    \tableofcontents
    \newpage

    \listoffigures
    \newpage

    \chapter{Test Chapter}
    \section{A Regular Section}

\appendix
\clearpage % or \cleardoublepage
\appendixpage
\addappheadtotoc
% code to show appendices at section level in TOC
\chapassect
\begin{appendices}
\chapter{Installation requirements}
\chapter{Acronyms}
\end{appendices}

\end{document}

在此处输入图片描述

我移动了hyperref包并最后加载它(除了一些有据可查的例外情况,这应该始终这样做)。

这是一个选择;appendix包用于在目录中的附录之前包含“附录”,并且titletoc包用于改变环境中目录中章节条目的排版方式appendix

\documentclass{book}
\usepackage{appendix}
\usepackage{titletoc}

\begin{document}

\tableofcontents
\chapter{Test Chapter}
\section{A Regular Section}

\begin{appendix}
\addappheadtotoc
\titlecontents{chapter}
  [3.8em]
  {}{\contentslabel{2.3em}}
  {\hspace*{-2.3em}}
  {\titlerule*[0.7em]{.}\contentspage}
\chapter{Test Appendix One}
\chapter{Test Appendix Two}
\end{appendix}

\end{document}

在此处输入图片描述

在上面的解决方案中,我假设附录将使用 构建\chapter,并且只需要更改目录中的条目;如果目的是使用\section来排版附录,那么使用包subappendices中的环境appendix并重新定义就足够了\setthesection

\documentclass{book}
\usepackage{appendix}

\renewcommand\setthesection{\Alph{section}} 

\begin{document}

\tableofcontents
\chapter{Test Chapter}
\section{A Regular Section}

\addappheadtotoc
\begin{subappendices}
\section{Test Appendix One}
\section{Test Appendix Two}
\end{subappendices}

\end{document}

在此处输入图片描述

因为根据评论,该hyperref包正在被使用,所以该titletoc解决方案不会完全有效,因为这两个包不能很好地交互;在这种情况下,必须做一些额外的工作:

\documentclass{book}
\usepackage{appendix}
\usepackage[colorlinks=true,linkcolor=blue]{hyperref}

\makeatletter
\newcommand\chapassect{%
\def\@chapter[##1]##2{\ifnum \c@secnumdepth >\m@ne
                       \if@mainmatter
                         \refstepcounter{chapter}%
                         \typeout{\@chapapp\space\thechapter.}%
                         \addcontentsline{toc}{section}%
                                   {\protect\numberline{\thechapter}##1}%
                       \else
                         \addcontentsline{toc}{section}{##1}%
                       \fi
                    \else
                      \addcontentsline{toc}{section}{##1}%
                    \fi
                    \chaptermark{##1}%
                    \addtocontents{lof}{\protect\addvspace{10\p@}}%
                    \addtocontents{lot}{\protect\addvspace{10\p@}}%
                    \if@twocolumn
                      \@topnewpage[\@makechapterhead{##2}]%
                    \else
                      \@makechapterhead{##2}%
                      \@afterheading
                    \fi}%
}
\makeatother

\begin{document}

\tableofcontents
\chapter{Test Chapter}
\section{A Regular Section}

\begin{appendix}
\addappheadtotoc
\chapassect
\chapter{Test Appendix One}
\chapter{Test Appendix Two}
\end{appendix}

\end{document}

在此处输入图片描述

上面的代码假设了book文档类;经过注释后,似乎没有使用这个类,但不幸的是注释中没有提到实际的文档类;但是,考虑到 OP 在尝试实现我的最后一个建议后获得的错误消息,我的水晶球告诉我文档类可能是amsbook。在这种情况下,必要的重新定义甚至更简单:

\documentclass{amsbook}
\usepackage{appendix}
\usepackage[colorlinks=true,linkcolor=blue]{hyperref}

\makeatletter
\def\@chapter[#1]#2{\refstepcounter{chapter}%
  \ifnum\c@secnumdepth<\z@ \let\@secnumber\@empty
  \else \let\@secnumber\thechapter \fi
  \typeout{\chaptername\space\@secnumber}%
  \def\@toclevel{0}%
  \ifx\chaptername\appendixname \@tocwriteb\tocappendix{section}{#2}%
  \else \@tocwriteb\tocchapter{chapter}{#2}\fi
  \chaptermark{#1}%
  \addtocontents{lof}{\protect\addvspace{10\p@}}%
  \addtocontents{lot}{\protect\addvspace{10\p@}}%
  \@makechapterhead{#2}\@afterheading}%
\makeatother

\begin{document}

\tableofcontents
\chapter{Test Chapter}
\section{A Regular Section}

\begin{appendix}
\addappheadtotoc
\chapter{Test Appendix One}
\chapter{Test Appendix Two}
\end{appendix}

\end{document}

在此处输入图片描述

相关内容