连缀小节和间距

连缀小节和间距

我正在尝试制作一个连续的小节标题,并在标题后插入一个长破折号。我成功做到了,但破折号后的间距有细微的差异。我希望得到与第二段相同的输出(不使用小节)。

\documentclass[12pt]{article}
\usepackage{lipsum, titlesec}

\titleformat{\subsubsection}[runin]
            {\normalfont\sffamily\bfseries}{}{0em}{}[ --- ]

\begin{document}
\subsubsection{A brand new template} Until now, we have have been using
a combination of markdown and pandoc for producing both the draft and the final
version of an article.\\

\noindent \textbf{\sffamily A brand new template ---} Until now, we have have
been using a combination of markdown and pandoc for producing both the draft
and the final version of an article.
\end{document}

输出

答案1

您也必须更改\titlespacingsubsubsection 命令:

\documentclass[12pt]{article}
\usepackage{lipsum, titlesec}

\titleformat{\subsubsection}[runin]
  {\normalfont\sffamily\bfseries}
  {}{0em}{}
  [\mbox{ --- }]
\titlespacing{\subsubsection}
  {0pt}% left
  {3.25ex plus 1ex minus .2ex}% before
  {0pt}% after

\begin{document}
\subsubsection{\sffamily A brand new template}Until now, we have have been using
a combination of markdown and pandoc for producing both the draft and the final
version of an article.

\noindent \textbf{\sffamily A brand new template ---} Until now, we have have
been using a combination of markdown and pandoc for producing both the draft
and the final version of an article.

\subsubsection{\sffamily A brand new template}Until now, ...

\noindent \textbf{\sffamily A brand new template ---} Until now, ...
\end{document}

在此处输入图片描述

您还可以加载包microtype

在此处输入图片描述

答案2

这主要取决于您是否希望破折号周围的空格参与线条的拉伸/收缩。

您还需要删除通常在标题后添加的空格,这可以使用 来完成\titlespacing。您可以在 文档的第 9.2 节末尾找到标准参数titlesec;因为\subsubsection它是

\titlespacing*{\subsubsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}

参数为

  1. 缩进(您希望它保持为零)
  2. 标题前的垂直空间(您希望它相同)
  3. 标题后的水平空间(您希望它为零)

\titlespacing和之间的区别\titlespacing*对于连贯标题来说无关紧要。对于块标题,后者会消除以下段落的缩进。

如果您希望空间不参与拉伸/收缩:

\documentclass[12pt]{article}
\usepackage{lipsum, titlesec}

\titleformat{\subsubsection}[runin]
  {\normalfont\sffamily\bfseries}
  {}
  {0em}
  {}
  [\mbox{ --- }]
\titlespacing*{\subsubsection}{0pt}{3.25ex plus 1ex minus .2ex}{0pt}

\begin{document}

\subsubsection{A brand new template}
Until now, we have have been using a combination of markdown and
pandoc for producing both the draft and the final version of an article.

\noindent\textbf{\sffamily A brand new template\mbox{ --- }}%
Until now, we have have been using a combination of markdown and
pandoc for producing both the draft and the final version of an article.

\end{document}

在此处输入图片描述

如果您希望空间参与拉伸和收缩:

\documentclass[12pt]{article}
\usepackage{lipsum, titlesec}

\titleformat{\subsubsection}[runin]
  {\normalfont\sffamily\bfseries}
  {}
  {0em}
  {}
  [ --- \hspace*{0pt}]
\titlespacing*{\subsubsection}{0pt}{3.25ex plus 1ex minus .2ex}{0pt}

\begin{document}

\subsubsection{A brand new template}
Until now, we have have been using a combination of markdown and
pandoc for producing both the draft and the final version of an article.

\noindent\textbf{\sffamily A brand new template --- }%
Until now, we have have been using a combination of markdown and
pandoc for producing both the draft and the final version of an article.

\end{document}

我们\hspace*{0pt}确保破折号后的空格不会被删除。

在此处输入图片描述

答案3

希望这应该接近你想要的。我在小节标题前使用了简短的语法:

\documentclass[12pt]{article}
\usepackage{lipsum, titlesec}
\usepackage{lipsum}

\titleformat{\subsubsection}[runin]
            {\normalfont\sffamily\bfseries}{}{-0.2em}{}[ --- ]

\titlespacing{\subsubsection}{0pt}{*3.2}{0.25em}

\begin{document}

\lipsum[2]

\subsubsection{A brand new template} Until now, we have have been using
a combination of markdown and pandoc for producing both the draft and the final
version of an article.\\

\noindent \textbf{\sffamily A brand new template ---} Until now, we have have
been using a combination of markdown and pandoc for producing both the draft
and the final version of an article.

\end{document} 

在此处输入图片描述

相关内容