我正在使用 titlesec 包来设置 runin 小节标题。但是,我有时只想要这个,如果我尝试用 \ 换行,它要么会抛出错误,要么会添加一些奇怪的缩进。有人能帮忙吗?
% Inline subsection
\usepackage{titlesec}
\titleformat{\subsection}[runin]% runin puts it in the same paragraph
{\bfseries}% formatting commands to apply to the whole heading
{\thesubsection}% the label and number
{0.5em}% space between label/number and subsection title
{\large}% formatting commands applied just to subsection title
[]% punctuation or other commands following subsection title
答案1
这是一个相当奇怪的要求。无论如何,你可以这样做。
\documentclass{article}
%\usepackage{xparse} % uncomment if using LaTeX prior to 2020-10-01
\usepackage{titlesec}
\titleformat{\subsection}[runin]% runin puts it in the same paragraph
{\bfseries}% formatting commands to apply to the whole heading
{\thesubsection}% the label and number
{0.5em}% space between label/number and subsection title
{}% formatting commands applied just to subsection title
[]% punctuation or other commands following subsection title
\makeatletter
\NewDocumentCommand{\psubsection}{sO{#3}m}{%
\IfBooleanTF{#1}{\subsection*{#3}}{\subsection[#2]{#3}}%
\mbox{}\par\nopagebreak\@afterheading
}
\makeatother
\begin{document}
\section{Test}
\subsection{Run in}
Some text
\psubsection{Not run in}
Some text
\end{document}
我删除了\large
,因为它与连贯的标题不协调。
答案2
来,试试这个:
\subsubsection{My header (singled out)}
\paragraph{}\noindent
% paragraph
如果你经常使用它,你可以把它放入命令中
\newcommand{\singlesubsec}[1]{\subsection{#1}\paragraph{}\noindent}
然后你可以使用它(替换上面的内容)作为
\singlesubsec{My header (singled out)}
% paragraph
梅威瑟:
\documentclass{article}
% Inline subsection
\usepackage{titlesec}
\titleformat{\subsection}[runin]% runin puts it in the same paragraph
{\bfseries}% formatting commands to apply to the whole heading
{\thesubsection}% the label and number
{0.5em}% space between label/number and subsection title
{\large}% formatting commands applied just to subsection title
[]% punctuation or other commands following subsection title
\usepackage{lipsum} % just for dummy text
\begin{document}
\subsection{Header in-line}
\lipsum[1]
\subsection{Header on own}
\paragraph{}\noindent
\lipsum[1]
\end{document}