--编辑--(重写我当前用来产生左边距的代码)
这是我尝试创建新环境(leftwhitespace
)的代码,而不是编写创建包含 1 个项目的列表的代码:
\begin{itemize}
\item[]
line 1
line 2
\end{itemize}
想要创建leftwhitespace
按照上述代码执行的新环境(添加左边距):
\begin{leftwhitespace}
line 1
line 2
\end{leftwhitespace}
答案1
答案2
这是否解决了您的疑问:
\documentclass{article}
\usepackage{lipsum}
\newenvironment{hanglist}[1][\parindent]{%
\begin{list}{}{%
\setlength{\leftmargin}{#1}
\setlength{\labelwidth}{0pt}
\setlength{\labelsep}{0pt}
\setlength{\itemindent}{-#1}}
}{%
\end{list}
}
\def\D{\par\noindent\makebox[1em][l]{-- }\hangindent1em}
\newcommand{\detail}[1]{\par\noindent\hangindent=\mylen\hangafter1-- #1}
\newlength{\mylen}
\settowidth{\mylen}{-- }
\begin{document}
\begin{hanglist}[2cm]
\item\lipsum[1]
\item\lipsum[2]
\end{hanglist}
Regular itemize
\begin{hanglist}[1cm]
\item First
\item Second
\item Third
\end{hanglist}
\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.
\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}