将两个并排的逐项列表中的项目符号对齐

将两个并排的逐项列表中的项目符号对齐

我正在尝试在一个文档中创建两个并排的项目符号列表,其中每个点都与另一个列表中的相应点对齐,即使其中一个点有多条线。

到目前为止,我使用了一个小型页面环境并将\\项目并排放置,但这似乎是一个主要的解决办法。

举个例子,我有这样的东西:

\documentclass{article}
\begin{document}
\begin{minipage}[t]{0.5\textwidth}
\begin{itemize}
\item Mary had a little lamb,
\item Old MacDonald had a farm,
\end{itemize}
\end{minipage}
\begin{minipage}[t]{0.5\textwidth}
\begin{itemize}
\item Her fleece was white as snow. And everywhere that Mary went, the lamb was sure to go.
\item E-I-E-I-O! And on this farm he had a cow, E-I-E-I-O! With a moo moo here, and a moo moo there.
\end{itemize}
\end{minipage}
\end{document}

上述代码片段的结果

然后为了对齐它们,我\\根据需要添加

\documentclass{article}
\begin{document}
\begin{minipage}[t]{0.5\textwidth}
\begin{itemize}
\item Mary had a little lamb, \\ \\
\item Old MacDonald had a farm,
\end{itemize}
\end{minipage}
\begin{minipage}[t]{0.5\textwidth}
\begin{itemize}
\item Her fleece was white as snow. And everywhere that Mary went, the lamb was sure to go.
\item E-I-E-I-O! And on this farm he had a cow, E-I-E-I-O! With a moo moo here, and a moo moo there.
\end{itemize}
\end{minipage}
\end{document}

使用反斜杠对齐的项目

但有没有更明智的方法来实现这一点?值得注意的是,每当我使用时,它都会停止工作\raggedright

答案1

如果您不担心分页,我只需将其设置为tabularx。这完全取决于列规范:

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx}% Loads the array package
\begin{document}

\noindent
\begin{tabularx}{\textwidth}{
    @{\hspace{1.5em}}% Space for left bullet
    >{\leavevmode\llap{\textbullet~}\raggedright}% Left bullet + formatting of column
    X% Left column specification
    @{\quad\hspace{1.5em}}% Space between columns + right bullet space
    >{\leavevmode\llap{\textbullet~}\raggedright\arraybackslash}% Right bullet + formatting of column
    X% Right column specification
    @{}% No column space on right
  }
  Mary had a little lamb, & 
    Her fleece was white as snow. And everywhere that Mary went, the lamb was sure to go. \\
  Old MacDonald had a farm, & 
    E-I-E-I-O! And on this farm he had a cow, E-I-E-I-O! With a moo moo here, and a moo moo there.
\end{tabularx}

\end{document}

如上所述,列规范是这里的关键。从技术上讲,我们只有 2 个X列,每个列1.5em左侧都有一个 的空间,用于放置\textbullet内部。外观类似于itemize。两列\quad之间有一个附加的。

通过正确的设置,您构建的代码应该相当容易阅读/解释,并因此易于维护。


内容也可以通过以下方式垂直拉伸:调整\arraystretch进行相应. 标题和其他tabular相关结构也很容易添加,例如,使用booktabs

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx,booktabs}
\newcommand{\fakeleft}{\multicolumn{1}{X}{}}
\let\fakeright\fakeleft
\begin{document}

\renewcommand{\arraystretch}{1.5}% Vertically stretch tabular constructions
\noindent
\begin{tabularx}{\textwidth}{
    @{\hspace{1.5em}}% Space for left bullet
    >{\leavevmode\llap{\textbullet~}\raggedright}% Left bullet + formatting of column
    X% Left column specification
    @{\quad\hspace{1.5em}}% Space between columns + right bullet space
    >{\leavevmode\llap{\textbullet~}\raggedright\arraybackslash}% Right bullet + formatting of column
    X% Right column specification
    @{}% No column space on right
  }
  \toprule
  \multicolumn{1}{X}{\centering\bfseries Left heading} &
    \multicolumn{1}{X}{\centering\bfseries Right heading} \\
  \midrule
  Mary had a little lamb, & 
    Her fleece was white as snow. And everywhere that Mary went, the lamb was sure to go. \\
  \fakeleft & 
    This is a right bullet without a left counterpart. \\
  Old MacDonald had a farm, & 
    E-I-E-I-O! And on this farm he had a cow, E-I-E-I-O! With a moo moo here, and a moo moo there. \\
  \bottomrule
\end{tabularx}

\end{document}

\fakeleft/\fakeright可以互换使用,以产生没有对应部分的子弹。

答案2

您可以尝试multienum包,通过定义新的multiitem环境

\newenvironment{multiitem}{%
  \multienumerate\renewcommand{\labelname}{\textbullet}%
}{%
  \endmultienumerate%
}

无需minipages 或tabulars。

平均能量损失

\documentclass{article}
\usepackage{multienum}

\newenvironment{multiitem}{%
  \multienumerate\renewcommand{\labelname}{\textbullet}%
}{%
  \endmultienumerate%
}

\begin{document}
\begin{multiitem}
\mitemxx{Mary had a little lamb,}{Her fleece was white as snow. And everywhere that Mary went, the lamb was sure to go.}
\mitemxx{Old MacDonald had a farm,}{E-I-E-I-O! And on this farm he had a cow, E-I-E-I-O! With a moo moo here, and a moo moo there.}
\end{multiitem}
\end{document} 

输出

在此处输入图片描述

答案3

您还可以使用 parcolumns 包来完成此操作,该包通常用于并排翻译。

在此处输入图片描述

\documentclass{article}
\usepackage{parcolumns}
\begin{document}
\raggedright
\begin{parcolumns}{2}
\colchunk{\centering Left Header}
\colchunk{\centering Right Header}
\colplacechunks
\colchunk{\begin{itemize}\item Mary had a little lamb,\end{itemize}}
\colchunk{\begin{itemize}\item Her fleece was white as snow. And everywhere that Mary went, the lamb was sure to go. \item Another right bullet under the same left bullet.\end{itemize}}
\colplacechunks
\colchunk{\begin{itemize}\item Old MacDonald had a farm,\end{itemize}}
\colchunk{\begin{itemize}\item E-I-E-I-O! And on this farm he had a cow, E-I-E-I-O! With a moo moo here, and a moo moo there.\end{itemize}}
\end{parcolumns}
\end{document}

相关内容