表格中有两列对齐,有一列未对齐

表格中有两列对齐,有一列未对齐

我正在尝试制作一个包含三列的表格,前两列按行对齐(通常的方式),但第三列仅与顶部的前两列对齐。以下是我尝试过的方法:

\documentclass[landscape,letterpaper,11pt]{article}

\usepackage[left=0.5in,top=0.5in,right=0.5in,bottom=0.5in,nohead]{geometry}
\pagestyle{empty}

\begin{document}

\begin{table}[h]
\begin{tabular}{p{0.6\textwidth}p{0.3\textwidth}}
\begin{tabular}{p{0.3\textwidth}p{0.3\textwidth}}
This is aligned with the first equation & $\displaystyle x^2 + y^2 = z^2 $ \\
This is aligned with the second equation & $\displaystyle e^{i\theta} = \cos(\theta) + i\sin(\theta)$
\end{tabular}
&
\begin{itemize}
\item Bullets.
\item Go with the table in general.
\item The top of the first bullet should be aligned with the tops of the rest of the table.
\end{itemize}
\end{tabular}
\end{table}

\end{document}

问题是,当我这样做时,三列的顶部没有对齐。我哪里做错了?

答案1

首先,tabular应该声明内部[t](顶部对齐)。为了删除p单元格中逐项列表前的空格,有多种方法。

如果你总是在这些单元格中有一个单独的项目列表,以下是略微修改的Danie Els 的回答可能做:

\documentclass[landscape,letterpaper,11pt]{article}
\usepackage{calc,array}
\usepackage[left=0.5in,top=0.5in,right=0.5in,bottom=0.5in,nohead]{geometry}
\pagestyle{empty}

\makeatletter
\newcolumntype{i}[1]{%
    >{\minipage[t]{\linewidth}\arraybackslash\itemize}
    p{#1}%
    <{\@finalstrut\@arstrutbox\enditemize\endminipage}}

\makeatother

\begin{document}

\noindent
\begin{tabular}{@{}p{0.6\textwidth}i{0.4\textwidth-2\tabcolsep}@{}}
\hline
\begin{tabular}[t]{@{}p{0.3\textwidth-\tabcolsep}p{0.3\textwidth-\tabcolsep}@{}}
This is aligned with the first equation & $\displaystyle x^2 + y^2 = z^2 $ \\
This is aligned with the second equation & $\displaystyle e^{i\theta} = \cos(\theta) + i\sin(\theta)$
\end{tabular}
&
\item Bullets.
\item Go with the table in general.
\item The top of the first bullet should be aligned with the tops of the rest of the table.
\\
\hline
\end{tabular}

\end{document}

(规则只是为了显示间距和对齐。)

注意我是如何计算表格列的宽度以便它们完全填满行的(calc为此需要该包)。

如果最后一列单元格并不总是只有一个逐项列表,那么将列表包含在内\begin{minipage}[t]{\linewidth}...\end{minipage}(几乎) 也可以达到相同的效果。当然,列应该声明为p{...}

在此处输入图片描述

答案2

egreg 的解决方案超出了我的需要,因此我最终根据他的评论选择了这个稍微简单的版本:

\documentclass[landscape,letterpaper,11pt]{article}

\usepackage[left=0.5in,top=0.5in,right=0.5in,bottom=0.5in,nohead]{geometry}
\pagestyle{empty}

% http://tex.stackexchange.com/questions/6445/preventing-itemize-environment-to-insert-initial-vertical-space
\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother

\begin{document}

\begin{table}[h]
\begin{tabular}{p{0.6\textwidth}p{0.3\textwidth}}
\begin{tabular}[t]{p{0.3\textwidth}p{0.3\textwidth}}
This is aligned with the first equation & $\displaystyle x^2 + y^2 = z^2 $ \\
This is aligned with the second equation & $\displaystyle e^{i\theta} = \cos(\theta) + i\sin(\theta)$
\end{tabular}
&
{\compress}
\begin{itemize}
\item Bullets.
\item Go with the table in general.
\item The top of the first bullet should be aligned with the tops of the rest of the table.
\end{itemize}
\end{tabular}
\end{table}

\end{document}

相关内容