我正在使用 Overleaf 中的 pdfLaTeX 编译器创建一个用于 Report 文档类的模板。我遇到的最后一个问题是让附录的目录看起来具有特定的外观。我有很多特定的格式,尤其是在% format headers
下面% format table of contents
的示例中,我认为这些格式可以控制外观,但我对 LaTeX 还不熟悉,不知道如何解开它。
目前的样子如下:
我想要更改以下内容:
- 删除子部分。我试过了
\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
,就像我的[MRE]中注释掉的那样https://stackoverflow.com/help/minimal-reproducible-example),但删除了我的图表列表页面上的图表。 - 将黄色突出显示改为“附录 A 我的第一个附录的名称 ..... #”(和“附录 B Foo ..... #”),全部大写。缩进应与“参考文献”相同。此外,附录必须位于参考文献之后。
这是生成 10 页 PDF 的代码。
%-------------------------------------------------------
% Dummy Chapter 1
\begin{filecontents*}[overwrite]{ChapterA.tex}
\chapter{Introduction}
\lipsum[1]
\section{Section Name}
Here is some text, see Figure \ref{fig:a}.
\begin{figure}
\centering
\includegraphics[width = 0.5\textwidth]{example-image-a}
\caption{An example figure.}
\label{fig:a}
\end{figure}
\subsection{Subsection Name}
Here is a subsection, see \cite{einstein1906new}.
\end{filecontents*}
%-------------------------------------------------------
% Dummy Abstract
\begin{filecontents*}[overwrite]{Abstract.tex}
\cleardoublepage
\addcontentsline{toc}{chapter}{Abstract}
\begin{center}
\fontsize{18pt}{0pt}\selectfont\MakeUppercase{\textbf{abstract}}
\end{center}
\vspace*{24pt}
This is the abstract.
\end{filecontents*}
%-------------------------------------------------------
% Dummy Appendix A
\begin{filecontents*}[overwrite]{AppendixA.tex}
\begin{center}
\vspace*{60pt}
{\fontsize{18pt}{0pt} \MakeUppercase{\textbf{Appendix A}}} \\
\vspace*{24pt}
{\fontsize{18pt}{0pt} \MakeUppercase{\textbf{The name of my first appendix}}}
\vspace*{100pt}
\end{center}
\thispagestyle{empty}
\appendix
\chapter{The name of my first appendix}
\lipsum[1]
\section{A section in my appendix}
Here is some text, see Figure \ref{fig:b}.
\begin{figure}
\centering
\includegraphics[width = 0.5\textwidth]{example-image-b}
\caption{An example figure.}
\label{fig:b}
\end{figure}
\subsection{A subsection in my appendix}
Here is a subsection.
\end{filecontents*}
%-------------------------------------------------------
% Dummy References
\begin{filecontents*}{refs.bib}
@article{einstein1906new,
title={A new determination of molecular dimensions},
author={Einstein, Albert},
journal={Ann. Phys.},
volume={19},
pages={289--306},
year={1906}
}
\end{filecontents*}
%-------------------------------------------------------
% Preamble
\documentclass[12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{nameref}
\usepackage{mathtools}
\usepackage{amsmath, amsthm, amssymb, amsfonts}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{threeparttable}
\usepackage{subcaption}
\usepackage{natbib}
\usepackage{appendix}
\usepackage{lipsum}
% set page & paragraph dimensions
\usepackage[letterpaper, margin=1in]{geometry}
\setlength{\parindent}{0.5in}
\setlength{\parskip}{6pt}
% set font
\usepackage[sfdefault]{carlito}
% set-up frontmatter, mainmatter, backmatter
\makeatletter
\newcommand\frontmatter{
\cleardoublepage
\pagenumbering{roman}}
\newcommand\mainmatter{
\cleardoublepage
\pagenumbering{arabic}}
\newcommand\backmatter{
\if@openright
\cleardoublepage
\else
\clearpage
\fi
}
\makeatother
% format headers
\usepackage{titlesec}
\newcommand{\chapterjustification}{}
\newcommand{\chapterfont}{\normalfont}
\newcommand{\chapterfontsize}{\fontsize{22pt}{0pt}\selectfont}
\titleformat{\chapter}%
{\chapterjustification\chapterfont\chapterfontsize\bfseries\MakeUppercase}%
{\thechapter}{0.5in}{}
\titlespacing*{\chapter}{0pt}{80pt}{40pt}
\titleformat{\section}%
{\normalfont\fontsize{14pt}{0pt}\selectfont\bfseries\MakeUppercase}%
{\thesection}{0.5in}{}
\titlespacing*{\section}{0pt}{24pt}{12pt}
\titleformat{\subsection}%
{\normalfont\fontsize{14pt}{0pt}\selectfont\bfseries}%
{\thesubsection}{0.5in}{}
\titlespacing*{\subsection}{0pt}{18pt}{12pt}
% format references fonts, etc.
\AtBeginEnvironment{thebibliography}{%
\titleformat{\chapter}%
{\normalfont\fontsize{14pt}{0pt}\bfseries\filcenter}%
{\thechapter}{0.5in}{\MakeUppercase}%
\titlespacing*{\chapter}{0pt}{0pt}{12pt}
}
\renewcommand{\bibname}{References}
\AddToHook{cmd/bibsection/after}{%
\addcontentsline{toc}{chapter}{\bibname}%
}
\def\bibfont{\fontsize{11pt}{0pt}\selectfont\hyphenpenalty=10000}
% format table of contents
\usepackage{titletoc}
\contentsmargin{0.2in}
\titlecontents{chapter}[0.5in]{%
\addvspace{12pt}\bfseries}{%
\contentslabel{0.5in}\MakeUppercase}{%
\hspace*{-0.5in}\MakeUppercase}{%
\titlerule*[0.5pc]{.}\contentspage} % dot density
\titlecontents{section}[1in]{\bfseries}{%
\contentslabel{0.5in}\MakeUppercase}{%
\hspace*{-1in}\MakeUppercase}{%
\titlerule*[0.5pc]{.}\contentspage}
\titlecontents{subsection}[1.5in]{\selectfont}{%
\contentslabel{0.5in}}{%
\hspace*{-1in}}{%
\titlerule*[0.5pc]{.}\contentspage}
\newcommand{\insertTOC}{\begingroup
\cleardoublepage
\addcontentsline{toc}{chapter}{Contents}
\renewcommand{\chapterjustification}{\centering}
\renewcommand{\chapterfontsize}{\fontsize{16pt}{0pt}\selectfont}
\titlespacing*{\chapter}{0pt}{0pt}{24pt}
\tableofcontents
\endgroup}
% format list of figures & list of tables pages
\newcommand{\insertLOF}{\begingroup
\cleardoublepage
\addcontentsline{toc}{chapter}{List of Figures}
\renewcommand{\chapterjustification}{\centering}
\renewcommand{\chapterfontsize}{\fontsize{16pt}{0pt}\selectfont}
\titlespacing*{\chapter}{0pt}{0pt}{24pt}
{\let\oldnumberline\numberline %
\renewcommand{\numberline}{\figurename~\oldnumberline} %
\listoffigures}
\endgroup}
\newcommand{\insertLOT}{\begingroup
\cleardoublepage
\addcontentsline{toc}{chapter}{List of Tables}
\renewcommand{\chapterjustification}{\centering}
\renewcommand{\chapterfontsize}{\fontsize{16pt}{0pt}\selectfont}
\titlespacing*{\chapter}{0pt}{0pt}{24pt}
{\let\oldnumberline\numberline %
\renewcommand{\numberline}{\tablename~\oldnumberline} %
\listoftables}
\endgroup}
% load hyperref last to minimize conflicts
\usepackage{xcolor}
\usepackage[linktocpage=true]{hyperref}
\hypersetup{colorlinks=true, linkcolor=blue, citecolor=blue}
%-------------------------------------------------------
\begin{document}
\frontmatter
\include{Abstract}
\insertTOC
\insertLOF
\insertLOT
\mainmatter
\include{ChapterA}
\backmatter
\bibliographystyle{plain}
\bibliography{refs}
\begin{appendices}
% \addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
% this removes the list of figures
\include{AppendixA}
\end{appendices}
\end{document}
%-------------------------------------------------------
答案1
更改的位置tocdepth
不应放在任何地方;它应该放在 ToC 中的适当位置,从那里开始您希望应用更改。就您而言,在您调用
\chapter{我的第一个附录的名称}
因此,\section
此之后的\chapter
不会出现在目录中。简而言之,在 内AppendixA.tex
。
对于APPENDIX
附录章节的前缀,也可以这样做。我已将 添加\chapterprefix
到您的设置中(最初为空白),该设置将在 内更新AppendixA.tex
。
%-------------------------------------------------------
% Dummy Chapter 1
\begin{filecontents*}[overwrite]{ChapterA.tex}
\chapter{Introduction}
\lipsum[1]
\section{Section Name}
Here is some text, see Figure \ref{fig:a}.
\begin{figure}
\centering
\includegraphics[width = 0.5\textwidth]{example-image-a}
\caption{An example figure.}
\label{fig:a}
\end{figure}
\subsection{Subsection Name}
Here is a subsection.
\end{filecontents*}
%-------------------------------------------------------
% Dummy Abstract
\begin{filecontents*}[overwrite]{Abstract.tex}
\cleardoublepage
\addcontentsline{toc}{chapter}{Abstract}
\begin{center}
\fontsize{18pt}{0pt}\selectfont\MakeUppercase{\textbf{abstract}}
\end{center}
\vspace*{24pt}
This is the abstract.
\end{filecontents*}
%-------------------------------------------------------
% Dummy Appendix A
\begin{filecontents*}[overwrite]{AppendixA.tex}
\begin{center}
\vspace*{60pt}
{\fontsize{18pt}{0pt} \MakeUppercase{\textbf{Appendix A}}} \\
\vspace*{24pt}
{\fontsize{18pt}{0pt} \MakeUppercase{\textbf{The name of my first appendix}}}
\vspace*{100pt}
\end{center}
\thispagestyle{empty}
\appendix
\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}% Only show up to \chapter in ToC from this point forward
\addtocontents{toc}{\protect\renewcommand{\protect\chapterprefix}{\protect\hspace*{-0.5in}APPENDIX\protect\hspace*{0.6in}}}%
\chapter{The name of my first appendix}
\lipsum[1]
\section{A section in my appendix}
Here is some text, see Figure \ref{fig:b}.
\begin{figure}
\centering
\includegraphics[width = 0.5\textwidth]{example-image-b}
\caption{An example figure.}
\label{fig:b}
\end{figure}
\subsection{A subsection in my appendix}
Here is a subsection.
\end{filecontents*}
%-------------------------------------------------------
% Preamble
\documentclass[12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{nameref}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage{appendix}
\usepackage{lipsum}
% set page & paragraph dimensions
\usepackage[letterpaper, margin=1in]{geometry}
\setlength{\parindent}{0.5in}
\setlength{\parskip}{6pt}
% set font
\usepackage[sfdefault]{carlito}
% set-up frontmatter, mainmatter, backmatter
\makeatletter
\newcommand\frontmatter{
\cleardoublepage
\pagenumbering{roman}}
\newcommand\mainmatter{
\cleardoublepage
\pagenumbering{arabic}}
\newcommand\backmatter{
\if@openright
\cleardoublepage
\else
\clearpage
\fi
}
\makeatother
% format headers
\usepackage{titlesec}
\newcommand{\chapterjustification}{}
\newcommand{\chapterfont}{\normalfont}
\newcommand{\chapterfontsize}{\fontsize{22pt}{0pt}\selectfont}
\titleformat{\chapter}%
{\chapterjustification\chapterfont\chapterfontsize\bfseries\MakeUppercase}%
{\thechapter}{0.5in}{}
\titlespacing*{\chapter}{0pt}{80pt}{40pt}
\titleformat{\section}%
{\normalfont\fontsize{14pt}{0pt}\selectfont\bfseries\MakeUppercase}%
{\thesection}{0.5in}{}
\titlespacing*{\section}{0pt}{24pt}{12pt}
\titleformat{\subsection}%
{\normalfont\fontsize{14pt}{0pt}\selectfont\bfseries}%
{\thesubsection}{0.5in}{}
\titlespacing*{\subsection}{0pt}{18pt}{12pt}
% format table of contents
\usepackage{titletoc}
\contentsmargin{0.2in}
\newcommand{\chapterprefix}{}
\titlecontents{chapter}[0.5in]{%
\addvspace{12pt}\bfseries}{%
\chapterprefix\contentslabel{0.5in}\MakeUppercase}{%
\hspace*{-0.5in}\MakeUppercase}{%
\titlerule*[0.5pc]{.}\contentspage} % dot density
\titlecontents{section}[1in]{\bfseries}{%
\contentslabel{0.5in}\MakeUppercase}{%
\hspace*{-1in}\MakeUppercase}{%
\titlerule*[0.5pc]{.}\contentspage}
\titlecontents{subsection}[1.5in]{\selectfont}{%
\contentslabel{0.5in}}{%
\hspace*{-1in}}{%
\titlerule*[0.5pc]{.}\contentspage}
\newcommand{\insertTOC}{\begingroup
\cleardoublepage
\addcontentsline{toc}{chapter}{Contents}
\renewcommand{\chapterjustification}{\centering}
\renewcommand{\chapterfontsize}{\fontsize{16pt}{0pt}\selectfont}
\titlespacing*{\chapter}{0pt}{0pt}{24pt}
\tableofcontents
\endgroup}
% format list of figures & list of tables pages
\newcommand{\insertLOF}{\begingroup
\cleardoublepage
\addcontentsline{toc}{chapter}{List of Figures}
\renewcommand{\chapterjustification}{\centering}
\renewcommand{\chapterfontsize}{\fontsize{16pt}{0pt}\selectfont}
\titlespacing*{\chapter}{0pt}{0pt}{24pt}
{\let\oldnumberline\numberline %
\renewcommand{\numberline}{\figurename~\oldnumberline} %
\listoffigures}
\endgroup}
\newcommand{\insertLOT}{\begingroup
\cleardoublepage
\addcontentsline{toc}{chapter}{List of Tables}
\renewcommand{\chapterjustification}{\centering}
\renewcommand{\chapterfontsize}{\fontsize{16pt}{0pt}\selectfont}
\titlespacing*{\chapter}{0pt}{0pt}{24pt}
{\let\oldnumberline\numberline %
\renewcommand{\numberline}{\tablename~\oldnumberline} %
\listoftables}
\endgroup}
% load hyperref last to minimize conflicts
\usepackage{xcolor}
\usepackage[linktocpage=true]{hyperref}
\hypersetup{colorlinks=true, linkcolor=blue, citecolor=blue}
%-------------------------------------------------------
\begin{document}
\frontmatter
\include{Abstract}
\insertTOC
\insertLOF
\insertLOT
\mainmatter
\include{ChapterA}
\backmatter
\begin{appendices}
% \addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
% this removes the list of figures
\include{AppendixA}
\end{appendices}
\end{document}