两个表不能同时居中对齐

两个表不能同时居中对齐

我有两个表格,它们的列号不同。现在我有以下代码(我是 LaTeX 新手,如果有更好的方法将两个表格放在一个组中,请告诉我)。

\begin{table}[H]
\centering
\begin{tabular}{|c|c|c|c|c|c|}
\hline
     & $W_f, W_u, W_c, W_o$ & $W_y$        & $b_f, b_u, b_c, b_o$ & $b_y$      \\ \hline
Dim. & $(n_a, n_a + n_x)$   & $(n_y, n_a)$ & $(n_a, 1)$           & $(n_y, 1)$ \\ \hline
\end{tabular}
\newline
\vspace*{0.1cm}
\newline
\centering
\begin{tabular}{|c|c|c|c|}
\hline
     & $a^{<t>}, a^{<t-1>}, c^{<t>}, c^{<t-1>}$ & $\Gamma_f, \Gamma_u, \Gamma_o$ & $\tilde{c}^{<t>}$ \\ \hline
Dim. & $(n_a, m)$                               & $(n_a, m)$                     & $(n_a, m)$      \\ \hline
\end{tabular}
\caption{The dimension of used parameters in an LSTM forward pass. We have a dimension size of $m$ because we are doing vectorization calculation for $m$ inputs simultaneously.}
\label{table:lstm-fp}
\end{table}

在此处输入图片描述

我想要的只是让这两个表垂直对齐到中心。但是我失败了一段时间。

编辑:

我试过了\bigskip,但是没用 :(

\begin{table}[H]
\centering
\begin{tabular}{|c|c|c|c|c|}
\hline
        & $W_f, W_u, W_c, W_o$ & $W_y$        & $b_f, b_u, b_c, b_o$ & $b_y$      \\ \hline
Dim. & $(n_a, n_a + n_x)$   & $(n_y, n_a)$ & $(n_a, 1)$           & $(n_y, 1)$ \\ \hline
\end{tabular}
\bigskip
\begin{tabular}{|c|c|c|c|}
\hline
        & $a^{\langle t \rangle}, a^{\langle t-1 \rangle}, c^{\langle t \rangle}, c^{\langle t-1 \rangle}$ & $\Gamma_f, \Gamma_u, \Gamma_o$ & $\tilde{c}^{\langle t \rangle}$ \\ \hline
Dim. & $(n_a, m)$                               & $(n_a, m)$                     & $(n_a, m)$      \\ \hline
\end{tabular}
\caption{The dimension of used parameters in an LSTM forward pass. We have a dimension size of $m$ because we are doing vectorization calculation for $m$ inputs simultaneously.}
\label{table:lstm-fp}
\end{table}

答案1

tabular我建议对两个表使用一个公共环境,并应用于\multicolumn第二个表的第 2 列和第 3 列。

我稍微拉长了阵列间距。

也不建议在表格中使用垂直规则。

\documentclass{article}


\begin{document}

\begin{table}
\centering
\renewcommand{\arraystretch}{1.3}
\begin{tabular}{|*{5}{c|}}
\hline
     & $W_f, W_u, W_c, W_o$ & $W_y$        & $b_f, b_u, b_c, b_o$ & $b_y$      \\ \hline
Dim. & $(n_a, n_a + n_x)$   & $(n_y, n_a)$ & $(n_a, 1)$           & $(n_y, 1)$ \\ \hline
\multicolumn{5}{c}{} \\
\hline
& \multicolumn{2}{c|}{$a^{<t>}, a^{<t-1>}, c^{<t>}, c^{<t-1>}$} & $\Gamma_f, \Gamma_u, \Gamma_o$ & $\tilde{c}^{<t>}$ \\ \hline
Dim. & \multicolumn{2}{c|}{$(n_a, m)$ }                              & $(n_a, m)$                     & $(n_a, m)$      \\ \hline
\end{tabular}
\caption{The dimension of used parameters in an LSTM forward pass. We have a dimension size of $m$ because we are doing vectorization calculation for $m$ inputs simultaneously.} \label{table:lstm-fp}
\end{table}

\end{document}

在此处输入图片描述

答案2

只需移除

\newline
\vspace*{0.1cm}
\newline
\centering

并在两个环境之间插入\bigskip(或),夹在空白行之间。\medskiptabular


附录:我认为你选择创建两个独立的tabular环境,这样材料的宽度就不会超过\textwidth。我认为最好创建一个单身的垂直方向的表格,而不是将信息分散在两个独立的tabular环境中。另一个问题是:由于几乎所有的材料都是数学模式,使用环境可以array大大减少$必须输入的符号数量。我还想建议您通过省略所有垂直线并仅使用一条水平线来使表格看起来更加“开放”。您的读者会很感激,他们可能会通过实际研究表格材料来回报您的努力……

在此处输入图片描述

\documentclass{article}
\usepackage{booktabs,mathtools}
\DeclarePairedDelimiter{\zz}{\langle}{\rangle}
\begin{document}

\begin{table}
\centering
\renewcommand\arraystretch{1.2}

$\begin{array}{@{}ll@{}}
\textnormal{Parameters} & \textnormal{Dimension} \\
\midrule % from 'booktabs' package
W_f, W_u, W_c, W_o & (n_a, n_a + n_x)\\
W_y & (n_y, n_a)\\
b_f, b_u, b_c, b_o & (n_a, 1)\\
b_y & (n_y, 1) \\
a^{\zz{t}}, a^{\zz{t-1}}, c^{\zz{t}}, c^{\zz{t-1}} & (n_a, m) \\
\Gamma_f, \Gamma_u, \Gamma_o & (n_a, m)\\ 
\tilde{c}^{\zz{t}} & (n_a, m) \\ 
\end{array}$

\caption{Dimensions of parameters used in an LSTM forward pass. We have a dimension size of $m$ because we are doing vectorization calculation for~$m$ inputs simultaneously.}
\label{table:lstm-fp}
\end{table}
\end{document}

相关内容