使用 enumitem 包对项目列表进行间距

使用 enumitem 包对项目列表进行间距

我想要一个看起来完全这样的列表:

       Main text with paragraph indent.  Now the list.  Notice that the list labels
aligns with the left margin, the text and paragraphs thereafter with the paragraph indent

1.     sdf asdf asd fa sdf asd fa sdf as df asd fa sd fa sdf as df asd fas df asd 
fa sdf as df asd fas df asd fas d

       A paragraph under item 1. asdfasdfasdf asdfasdfasdf asdfasdfa sdfasdfasdf
asdfasdf asdfsadf asd fas df asd fas df

       1.1 a sub item asd asd asd asda sda sd as da sd as da sd asda sasd asd as d
asdasd asdas dasdas dasd asdasd 

2.     sdfs df sdf sdfsdf sdf sdf sd fs df sd fs df sdf s df sdfsdfsdfsdfsd fsdfs
sdf sdfsdfsdf

我正在尝试这些设置但可以让它正常工作:

\parskip=0pt 
\parindent=1.5 cm

 \begin{enumerate}[align=left, leftmargin=0pt, labelindent=0pt,
listparindent=\parindent, labelwidth=0pt, itemindent=!]
   \item sdfasdas sdasd a asd asd asda sdasdasd asdasd asda sdasd asdasd asdasd asdasd asdasd sd

asdasd asdasd asd asd asd asd asd asd asdasdasd asdasdasd  asdasdasda sdasdasd asdasd asdasda sdasdas dasda sdaasdasd asdasd 

 asdasd asdasd asd asd asd asd asd asd asdasdasd asdasdasd  asdasdasda sdasdasd asdasd asdasda sdasdas dasda sdaasdasd asdasd 

 \end{enumerate}

答案1

使用enumitem您需要的软件包:

label=\arabic*.,      % define the label
align=left,           % align the label to the left
itemindent=\parindent,% fit the label and the space following in this width
labelwidth=\parindent,% fit the label and the space following in this width
labelsep=0pt,
listparindent=\parindent,
leftmargin=0pt,% New lines in paragraph are to be aligned on the left

这是列表的第一级。第二级类似,但略有调整:

在此处输入图片描述

笔记:

代码:

\documentclass{article}
\usepackage{showframe}
\usepackage{enumitem}

\newlist{MyEnumerate}{enumerate}{2}
\setlist[MyEnumerate,1]{
    label=\arabic*.,      % define the label
    align=left,           % align the label to the left
    itemindent=\parindent,% fit the label and the space following in this width
    labelwidth=\parindent,% fit the label and the space following in this width
    labelsep=0pt,
    listparindent=\parindent,
    leftmargin=0pt,% New lines in paragraph are to be aligned on the left
    }
\setlist[MyEnumerate,2]{% settings for second level 
    label*=\arabic*, start=1, % define the label
    align=left,           % align the label to the left
    itemindent=2\parindent,% fit the label and the space following in this width
    labelwidth=\parindent,% fit the label and the space following in this width
    leftmargin=0pt,% New lines in paragraph are to be aligned on the left
    }

\begin{document}
Main text with paragraph indent.  Now the list.  Notice that the list labels
aligns with the left margin, the text and paragraphs thereafter with the paragraph indent

\begin{MyEnumerate}
   \item sdfasdas sdasd a asd asd asda sdasdasd asdasd asda sdasd asdasd asdasd asdasd asdasd sd

    A paragraph under item 1. asdfasdfasdf asdfasdfasdf asdfasdfa sdfasdfasdf
asdfasdf asdfsadf asd fas df asd fas df

    \begin{MyEnumerate}
        \item a sub item asd asd asd asda sda sd as da sd as da sd asda sasd asd as d
    asdasd asdas dasdas dasd asdasd
    \end{MyEnumerate}
    
    \item sdfs df sdf sdfsdf sdf sdf sd fs df sd fs df sdf s df sdfsdfsdfsdfsd fsdfs
sdf sdfsdfsdf
 \end{MyEnumerate}
\end{document}

答案2

以下不使用enumitem包裹而是通过在正确的位置插入编号来模仿列表。采用这种方法的原因是您的设置似乎类似于常规段落文本。因此,摆弄列表缩进可能会很棘手。

在此处输入图片描述

\documentclass{article}

\setlength{\parindent}{2em}
\renewcommand{\theenumii}{\theenumi.\arabic{enumii}}

\makeatletter
\newlength{\myenum@indent}
\setlength{\myenum@indent}{-\parindent}
\newenvironment{myenum}
  {\ifnum \@enumdepth >\thr@@\@toodeep\else
     \advance\@enumdepth\@ne
     \addtolength{\myenum@indent}{\parindent}%
     \edef\@enumctr{enum\romannumeral\the\@enumdepth}%
   \fi%
   \setcounter{\@enumctr}{0}% Restart numbering
   \renewcommand{\item}{%
     \refstepcounter{\@enumctr}
     \noindent%
     \ifnum \@enumdepth >1 \hspace*{\myenum@indent}\fi%
     \makebox[\parindent][l]{\csname the\@enumctr\endcsname.}\ignorespaces}%
  }{}
\makeatother

\begin{document}

Main text with paragraph indent.  Now the list.  Notice that the list labels
aligns with the left margin, the text and paragraphs thereafter with the paragraph indent

\begin{myenum}
  \item sdf asdf asd fa sdf asd fa sdf as df asd fa sd fa sdf as df asd fas df asd 
        fa sdf as df asd fas df asd fas d

        A paragraph under item 1. asdfasdfasdf asdfasdfasdf asdfasdfa sdfasdfasdf
        asdfasdf asdfsadf asd fas df asd fas df

  \begin{myenum}
    \item a sub item asd asd asd asda sda sd as da sd as da sd asda sasd asd as d
          asdasd asdas dasdas dasd asdasd 

    \item a sub item asd asd asd asda sda sd as da sd as da sd asda sasd asd as d
          asdasd asdas dasdas dasd asdasd 
  \end{myenum}

  \item sdfs df sdf sdfsdf sdf sdf sd fs df sd fs df sdf s df sdfsdfsdfsdfsd fsdfs
        sdf sdfsdfsdf

  \begin{myenum}
    \item a sub item asd asd asd asda sda sd as da sd as da sd asda sasd asd as d
          asdasd asdas dasdas dasd asdasd 

    \item a sub item asd asd asd asda sda sd as da sd as da sd asda sasd asd as d
          asdasd asdas dasdas dasd asdasd 
  \end{myenum}

\end{myenum}
\end{document}

答案3

以下是使用wideenumitem 选项的解决方案:

 \documentclass{article}
\usepackage{enumitem}
\setlist[enumerate] {labelsep = 0pt}
\setlist[enumerate, 1] {wide = 0pt, labelwidth = \parindent, listparindent = \parindent}
\setlist[enumerate, 2]{label =\theenumi.\arabic*, wide =\parindent, labelwidth = \parindent, leftmargin =0pt}

\begin{document}

Main text with paragraph indent. Now the list. Notice that the list labels
aligns with the left margin, the text and paragraphs thereafter with the paragraph indent

\begin{enumerate}
\item sdfasdas sdasd a asd asd asda sdasdasd asdasd asda sdasd asdasd asdasd asdasd asdasd sd

A paragraph under item 1. asdfasdfasdf asdfasdfasdf asdfasdfa sdfasdfasdf
asdfasdf asdfsadf asd fas df asd fas df
\begin{enumerate}%[wide = 0pt, labelwidth = \parindent, labelsep = 0pt, listparindent = \parindent]
   \item A sub item asd asd asd asda sda sd as da sd as da sd asda sasd asd as d
asdasd asdas dasdas dasd asdasd
\end{enumerate}
\item sdfs df sdf sdfsdf sdf sdf sd fs df sd fs df sdf s df sdfsdfsdfsdfsd fsdfs
sdf sdfsdfsdf
\end{enumerate}

\end{document} 

在此处输入图片描述

相关内容