我有一个页面,用 分成两列\minipage
,每列中\minipage
都有一个\begin{enumerate}
环境,\item
每列包含多个项目。项目标记为 (1)、(2) 等...\item
左侧的第一个项目与右侧的\minipage
第一个项目相关,两个列表都是如此。但是,每列中的条目长度不同,因此它们不会自动在列中对齐。我希望左列中的 (1) 与右侧的 (1) 对齐,依此类推,无论条目的大小如何,即在项目之间插入适当的垂直空间,以保持列表编号之间的水平对齐。\item
\minipage
目前,我正在使用\vspace*{0.Xcm}
甚至多次\hbox{}
手动\items
上下移动以获得我想要的对齐,但这非常耗时且繁琐。
我一直\minipage
在 stackexchange 上查看有关对齐的类似问题,但找不到我想要的内容。有没有一种方法可以按照我想要的方式对齐项目? minipage 是尝试此操作的正确方法吗?还是我应该使用某种表格?
例子:
\documentclass{tufte-book}
\usepackage{enumitem}
\begin{document}
\begin{minipage}[t]{.48\linewidth}%.48\linewidth to give padding between columns
\tb{List 1}
\begin{enumerate}[noitemsep]
\item This is item 1.
\item This is item two and is quite a bit longer than item one, taking up more than one line. This issue now is that item three in this list will not horizontally align with item 3 in the adjacent list due to the varying linewidth.
\item This is item 3.
\end{minpage}
\begin{minipage}[t]{.48\linewidth}
\tb{List 2}
\begin{enumerate}[noitemsep]
\item This is item 1.
\item This is item 2.
\item this is item 3.
\end{enumerate}
\end{minipage}
\end{document}
答案1
您可以使用 \vspace{n\baselineskip} 来对齐两个列表,其中 n 是您想要跳过的行数。笔记- 你的例子语法有误。我假设\tb
是,\textbf
并\end{minpage}
改为\end{minipage}
。
这是一个有效的例子-
\documentclass{tufte-book}
\usepackage{enumitem}
\begin{document}
\begin{minipage}[t]{.48\linewidth}%.48\linewidth to give padding between columns
\textbf{List 1}
\begin{enumerate}[noitemsep]
\item This is item 1.
\item This is item two and is quite a bit longer than item one, taking up more than one line. This issue now is that item three in this list will not horizontally align with item 3 in the adjacent list due to the varying linewidth.
\item This is item 3.
\end{enumerate}
\end{minipage}
\begin{minipage}[t]{.48\linewidth}
\textbf{List 2}
\begin{enumerate}[noitemsep]
\item This is item 1.
\item This is item 2. \vspace{7\baselineskip}
\item this is item 3.
\end{enumerate}
\end{minipage}
\end{document}
答案2
您可以使用tabular
-like 结构来保持元素之间的垂直对齐。这可以通过以下方式轻松实现tabularx
:
\documentclass{tufte-book}
\usepackage{tabularx}
\begin{document}
\noindent
\begin{tabularx}{\linewidth}{@{} r X r X @{}}
\multicolumn{2}{@{} l}{\bfseries List 1} & \multicolumn{2}{l}{\bfseries List 2} \\[\topsep]
1. & This is item 1. &
1. & This is item 1. \\
2. & This is item two and is quite a bit longer than item one, taking up
more than one line. This issue now is that item three in this list will
not horizontally align with item 3 in the adjacent list due to the varying
\verb|\linewidth|. &
2. & This is item 2. \\
3. & This is item 3. &
3. & This is item 3.
\end{tabularx}
\end{document}
您可以手动输入列表枚举,也可以使用特定的列类型自动执行该过程。但是,对于小型列表,这可能不是必需的。
列表间距可以根据具体情况进行管理,也可以统一设置。
答案3
如果您想要编写整个第一列,然后编写整个第二列,并且您不想对表格使用特殊标记,那么您的问题是使用\valign
原始数据的典型任务:
\newcount\colitemnum
\long\def\twocolitems#1{\hbox{\colitemnum=0
\def\firstitem##1{\global\advance\colitemnum by1 \llap{(\the\colitemnum)\ }}%
\def\item{&\firstitem:}%
\def\nextcol##1{\cr\colitemnum=0 \firstitem:}%
\hsize=.5\hsize \leftskip=2em \rightskip=1em
\valign{&\vtop{\noindent\strut##\unskip\strut}\vfil\cr\firstitem#1\crcr}}}
\twocolitems{
\item This is item 1.
\item This is item two and is quite a bit longer than item one, taking up more than one line. This issue now is that item three in this list will not horizontally align with item 3 in the adjacent list due to the varying linewidth.
\item This is item 3.
\nextcol
\item This is item 1 and it is quite a bit longer, more than one line.
\item This is item 2.
\item this is item 3.
}
\bye
答案4
另一种解决方案基于tabularx
和ltablex
(因此它可以跨页面),使用 series
来自的键enumitem
。
我定义了一个新的列类型,E
它是X
开始和结束enumerate
环境的列类型。它接收一个参数,即该列中系列的名称。因为必须有一个初始枚举,定义该系列中,我定义了一个\Ehead
命令,将列标题放入这样的枚举中(这些列标题未枚举,使用 item 的可选参数)。
\documentclass[showframe]{tufte-book}%
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{ragged2e}
\usepackage{enumitem}
\usepackage{ltablex, booktabs}
\keepXColumns
\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother
\newcolumntype{E}[1]{>{\enumerate[#1]}X<{\endenumerate}}
\newcommand\Ehead[2]{\multicolumn{1}{@{}X}{ \begin{enumerate}[series=#1, before = \compress\vspace{-\baselineskip}]
\item[\bfseries #2]
\end{enumerate}}}
\begin{document}
\noindent
\setlist[enumerate] {wide=0pt, label=\arabic*., leftmargin=*, before=\vspace*{-\baselineskip}
, after =\vspace{-\dimexpr\baselineskip + \partopsep}}
\begin{tabularx}{\linewidth}{@{}E{colA}E{colB}@{}}
\Ehead{colA}{List 1}
&
\Ehead{colB}{List 2} \\
\addlinespace[-2ex]
\hline
\item This is item 1. &
\item This is item 1. \\\hline
\item This is item two and is quite a bit longer than item one, taking up
more than one line. This issue now is that item three in this list will
not horizontally align with item 3 in the adjacent list due to the varying
\verb|\linewidth|.
&
\item This is item 2. \\\hline
\item This is item 3. A longer item3, not so long as item 2 in the right column. &
\item This is item 3. \\
\hline
\end{tabularx}
\end{document}