我正在使用“setspace”包将我的文档格式化为双倍行距(作业要求)。但是,我的一个节标题占用了两行,而这些节标题使用单倍行距看起来更好。我继续使用以下内容修复了它。
Nunc venenatis nulla eu arcu pellentesque eu molestie nunc condimentum.
Donec sodales lacinia dictum.
Sed aliquam turpis quis enim bibendum pharetra.
This is the last paragraph in section i.
\singlespace
\section{The Next Section Which Has a Fairly Long Name that Stretches Over Two Lines}
\doublespace
This is the first paragraph in section i+1.
Cras ut tortor vel dui ultricies dapibus vitae sit amet nisi.
Aliquam rhoncus leo id eros volutpat faucibus.
Integer lectus elit, varius et semper eget, tristique vel odio.
这是我的论文中唯一一个需要两行标题的情况(到目前为止),所以用这个技巧来修复它并不是什么大问题。然而,我可以想象,随着论文越来越长,章节越来越多,多次添加这个技巧可能会变得更加乏味。
有什么方法可以表明我一次章节标题应为单倍行距,段落应为双倍行距,而不是在整个文档中多次添加此技巧?
答案1
您可以使用etoolbox
包插入到\singlespacing
分段单元之前,然后附加\doublespacing
:
\documentclass{article}
\usepackage{setspace}
\usepackage{etoolbox}
\makeatletter
\pretocmd{\@sect}{\singlespacing}{}{}
\pretocmd{\@ssect}{\singlespacing}{}{}
\apptocmd{\@sect}{\doublespacing}{}{}
\apptocmd{\@ssect}{\doublespacing}{}{}
\makeatother
\doublespacing
\begin{document}
Nunc venenatis nulla eu arcu pellentesque eu molestie nunc condimentum.
Donec sodales lacinia dictum.
Sed aliquam turpis quis enim bibendum pharetra.
This is the last paragraph in section i.
\section{The Next Section Which Has a Fairly Long Name that Stretches Over Two Lines}
This is the first paragraph in section i+1.
Cras ut tortor vel dui ultricies dapibus vitae sit amet nisi.
Aliquam rhoncus leo id eros volutpat faucibus.
Integer lectus elit, varius et semper eget, tristique vel odio.
\end{document}
这将适用于\section
,,\subsection
。\subsubsection
另一个选择是使用titlesec
包裹:
\documentclass{article}
\usepackage{setspace}
\usepackage{titlesec}
\titleformat{\section}
{\singlespacing\normalfont\Large\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}
{\singlespacing\normalfont\large\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}
{\singlespacing\normalfont\normalsize\bfseries}{\thesubsubsection}{1em}{}
\doublespacing
\begin{document}
Nunc venenatis nulla eu arcu pellentesque eu molestie nunc condimentum.
Donec sodales lacinia dictum.
Sed aliquam turpis quis enim bibendum pharetra.
This is the last paragraph in section i.
\section{The Next Section Which Has a Fairly Long Name that Stretches Over Two Lines}
This is the first paragraph in section i+1.
Cras ut tortor vel dui ultricies dapibus vitae sit amet nisi.
Aliquam rhoncus leo id eros volutpat faucibus.
Integer lectus elit, varius et semper eget, tristique vel odio.
\end{document}
或者,使用简化的语法:
\usepackage{titlesec}
\titleformat*{\section}{\normalfont\Large\bfseries\singlespacing}
\titleformat*{\subsection}{\normalfont\large\bfseries\singlespacing}
\titleformat*{\subsubsection}{\normalfont\normalsize\bfseries\singlespacing}
顺便说一下,该软件包setspace
提供了几个命令和环境;命令(开关)以“ing”结尾:,,,,\singlespacing
而环境是,,,。\onehalfspacing
\doublespacing
singlespace
onehalfspace
doublespace
使用\doublespace
“你正在做什么”(作为开关)并不完全正确;以下简单文档:
\documentclass{article}
\usepackage{setspace}
\doublespace
\begin{document}
test
\end{document}
处理后将在输出控制台中显示一条消息
(\end occurred inside a group at level 1)
### semi simple group (level 1) entered at line 4 (\begingroup)
表示一个组已启动但从未结束(在本例中,该组由\doublespace
与环境关联的命令创建doublespace
)。使用开关的正确形式是
\documentclass{article}
\usepackage{setspace}
\doublespacing
\begin{document}
test
\end{document}
并针对相应的环境:
\documentclass{article}
\usepackage{setspace}
\begin{document}
\begin{doublespace}
test...
\end{doublespace}
\end{document}
答案2
如果正在使用“标准”文档类之一—— article
、report
和book
——或基于其中一个标准类的文档类,则一种直接的解决方案是加载该包并在序言中sectsty
发出指令。\allsectionsfont{\singlespacing}
MWE(最小工作示例):
\documentclass{article}
\usepackage{setspace,lipsum}
\doublespacing
\usepackage{sectsty}
\allsectionsfont{\singlespacing}
\begin{document}
\lipsum[1] % filler text
\section{The Next Section Which Has a Fairly Long Name that Stretches Over Two Lines}
\lipsum[2] % more filler text
\end{document}