如何创建具有默认左边距的自定义环境?

如何创建具有默认左边距的自定义环境?

--编辑--(重写我当前用来产生左边距的代码)

这是我尝试创建新环境(leftwhitespace)的代码,而不是编写创建包含 1 个项目的列表的代码:

\begin{itemize} 
    \item[]
      line 1
      line 2
\end{itemize}

想要创建leftwhitespace按照上述代码执行的新环境(添加左边距):

\begin{leftwhitespace}
    line 1
    line 2
\end{leftwhitespace}

答案1

如果我很清楚你想要什么,changepage那么已经有一个环境了:

\documentclass{article}
\usepackage{lipsum}
\usepackage{changepage}

\begin{document}

\lipsum[10]
\begin{adjustwidth}{3em}{0pt}
\lipsum[11-12]
\end{adjustwidth}

\lipsum[13]

\end{document} 

在此处输入图片描述

答案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}

相关内容