如何将枚举/逐项列表标签与正文对齐

如何将枚举/逐项列表标签与正文对齐

我不确定如何命名这个问题,所以请随意更改。

鉴于以下情况:

在此处输入图片描述

这看起来确实是我想要的,但是请注意,我“目测”了leftmargin传递给itemize列表的内容。在这种情况下,它似乎45pt是让它排队的原因(也许我错了)。

我想知道是否有某种方法可以计算这个(或者是否有另一种方法可以完全计算),这样我就不必对其进行硬编码,这样它就可以自动工作,而不管文档边距如何。

请注意,\parindent0pt,这确实是我想要的。

\documentclass[10pt]{article}

\usepackage{fontspec}
\usepackage[inline]{enumitem}
\usepackage[letterpaper,vmargin=0.3in,hmargin=0.7in]{geometry}

\defaultfontfeatures{Ligatures=TeX}
\setmainfont{TeX Gyre Pagella}

\setlength{\parindent}{0pt}
\pagestyle{empty}

\newlist{points}{itemize}{1}
\setlist[points]{label=»,leftmargin=0pt,itemsep=2pt,parsep=0pt,topsep=4pt}

\begin{document}

I want the left-most edge of the list contents below (the labels in particular) to be aligned with this text.

\begin{points}[leftmargin=45pt] % What should leftmargin be so that it's not hardcoded?
  \item[{\textbf{ABC 1}} »] This is a line to illustrate the problem it is long enough to somewhat reach the end
  \item[{\footnotesize Abc 1234} »] This is a second line to illustrate the problem it is long enough to somewhat reach the end
  
  \par\addvspace{\baselineskip}
  
  \item[{\textbf{ABC 2}} »] This is a third line to illustrate the problem it is long enough to somewhat reach the end
  \item[{\footnotesize Abc 5678} »] This is a fourth line to illustrate the problem it is long enough to go past the end and wrap onto another line at this point. It should wrap like this, with an indent skipping the label's width.
  \item Final point for good measure.
\end{points}\par

I want the left-most edge of the list contents above (the labels in particular) to be aligned with this text.

\end{document}

答案1

指定widest列表中的元素并leftmargin使用以下*选项重新计算:

在此处输入图片描述

\documentclass{article}

\usepackage{fontspec}
\usepackage[inline]{enumitem}
\usepackage[letterpaper,vmargin=0.3in,hmargin=0.7in]{geometry}

\defaultfontfeatures{Ligatures=TeX}
\setmainfont{TeX Gyre Pagella}

\setlength{\parindent}{0pt}
\pagestyle{empty}

\newlist{points}{itemize}{1}
\setlist[points]{label=»,leftmargin=0pt,itemsep=2pt,parsep=0pt,topsep=4pt}

\begin{document}

I want the left-most edge of the list contents below (the labels in particular) to be aligned with this text.

\begin{points}[widest={{\footnotesize Abc 1234} »},leftmargin=*]
  \item[{\textbf{ABC 1}} »] This is a line to illustrate the problem it is long enough to somewhat reach the end
  \item[{\footnotesize Abc 1234} »] This is a second line to illustrate the problem it is long enough to somewhat reach the end
  
  \par\addvspace{\baselineskip}
  
  \item[{\textbf{ABC 2}} »] This is a third line to illustrate the problem it is long enough to somewhat reach the end
  \item[{\footnotesize Abc 5678} »] This is a fourth line to illustrate the problem it is long enough to go past the end and wrap onto another line at this point. It should wrap like this, with an indent skipping the label's width.
  \item Final point for good measure.
\end{points}\par

I want the left-most edge of the list contents above (the labels in particular) to be aligned with this text.

\end{document}

相关内容