答案1
您可以使用\settowidth
宏将长度参数的值设置\hangindent
为所选字符串的宽度。
注意:如果您使用悬挂缩进,并假设段落的右边缘对齐,则需要将 head 元素(如“A short head”、“A much longer head”等)放在 中,以防止\mbox
LaTeX 拉伸或收缩可能出现在导语中的任何空格。将 head 元素放在 中会\mbox
“冻结”单词间空格的宽度。
\documentclass{article}
\usepackage{parskip} % no \parindent, \non-zero parskip
\newcommand\dummytext{This is a long sentence that will extend to the second line. I want the second line indented by the length of the head words.}
\begin{document}
\settowidth{\hangindent}{\textbf{A short Head: }}
\mbox{\textbf{A short Head: }}\dummytext
\settowidth{\hangindent}{\textbf{A much longer Head: }}
\mbox{\textbf{A much longer Head: }}\dummytext
\settowidth{\hangindent}{\textbf{Head: }}
\mbox{\textbf{Head: }}\dummytext
\end{document}