我正在尝试垂直居中此表的第一列,但是当我在第二列插入方程式时,第一列不考虑垂直居中。我该怎么办?
\documentclass[a4paper,12pt]{report}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{array}
\begin{document}
\begin{table}[htbp]
\centering
\begin{tabular}{>{\centering\arraybackslash}m{4cm}>{\centering\arraybackslash}p{5cm}}
\toprule
Models & Matrix \\
\midrule
Model 1 & \vbox{ \begin{equation}
\begin{bmatrix}
1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1
\end{bmatrix}
\end{equation}} \\
Model 2 & \vbox{ \begin{equation}
\begin{bmatrix}
1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1
\end{bmatrix}
\end{equation}} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案1
将$\vcenter{...}$
应用于\vbox
。
\documentclass[a4paper,12pt]{report}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{array}
\begin{document}
\begin{table}[htbp]
\centering
\begin{tabular}{>{\centering\arraybackslash}m{4cm}>{\centering\arraybackslash}p{5cm}}
\toprule
Models & Matrix \\
\midrule
Model 1 & $\vcenter{\vbox{ \begin{equation}
\begin{bmatrix}
1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1
\end{bmatrix}
\end{equation}}}$ \\
Model 2 & $\vcenter{\vbox{ \begin{equation}
\begin{bmatrix}
1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1
\end{bmatrix}
\end{equation}}}$ \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
该解决方案的一个变体m
,具有改进的垂直间距:
\documentclass[a4paper,12pt]{report}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{array}
\begin{document}
\begin{table}[htbp]
\centering
\begin{tabular}{@{}>{\centering\arraybackslash}m{4cm}>{\centering\arraybackslash\vspace{-\baselineskip}\equation}m{5cm} <{\endequation\vspace{-\belowdisplayskip}}@{}}
\toprule
Models & \multicolumn{1}{c}{Matrix} \\
\midrule
Model 1 & \begin{bmatrix}
1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1
\end{bmatrix} \\
Model 2 &
\begin{bmatrix}
1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1
\end{bmatrix}
\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案3
使用\begin{minipage}{\linewidth} ... \end{minipage}
而不是\vbox{...}
。
如果您有许多这样的矩阵,请定义一个命令:
\newcommand\eqmatrix[2]%
{\begin{minipage}{\linewidth}
\begin{equation}
\begin{bmatrix}
#1
\end{bmatrix}
\label{#2}
\end{equation}
\end{minipage}%
}
\documentclass[a4paper,12pt]{report}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{array}
\newcommand\eqmatrix[2]%
{\begin{minipage}{\linewidth}
\begin{equation}
\begin{bmatrix}
#1
\end{bmatrix}
\label{#2}
\end{equation}
\end{minipage}%
}
\begin{document}
\begin{table}[htbp]
\centering
\begin{tabular}{>{\centering\arraybackslash}m{4cm}>{\centering\arraybackslash}p{5cm}}
\toprule
Models & Matrix \\
\midrule
Model 1 & \eqmatrix{1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1}{m1}\\
Model 2 & \eqmatrix{1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1}{m2}\\
\bottomrule
\end{tabular}
\end{table}
\end{document}