如何正确使用enumitem来对齐子列表和列表?

huangapple go评论53阅读模式
英文:

How to align sublists and lists using enumitem correctly?

问题

我正在尝试使用 enumitem 配置列表和子列表的对齐。以下是代码:

\documentclass{article}
\usepackage{enumitem}

\begin{document}

\section{Introduction}
Lists:

\begin{itemize}[align=left, labelindent=0em, leftmargin=0em, itemindent=!, nosep, noitemsep]
  \item Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
  %
  \begin{itemize}[nosep, noitemsep]
    \item Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
  </begin{itemize}
  %
  \item Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\end{itemize}

\end{document}

标签被正确放置,但第一级文本的起始点(1和5行)应根据第二级标签(第3行)对齐,第二级文本的延续部分(第4行)也应根据第二级标签(第3行)对齐。我该如何实现这个效果?我尝试阅读 https://mirror.datacenter.by/pub/mirrors/CTAN/macros/latex/contrib/enumitem/enumitem.pdf,但它对我来说很难理解。

英文:

I'm trying to configure aligning of lists and sublists using enumitem. Here is the code:

\documentclass{article}
\usepackage{enumitem}

\begin{document}

\section{Introduction}
Lists:

\begin{itemize}[align=left, labelindent=0em, leftmargin=0em, itemindent=!, nosep, noitemsep]
  \item Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
  %
  \begin{itemize}[nosep, noitemsep]
    \item Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
  \end{itemize}
  %
  \item Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\end{itemize}

\end{document}

Labels are placed correctly, but the 1st lvl text start (1 and 5 lines) should align according to the 2nd lvl label (3 line), and the 2nd lvl text continuation (4 line) should align according to the 2nd lvl label (3 line) too. How can I achieve that? I tried to read https://mirror.datacenter.by/pub/mirrors/CTAN/macros/latex/contrib/enumitem/enumitem.pdf, but it's all Greek to me.

如何正确使用enumitem来对齐子列表和列表?
如何正确使用enumitem来对齐子列表和列表?

答案1

得分: 1

以下是代码的中文翻译:

\documentclass{article}
\usepackage{enumitem}
\usepackage{blindtext}

% 设置全局的itemize列表样式
\setlist[itemize]{
  nosep,             % 无额外间距
  align=left,        % 左对齐
  leftmargin=0pt,    % 左边距为0
  labelwidth=1.25em, % 标签宽度
  itemindent=1.25em, % 项目缩进
  labelsep=0pt,      % 标签与文本无间距
}

% 设置第二级itemize列表的样式
\setlist*[itemize,2]{
  leftmargin=1.25em,  % 左边距为1.25em
}

\begin{document}
\section{Introduction}
列表示例:

\begin{itemize}
\item Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
  % 
  \begin{itemize}
  \item Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
  \end{itemize}
  % 
\item Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\end{itemize}

\end{document}

希望这有助于您理解代码的内容。

英文:

Does the code below work for you?

\documentclass{article}
\usepackage{enumitem}
\usepackage{blindtext}


\setlist[itemize]{
  nosep,
  align=left,
  leftmargin=0pt,
  labelwidth=1.25em,
  itemindent=1.25em,
  labelsep=0pt,
}
\setlist*[itemize,2]{
  leftmargin=1.25em,
}

\begin{document}
\section{Introduction}
Lists:

\begin{itemize}
\item Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
  % 
  \begin{itemize}
  \item Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
  \end{itemize}
  % 
\item Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
\end{itemize}

\end{document}

here's the screnshot:

如何正确使用enumitem来对齐子列表和列表?


EDIT. Use \setlist to make global settings and then its starred version to add adjustment per list, level of a specific list, etc. If it's a local for one list, you could even create a new list \newlist for a specific purpose (more in enumitem documentation).

huangapple
  • 本文由 发表于 2023年2月19日 18:05:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75499335.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定