我正在尝试对齐minipage
包含列表的 。使用tabular
列表的环境会导致 minipage 忽略该[t]
选项(或任何其他选项,据我所知)。另一方面,使用description
环境会产生正确的结果,但我不喜欢它如何对齐item[]
具有不同长度的 s,因此更喜欢使用表格。
梅威瑟:
\documentclass{article}
\begin{document}
\textbf{One set of notes.}
\begin{minipage}[t]{0.5\linewidth}
\begin{tabular}{@{}r@{ }l@{}}
Note 1: & This is the first note \\
Note 2: & This is the second note \\
Note 3: & This is the third note \\
Note 4: & This is the fourth note \\
\end{tabular}
\end{minipage}
\textbf{Another set of notes.}
\begin{minipage}[t]{0.5\linewidth}
\begin{description}
\item[Note 1:] This is the first note \\
\item[Note 2:] This is the second note \\
\item[Note 3:] This is the third note \\
\item[Note 4:] This is the fourth note \\
\end{description}
\end{minipage}
\end{document}
结果显示在底部的图像中。
有没有办法在tabular
a 内部使用minipage
承认垂直对齐?
答案1
操作[t]
对齐将minipage
其内容与内部锚点的顶部对齐minipage
。由于minipage
内部在中间有一个锚点 - 由tabular
块提供,minipage
因此“顶部”位于块的(垂直)中间。
为了避免这种情况,请将锚点也指定tabular
为op:[t]
\documentclass{article}
\begin{document}
\textbf{One set of notes.}
\begin{minipage}[t]{0.5\linewidth}
\begin{tabular}[t]{@{}r@{ }l@{}}
Note 1: & This is the first note \\
Note 2: & This is the second note \\
Note 3: & This is the third note \\
Note 4: & This is the fourth note \\
\end{tabular}
\end{minipage}
\textbf{Another set of notes.}
\begin{minipage}[t]{0.5\linewidth}
\begin{description}
\item[Note 1:] This is the first note \\
\item[Note 2:] This is the second note \\
\item[Note 3:] This is the third note \\
\item[Note 4:] This is the fourth note \\
\end{description}
\end{minipage}
\end{document}
由于minipage
/\parbox
框中基线设置的已知问题,你最好将整个组合设置minipage
在tabular
嵌套中tabular
:
\begin{tabular}[t]{@{}p{0.5\linewidth}@{}}
\begin{tabularx}{\linewidth}[t]{@{}r@{ }X@{}}
Note 1: & This is the first note \\
Note 2: & This is the second note \\
Note 3: & This is the third note \\
Note 4: & This is the fourth note \\
\end{tabularx}
\end{tabular}
我插入了一个tabularx
inner 允许固定宽度的0.5\linewidth
结构。