我正在使用 Overleaf 中的 pdfLaTeX 编译器创建一个用于报告文档类的模板。
有很多格式细节,但我认为我已经在下面的代码中最低限度地重现了它们。
我对格式化目录有五个问题;我认为它们都是相关的,所以我将它们归类在同一篇文章中:
- 如何将“Contents”一词居中、大写,并指定字体大小?我目前正在做的
\renewcommand{\contentsname}{\centering\fontsize{18pt}{0pt}\MakeUppercase{\textbf{contents}}}
,它不应用居中,并且根据答案,这是一种不好的做法这里和这里。我明白为什么这是不好的做法,但我不明白正确的做法。(我打算应用它以使“图片列表”标题具有相同的格式。) - 目录中的大部分内容目前都以粗体显示,我很喜欢这一点。我怎样才能将目录中的部分(而不是子部分)也设为粗体?
- 我怎样才能将章节标题和节(但不将小节)全部大写?
- 如何在目录中的摘要、图表列表等处添加与其他点格式(间距)相同的页码点?我可以让所有点更密集吗?(以满足 Word 模板要求)
\addcontentsline{toc}{chapter}{\MakeUppercase{Table of Contents}}
在这个独立示例中使用效果很好,但出于某种原因,它在我的真实模板中引发了错误。它编译正确,但我想消除错误。我找不到导致它的任何差异。错误:Undefined control sequence. The compiler is having trouble understanding a command you have used. Check that the command is spelled correctly. If the command is part of a package, make sure you have included the package in your preamble using \usepackage{...}. Learn more **\MakeUppercase ...ppercaseUnsupportedInPdfStrings** The control sequence at the end of the top line of your error message was never \def'ed. If you have misspelled it (e.g., \hobx'), type I' and the correct spelling (e.g., I\hbox'). Otherwise just continue, and I'll forget about whatever was undefined.
根据答案这里,我想我需要使用\texorpdfstring{}
,但我尝试了一些组合,但它们没有编译。
%-------------------------------------------------------
% Dummy Chapter 1
\begin{filecontents*}{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*}{Abstract.tex}
\begin{center}
{\fontsize{18pt}{0pt}\MakeUppercase{\textbf{abstract}}}
\vspace*{24pt}
\end{center}
\addcontentsline{toc}{chapter}{\MakeUppercase{Abstract}}
This is the abstract.
\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{graphicx}
\usepackage{natbib}
\usepackage{lipsum}
% set page and paragraph dimensions
\setlength{\parindent}{0.5in}
\setlength{\parskip}{6pt}
% set report font
\usepackage[sfdefault]{carlito}
% format headers
\usepackage{titlesec}
\titleformat{\chapter}%
{\normalfont\fontsize{22pt}{0pt}\bfseries}%
{\thechapter}{0.5in}{}
\titlespacing*{\chapter}{0pt}{80pt}{40pt}
\titleformat{\section}%
{\normalfont\fontsize{14pt}{0pt}\bfseries}%
{\thesection}{0.5in}{\MakeUppercase}
\titlespacing*{\section}{0pt}{24pt}{12pt}
\titleformat{\subsection}%
{\normalfont\fontsize{14pt}{0pt}\bfseries}%
{\thesubsection}{0.5in}{}
\titlespacing*{\subsection}{0pt}{18pt}{12pt}
% 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 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 TOC
\renewcommand{\contentsname}{%
\centering\fontsize{18pt}{0pt}%
\MakeUppercase{\textbf{contents}}}
%-------------------------------------------------------
% Begin
\begin{document}
\title{test}
\author{none}
\date{\today}
\frontmatter
\include{Title}
\include{Abstract}
\tableofcontents
\addcontentsline{toc}{chapter}{Contents}
\listoffigures
\addcontentsline{toc}{chapter}{List of Figures}
\mainmatter
\include{ChapterA}
\backmatter
\bibliographystyle{abbrvnat}
\bibliography{refs}
\end{document}
%-------------------------------------------------------
答案1
目录与其他目录一样
\chapter*
。因此,如果您希望格式与常规章节布局不同,则必须适应这一点。在某些情况下,\contentsname
根据自己的喜好进行调整就足够了,但由于您使用的是titlesec
情况可能并非如此。相反,我添加了参数,以便您可以即时更改对齐方式:\chapterjustification
(默认值为无,但可以更改为,例如\centering
)\chapterfont
(默认为\normalfont
)\chapterfontsize
(默认为\fontsize{22pt}{0pt}\selectfont
)
您可以使用互补的
titletoc
包来格式化与目录相关的条目。具体来说,使用\dottedcontents
(对于需要带点目录条目的分段单元)或\titlecontents
更通用的定义。\dottedcontents{<section>}[<left>]{<above-code>}{<label width>}{<leader width>}
因为你想要虚线所以我就用它了。最好
<section>
明确定义每个条目类型(),否则它将采用该文档类的默认格式。您需要使用更通用的并将
\titlecontents{<section>}[<left>]{<above-code>}{<numbered-entry-format>}{<numberless-entry-format>}{<filler-page-format>}[<below-code>]
的适当位置作为和\MakeUppercase
的最后一个参数。<numbered-entry-format>
<numberless-entry-format>
这是通过使用
\dottedcontents
(或通过使用 时\titlerule
指定)自然实现的。您可以将测量值调整为您想要的任何值(例如,)。.
\titlecontents
1pc
5pt
如果不查看实际文档,很难测试这一点。不过,下面的最小示例会自动格式化目录和文本条目,因此无需专门传递格式化元素,例如
\MakeUppercase
。
普通的留言:
当您使用时
\fontsize{<size>}{<baselineskip}
,您还必须发出命令\selectfont
才能使用该特定的字体参数。使用
\listoffigures \addcontentsline{toc}{chapter}{List of Figures}
不会实现你想要的,因为
\addcontentsline
将插入List of Figures
(toc
格式化为chapter
)指向最后的LoF 的页面。为什么?\listoffigures
将设置 LoF,在调用之前它可能跨越多个页面\addcontentsline
。解决这个问题的方法是强制适当的分页符(通过
\cleardoublepage
),然后发出内容添加宏(不打印任何内容),然后发出打印机制:\cleardoublepage \addcontentsline{toc}{chapter}{List of Figures} \listoffigures
以下是完整的最小示例:
%-------------------------------------------------------
% 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*}
%-------------------------------------------------------
% Preamble
\documentclass[12pt]{report}
\usepackage{graphicx}
\usepackage{lipsum}
% set page and paragraph dimensions
\setlength{\parindent}{0.5in}
\setlength{\parskip}{6pt}
% set report font
\usepackage[sfdefault]{carlito}
% format headers
\usepackage{titlesec}
\usepackage{titletoc}
\newcommand{\chapterjustification}{}% Similar to \raggedright
\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}%
{\thesection}{0.5in}{}
\titlespacing*{\section}{0pt}{24pt}{12pt}
\titleformat{\subsection}%
{\normalfont\fontsize{14pt}{0pt}\selectfont\bfseries}%
{\thesubsection}{0.5in}{}
\titlespacing*{\subsection}{0pt}{18pt}{12pt}
% set-up frontmatter, mainmatter
\newcommand\frontmatter{
\cleardoublepage
\pagenumbering{roman}}
\newcommand\mainmatter{
\cleardoublepage
\pagenumbering{arabic}}
% format TOC
\renewcommand{\contentsname}{\textbf{Contents}}
\contentsmargin{2.55em}
\titlecontents{chapter}[1.5em]{\addvspace{.5\baselineskip}\bfseries}{\contentslabel{2em}\MakeUppercase}{\hspace*{-2em}\MakeUppercase}{\titlerule*[1pc]{.}\contentspage}
\titlecontents{section}[3.8em]{\bfseries}{\contentslabel{2.3em}\MakeUppercase}{\hspace*{-2.3em}\MakeUppercase}{\titlerule*[1pc]{.}\contentspage}
\dottedcontents{subsection}[6.1em]{}{2.3em}{1pc}
%-------------------------------------------------------
% Begin
\begin{document}
\frontmatter
\include{Abstract}
\begingroup
\cleardoublepage
\addcontentsline{toc}{chapter}{CONTENTS}
\renewcommand{\chapterjustification}{\centering}
\renewcommand{\chapterfontsize}{\fontsize{18pt}{0pt}\selectfont}
\tableofcontents
\endgroup
\cleardoublepage
\addcontentsline{toc}{chapter}{LIST OF FIGURES}
\listoffigures
\mainmatter
\include{ChapterA}
\end{document}
答案2
也许你会考虑以你的模板为基础(我不明白人们所说的模板是什么意思,请参阅什么是模板?) 类(和memoir
的超集)。它相当简单地提供了您所追求的内容。book
report
% reptocprob.tex SE 621261
\documentclass{memoir}
%%%% ToC changes
% change the title format/location
\renewcommand{\printtoctitle}[1]{\centering\Large\bfseries\MakeUppercase{#1}}
% use dotted leaders for chapters
\renewcommand{\cftchapterdotsep}{\cftdotsep}
%%% perhaps `memoir` (and `tocloft`) could be updated to not to need this
\def\UppercaseIt{\afterassignment\UppercaseItA
\long\expandafter\def\expandafter\tmp\expandafter{\iffalse}\fi}
\def\UppercaseItA{\uppercase\expandafter{\tmp}\egroup}
% Uppercase and bold cahpter and section titles in the ToC
\renewcommand{\cftchapterfont}{\UppercaseIt\bfseries}
\renewcommand{\cftsectionfont}{\UppercaseIt\bfseries}
\setcounter{tocdepth}{3}
\begin{document}
\frontmatter
\tableofcontents
\listoffigures
\clearpage
\abstractintoc
\begin{abstract}
Abstraction text.
\end{abstract}
\mainmatter
\chapter{First chapter}
\begin{figure}
\centering ILLUSTRATION
\caption{A figure}
\end{figure}
\section{First section in first chapter}
\subsection{A subsection}
\backmatter
\end{document}