悬挂缩进/文本换行

悬挂缩进/文本换行

我正在尝试实现一个命令来代替itemize/enumerate环境。我的想法是,我想要一个命令 ( \detail),它可用于构建一个不包含在环境中的逐项列表。我遇到的问题是,当一行长于页面宽度并因此换行到下一行时,我似乎无法控制换行文本的缩进。我尝试过包hanging\hangindent,但运气不佳。

我在下面提供了一个最小示例以及编译后的输出。理想情况下,我希望换行的文本缩进,以便第二行的第一个单词与第一行的第一个单词对齐。

\documentclass{article}
\newcommand{\detail}[1]{-- {#1}}

\begin{document}
    \noindent\textbf{This is a header}\\
    \detail{This is a detail.}\\
    \detail{This is a detail that has too many words in it and consequently runs onto the next line of the page, and I want it to have a hanging indent.}
\end{document}

在此处输入图片描述

答案1

已经回答的简化:

\documentclass{article}
\def\D{\par\noindent\makebox[1em][l]{-- }\hangindent1em}
\begin{document}
\subsubsection*{This is a header}
\D This is a detail
\D This is a detail that has too many words in it and consequently runs onto The next line of the page, and I want it to have a hanging indent.
\end{document}

平均能量损失

答案2

\documentclass{article}
\newcommand{\detail}[1]{\par\noindent\hangindent=\mylen\hangafter1-- #1}
\newlength{\mylen}
\settowidth{\mylen}{-- }

\begin{document}
    \noindent\textbf{This is a header}
    \detail{This is a detail.}
    \detail{This is a detail that has too many words in it and consequently runs onto the next line of the page, and I want it to have a hanging indent.}
\end{document}

在此处输入图片描述

答案3

\documentclass{article}
\newcommand{\detail}[1]{\par\noindent\hangindent=\mylen\hangafter1--\,\,#1}
\newlength{\mylen}
\settowidth{\mylen}{--\,\,}

\begin{document}
    \noindent\textbf{This is a header}
    \detail{This is a detail.}
    \detail{This is a detail that has too many words in it and consequently runs onto the next line of the page, and I want it to have a hanging indent.}
\end{document}

想把这个作为对 Harish Kumar 的回答的评论,但我没有足够的声望。无论如何,由于空间是橡胶,最好使用固定长度。由于 \,似乎有点窄,我用了两次,你可以根据自己的喜好进行调整。

相关内容