我有几个paragraph
,每个都有不同长度的唯一标题:
\documentclass[12pt]{article}
\begin{document}
\subsection{Subsection 1}
\paragraph{Title}
Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here.
\subsection{Subsection 2}
\paragraph{Long Title}
Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here.
\paragraph{Long Long Title}
Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here.
\end{document}
我正在寻找一个全局设置,它可以以可变的方式格式化每个段落的文本,例如(忽略“...”):
第1节
标题此处输入段落文本。此处输入段落文本。此处输入段落文本。此处输入段落文本。......此处输入段落文本。此处输入段落文本。此处输入段落文本。此处输入段落文本。
第2节
长标题此处输入段落文本。此处输入段落文本。此处输入段落文本。此处输入段落文本。此处输入段落文本。此处输入段落文本。此处输入段落文本。此处输入段落文本。此处输入段落文本。
长长标题此处输入段落文本。此处输入段落文本。此处输入段落文本。此处输入段落文本。此处输入段落文本。此处输入段落文本。此处输入段落文本。此处输入段落文本。...........此处输入段落文本。
我确信有enumitem
解决方案,但是我想坚持使用paragraph
s 并远离变通方法。我相信and/orenumitem
的一些用法可能有效,但我不确定如何这样做。\hangindent
\hangafter
答案1
你可以\myparagraph
这样定义:
\usepackage{calc} %% provides `\widthof` macro
\newlength{\mylen}
\newlength{\mylength}
\newcommand{\myparagraph}[2][]{%
\setlength{\mylen}{\widthof{\textbf{#2}}}
\setlength{\mylength}{\dimexpr\mylen+1em\relax}
\paragraph[#1]{#2}
\hangindent=\mylength
}
然后\myparagraph{Title}
在需要悬挂时使用。
\documentclass{article}
\usepackage{calc}
\newlength{\mylen}
\newlength{\mylength}
\newcommand{\myparagraph}[2][]{%
\setlength{\mylen}{\widthof{\textbf{#2}}}
\setlength{\mylength}{\dimexpr\mylen+1em\relax}
\paragraph[#1]{#2}
\hangindent=\mylength
}
\begin{document}
\subsection{Subsection 1}
\myparagraph{Title}
Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here.
\subsection{Subsection 2}
\myparagraph{Long Title}
Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here.
\myparagraph{Long Long Title}
Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here. Paragraph text here.
\end{document}