我正在使用 titlesec 包来格式化我的(子)节标题。我想使用runin
中的选项\titleformat
将我的小节标题放在每个小节的第一段内。但是,当我这样做时,我会在每个小节的第一行后得到额外的空格。我摆弄了 中的选项,\titlespacing
但似乎都没有解决问题。
\documentclass[11pt]{article}
\usepackage{titlesec}
\titleformat{\section}{\normalfont\fontsize{11}{36}\bfseries}{\thesection.}{0.25em}{}
\titlespacing{\section}{0em}{-1.0em}{-2.0em} % {left}{before}{after}[right]
\renewcommand{\thesubsection}{\thesection.\alph{subsection}}
\titleformat{\subsection}[runin]{\normalfont\fontsize{11}{36}\bfseries\slshape}{\thesubsection.}{0.25em}{}
\titlespacing{\subsection}{0.0em}{0.0em}{0.5em} % {left}{before}{after}[right]
\linespread{1}
\begin{document}
\section{The first section}
\subsection{The first subsection within the first section:} Asdf asdf asdf asdf asdf asdf adsf asdf asdf asdf adf adf adsf adsf adsf asdf asdf asdf asd f. Wert qwer qwer qwer qwer qwer qwer qewr qewr erwq erw erw rewr rew re ewq ewr wqr qwer weq rqwe r re qwe reqw r ewe r we e w er qwe rq we rqwer qwer qw erq er qewr we are qew rq ew r ew. Hkjlkljj h jlkjh lkjlk jlhlkh lhkjljkj lklkk.
\subsection{The second subsection within the first section:} Asdf asdf asdf asdf asdf asdf adsf asdf asdf asdf adf adf adsf adsf adsf asdf asdf asdf asd f. Wert qwer qwer qwer qwer qwer qwer qewr qewr erwq erw erw rewr rew re ewq ewr wqr qwer weq rqwe r re qwe reqw r ewe r we e w er qwe rq we rqwer qwer qw erq er qewr we are qew rq ew r ew. Hkjlkljj h jlkjh lkjlk jlhlkh lhkjljkj lklkk.
\end{document}
有什么建议么?
答案1
您获得的间距取决于您指定字体大小的方式:\fontsize
参数是实际字体大小和领导大致相当于一条线的高度。(见领导到底是什么?进行广泛的讨论。)您在分段命令中将其设为 36 pt,这意味着每行大约是字符高度的 3 倍。因此,您应该对字体大小命令使用正常行距,然后使用间距titlesec
命令调整间距。为此,我刚刚添加\normalsize
到您的分段命令中。我不知道您实际上想要什么间距,但此示例应该允许您适当地更改间距。我还将其用作ex
垂直高度的单位,而不是em
通常的水平高度的度量。(这主要在您使用的字体中两个值完全不同时很重要,但这是一个好习惯。)
乱用 也不是一个好主意\linespread
;如果您需要在文档中使用双倍行距和 1/2 行距之类的东西,请使用setspace
包。
\documentclass[11pt]{article}
\usepackage{titlesec}
\titleformat{\section}{\normalfont\normalsize\bfseries}{\thesection.}{0.25em}{}
\titlespacing{\section}{0em}{0ex}{0ex} % {left}{before}{after}[right]
\renewcommand{\thesubsection}{\thesection.\alph{subsection}}
\titleformat{\subsection}[runin]{\normalfont\normalsize\bfseries\slshape}{\thesubsection.}{0.25em}{}
\titlespacing{\subsection}{0.0em}{.5ex}{.5ex} % {left}{before}{after}[right]
\begin{document}
\section{The first section}
\subsection{The first subsection within the first section:} Asdf asdf asdf asdf asdf asdf adsf asdf asdf asdf adf adf adsf adsf adsf asdf asdf asdf asd f. Wert qwer qwer qwer qwer qwer qwer qewr qewr erwq erw erw rewr rew re ewq ewr wqr qwer weq rqwe r re qwe reqw r ewe r we e w er qwe rq we rqwer qwer qw erq er qewr we are qew rq ew r ew. Hkjlkljj h jlkjh lkjlk jlhlkh lhkjljkj lklkk.
\subsection{The second subsection within the first section:} Asdf asdf asdf asdf asdf asdf adsf asdf asdf asdf adf adf adsf adsf adsf asdf asdf asdf asd f. Wert qwer qwer qwer qwer qwer qwer qewr qewr erwq erw erw rewr rew re ewq ewr wqr qwer weq rqwe r re qwe reqw r ewe r we e w er qwe rq we rqwer qwer qw erq er qewr we are qew rq ew r ew. Hkjlkljj h jlkjh lkjlk jlhlkh lhkjljkj lklkk.
\end{document}