如何隐藏 LaTeX 上的章节标题编号并更改间距?

如何隐藏 LaTeX 上的章节标题编号并更改间距?

我正在撰写论文,但遇到了一些布局问题,我正在使用标准书籍文档类,这导致我的章节标题的形式如下:

章节 #

我的章节名称

我正在寻找一种方法来改变它,从中删除“章节#”,将其改为以下形式:

我的章节名称

我尝试在主文件上使用以下代码做我想做的事情,虽然我不知道它是否理想,就像我在评论中所说的那样,我尝试使用/titlesec,但我无法删除章节编号:

\renewcommand{\@makechapterhead}[1]{\vspace*{50\p@}%
{\parindent \z@ \raggedright \normalfont
\hrule                                        % horizontal line
\vspace{5pt}%                                 % add vertical space
\interlinepenalty\@M
\Huge \scshape #1\par                        % chapter title
\vspace{5pt}%                                 % add vertical space
\hrule                                        % horizontal rule
\nobreak
\vskip 2\baselineskip
}}

\renewcommand{\@makeschapterhead}[1]{%
\vspace*{50\p@}%
{\parindent \z@ \raggedright
\normalfont
\hrule                                        % horizontal line
\vspace{5pt}%                                 % add vertical space
\interlinepenalty\@M
\Huge \scshape #1\par                         % chapter title
\vspace{5pt}%                                 % add vertical space
\hrule                                        % horizontal line
\nobreak
\vskip 2\baselineskip
}}

我还需要将章节标题后的间距设置为两行,因为这是我所在大学的要求之一,我目前正在尝试这样做,\vskip #\baselineskip但我得到的间距比我想要的更大,所以我猜这与我使用的格式修饰符有关,\Huge但我不确定。

答案1

这是一个可能的解决方案,使用标题安全\aftertitleunit包;将的值设置为\baselineskip,然后可以*2在的第四个强制参数中使用\titlespacing以获得标题和以下文本之间所需的垂直间距。您没有提供标题前的间距信息,所以我使用了50pt,但您可以将此值更改为最适合您需求的值。为了保持编号和未编号章节之间的一致性,我使用了两个\titleformat具有类似设置的命令:一个用于编号章节,另一个使用键numberless,用于未编号章节:

\documentclass{book}
\usepackage{titlesec}

\setlength\aftertitleunit{\baselineskip}

\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries}{}{0pt}{\Huge}
\titleformat{name=\chapter,numberless}[display]
  {\normalfont\huge\bfseries}{}{0pt}{\Huge}
\titlespacing*{\chapter}{0pt}{50pt}{*2}

\begin{document}

\chapter{Test Numbered chapter}
\chapter*{Test Unumbered chapter}

\end{document}

考虑到对原始问题的编辑,您可以\normalsize在之前添加\vskip2\baselineskip

\makeatletter
\renewcommand{\@makechapterhead}[1]{\vspace*{50\p@}%
{\parindent \z@ \raggedright \normalfont
\hrule                                        % horizontal line
\vspace{5pt}%                                 % add vertical space
\interlinepenalty\@M
\Huge \scshape #1\par                        % chapter title
\vspace{5pt}%                                 % add vertical space
\hrule                                        % horizontal rule
\nobreak\normalsize
\vskip 2\baselineskip
}}

\renewcommand{\@makeschapterhead}[1]{%
\vspace*{50\p@}%
{\parindent \z@ \raggedright
\normalfont
\hrule                                        % horizontal line
\vspace{5pt}%                                 % add vertical space
\interlinepenalty\@M
\Huge \scshape #1\par                         % chapter title
\vspace{5pt}%                                 % add vertical space
\hrule                                        % horizontal line
\nobreak\normalsize
\vskip2\baselineskip
}}
\makeatother

下面是相同的布局,但使用titlesec

\documentclass{book}
\usepackage{titlesec}

\setlength\aftertitleunit{\baselineskip}

\titleformat{\chapter}[display]
  {\normalfont\Huge \scshape}{\titlerule}{-33pt}{\Huge}[\vspace{-4pt}\titlerule]
\titleformat{name=\chapter,numberless}[display]
  {\normalfont\Huge \scshape}{\titlerule}{-33pt}{\Huge}[\vspace{-4pt}\titlerule]
\titlespacing*{\chapter}{0pt}{50pt}{*2}

\usepackage{lipsum}

\begin{document}

\chapter{test}

\end{document}

答案2

您声明需要隐藏Chapter <x>(编号)章节标题区域中的行。可以通过重新定义 LaTeX 命令\@makechapterhead(在 中设置book.cls)来实现此更改,使其作用与 完全相同\@makeschapterhead,LaTeX 使用该命令排版未编号或“带星号”章节的标题。

您提到的第二个要求是章节标题行和后续内容之间的垂直空白量等于两个空白行。由于不知道文档的字体大小和行距设置,恐怕无法在此给出明确的设置。在下面的示例中,我使用了跳过值1\baselineskip;您可能需要进行一些实验才能找到适合您机构要求的值。

我建议您使用 LaTeX 包etoolbox及其命令\patchcmd来修改命令\@makeschapterhead,如下面的 MWE 中所做的那样。

\documentclass{book}
\usepackage{etoolbox,lipsum} % use lipsum for filler text
\makeatletter
  % patch the command \@makeschapterhead
  \patchcmd{\@makeschapterhead}{\vskip 40\p@}{\vspace*{1\baselineskip}}{}{}
  % make \@makechapterhead act like \@makeschapterhead
  \let\@makechapterhead\@makeschapterhead 
\makeatother

\begin{document}
\frontmatter
\tableofcontents
\chapter{Acknowledgments}
\lipsum[1-5]
\mainmatter
\chapter{On a very fine day}
\lipsum[6-10]
\end{document}

相关内容