懸掛縮排/文字環繞

懸掛縮排/文字環繞

我正在嘗試實現一個命令來代替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 答案的評論,但我對此沒有足夠的代表。無論如何,由於空間是橡膠的,所以最好使用固定長度。因為\,好像有點窄,我用了兩次,你可以依照口味調整。

相關內容