表格:标题和对齐问题

表格:标题和对齐问题

我想要创建两个并排的表格,每个表格上方都有自己的标题。这是我的尝试

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath,amssymb,amsfonts,systeme}
\usepackage{makecell}
\setcellgapes{5pt}
\usepackage{float}
\floatstyle{plaintop}
\restylefloat{table}

\begin{document}

\begin{table}[H]
\centering
\makegapedcells
\begin{tabular}{| *{7}{>{\centering\arraybackslash}p{1.5cm} |}}
\hline
$\theta $ & $\eta$ & $\nu$ & $\rho$ \\ \hline\hline
20 & 22.727 & 22.272 & 1.0204 \\ \hline
25 & 17.962 & 17.670 & 1.0165 \\ \hline
30 & 14.416 & 14.234 & 1.0127 \\ \hline
35 & 11.631 & 11.528 & 1.0090 \\ \hline
40 & 9.8771 & 9.8264 & 1.0052 \\ \hline
45 & 9.1780 & 9.1658 & 1.0013 \\ \hline
50 & error & error & error \\ \hline
\caption{$x_1 = 0.4$}
\end{tabular}
\end{table}
\quad
\begin{table}[H]
\centering
\makegapedcells
\begin{tabular}{| *{7}{>{\centering\arraybackslash}p{1.5cm} |}}
\hline
$\theta $ & $\eta$ & $\nu$ & $\rho$ \\ \hline\hline
20 & 39.976 & 37.827 & 1.0568 \\ \hline
25 & 30.827 & 29.273 & 1.0531 \\ \hline
30 & 24.157 & 23.027 & 1.0491 \\ \hline
35 & 19.205 & 18.373 & 1.0453 \\ \hline
40 & 15.486 & 14.867 & 1.0417 \\ \hline
45 & 12.577 & 12.115 & 1.0381 \\ \hline
50 & error & error & error \\ \hline
\caption{$x_1 = 0.5$}
\end{tabular}
\end{table}

\end{document}

在此处输入图片描述

如你所见,标题的位置很不寻常,而且表格并没有并排放置

你能帮助我吗?

先感谢您

答案1

有两种可能性:

我已将\caption命令从环境内部移至tabular环境之前\begin{tabular},因此无需使用\restylefloat。我还大幅减少了边距,以使两个表格适合文本宽度。最后,我还将列说明符从更改为,因为74的表格中只需要四列。为了将表格彼此相邻,请将它们放在同一个table环境中,并将每个表格tabulars放在自己的minipage环境中。

[H]由于您使用了将表准确放置在代码中定义的位置的选项,因此我添加了第二个示例。在此,我完全删除了环境,而是从包中table使用。\captionof{table}caption

在此处输入图片描述

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath,amssymb,amsfonts,systeme}
\usepackage{makecell}
\setcellgapes{5pt}
\usepackage{float}
%\floatstyle{plaintop}
%\restylefloat{table}
\usepackage{caption}
\usepackage[margin=1.5cm]{geometry}

\begin{document}

\begin{table}
\begin{minipage}{0.5\textwidth}
\centering
\makegapedcells
\caption{$x_1 = 0.4$}
\begin{tabular}{| *{4}{>{\centering\arraybackslash}p{1.5cm} |}}
\hline
$\theta $ & $\eta$ & $\nu$ & $\rho$ \\ \hline\hline
20 & 22.727 & 22.272 & 1.0204 \\ \hline
25 & 17.962 & 17.670 & 1.0165 \\ \hline
30 & 14.416 & 14.234 & 1.0127 \\ \hline
35 & 11.631 & 11.528 & 1.0090 \\ \hline
40 & 9.8771 & 9.8264 & 1.0052 \\ \hline
45 & 9.1780 & 9.1658 & 1.0013 \\ \hline
50 & error & error & error \\ \hline
\end{tabular}
\end{minipage}%
\begin{minipage}{0.5\textwidth}
\centering
\makegapedcells
\caption{$x_1 = 0.5$}
\begin{tabular}{| *{4}{>{\centering\arraybackslash}p{1.5cm} |}}
\hline
$\theta $ & $\eta$ & $\nu$ & $\rho$ \\ \hline\hline
20 & 39.976 & 37.827 & 1.0568 \\ \hline
25 & 30.827 & 29.273 & 1.0531 \\ \hline
30 & 24.157 & 23.027 & 1.0491 \\ \hline
35 & 19.205 & 18.373 & 1.0453 \\ \hline
40 & 15.486 & 14.867 & 1.0417 \\ \hline
45 & 12.577 & 12.115 & 1.0381 \\ \hline
50 & error & error & error \\ \hline
\end{tabular}
\end{minipage}
\end{table}


\noindent
\begin{minipage}{0.5\textwidth}
\centering
\makegapedcells
\captionof{table}{$x_1 = 0.4$}
\begin{tabular}{| *{4}{>{\centering\arraybackslash}p{1.5cm} |}}
\hline
$\theta $ & $\eta$ & $\nu$ & $\rho$ \\ \hline\hline
20 & 22.727 & 22.272 & 1.0204 \\ \hline
25 & 17.962 & 17.670 & 1.0165 \\ \hline
30 & 14.416 & 14.234 & 1.0127 \\ \hline
35 & 11.631 & 11.528 & 1.0090 \\ \hline
40 & 9.8771 & 9.8264 & 1.0052 \\ \hline
45 & 9.1780 & 9.1658 & 1.0013 \\ \hline
50 & error & error & error \\ \hline
\end{tabular}
\end{minipage}%
\begin{minipage}{0.5\textwidth}
\centering
\makegapedcells
\captionof{table}{$x_1 = 0.5$}
\begin{tabular}{| *{4}{>{\centering\arraybackslash}p{1.5cm} |}}
\hline
$\theta $ & $\eta$ & $\nu$ & $\rho$ \\ \hline\hline
20 & 39.976 & 37.827 & 1.0568 \\ \hline
25 & 30.827 & 29.273 & 1.0531 \\ \hline
30 & 24.157 & 23.027 & 1.0491 \\ \hline
35 & 19.205 & 18.373 & 1.0453 \\ \hline
40 & 15.486 & 14.867 & 1.0417 \\ \hline
45 & 12.577 & 12.115 & 1.0381 \\ \hline
50 & error & error & error \\ \hline
\end{tabular}
\end{minipage}


\end{document}

如果您不想减少边距,您可能需要考虑减少列宽。例如,您可以使用ctpe 列。使用此列类型,两个表将很容易在 documentclass 的标准文本宽度内并排放置article。就我个人而言,我更喜欢行数较少的表格,因此在下面的 MWE 中,我还提供了一个如何使用包来实现这一点的示例booktabs。(如果您还想根据小数点分隔符对齐数字,您可能需要查看siunitxdcolumn包。)

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath,amssymb,amsfonts,systeme}
\usepackage{makecell}
\setcellgapes{5pt}
\usepackage{booktabs}

\begin{document}

\begin{table}
\begin{minipage}{0.5\textwidth}
\centering
\makegapedcells
\caption{$x_1 = 0.4$}
\begin{tabular}{| *{4}{c|}}
\hline
$\theta $ & $\eta$ & $\nu$ & $\rho$ \\ \hline\hline
20 & 22.727 & 22.272 & 1.0204 \\ \hline
25 & 17.962 & 17.670 & 1.0165 \\ \hline
30 & 14.416 & 14.234 & 1.0127 \\ \hline
35 & 11.631 & 11.528 & 1.0090 \\ \hline
40 & 9.8771 & 9.8264 & 1.0052 \\ \hline
45 & 9.1780 & 9.1658 & 1.0013 \\ \hline
50 & error & error & error \\ \hline
\end{tabular}
\end{minipage}%
\begin{minipage}{0.5\textwidth}
\centering
\makegapedcells
\caption{$x_1 = 0.5$}
\begin{tabular}{| *{4}{c|}}
\hline
$\theta $ & $\eta$ & $\nu$ & $\rho$ \\ \hline\hline
20 & 39.976 & 37.827 & 1.0568 \\ \hline
25 & 30.827 & 29.273 & 1.0531 \\ \hline
30 & 24.157 & 23.027 & 1.0491 \\ \hline
35 & 19.205 & 18.373 & 1.0453 \\ \hline
40 & 15.486 & 14.867 & 1.0417 \\ \hline
45 & 12.577 & 12.115 & 1.0381 \\ \hline
50 & error & error & error \\ \hline
\end{tabular}
\end{minipage}
\end{table}

\begin{table}
\begin{minipage}{0.5\textwidth}
\centering
\caption{$x_1 = 0.4$}
\begin{tabular}{cccc}
\toprule
$\theta $ & $\eta$ & $\nu$ & $\rho$ \\ \midrule
20 & 22.727 & 22.272 & 1.0204 \\ 
25 & 17.962 & 17.670 & 1.0165 \\ 
30 & 14.416 & 14.234 & 1.0127 \\ 
35 & 11.631 & 11.528 & 1.0090 \\ 
40 & 9.8771 & 9.8264 & 1.0052 \\ 
45 & 9.1780 & 9.1658 & 1.0013 \\ 
50 & error & error & error \\ \bottomrule
\end{tabular}
\end{minipage}%
\begin{minipage}{0.5\textwidth}
\centering
\caption{$x_1 = 0.5$}
\begin{tabular}{cccc}
\toprule
$\theta $ & $\eta$ & $\nu$ & $\rho$ \\ \midrule
20 & 39.976 & 37.827 & 1.0568 \\ 
25 & 30.827 & 29.273 & 1.0531 \\ 
30 & 24.157 & 23.027 & 1.0491 \\ 
35 & 19.205 & 18.373 & 1.0453 \\ 
40 & 15.486 & 14.867 & 1.0417 \\ 
45 & 12.577 & 12.115 & 1.0381 \\ 
50 & error & error & error \\ \bottomrule
\end{tabular}
\end{minipage}
\end{table}

\end{document}

在此处输入图片描述


由于您的两个表似乎紧密相关,您也可以将它们合并为一个:

在此处输入图片描述

\documentclass{article}
\usepackage{caption}
\usepackage{booktabs}

\begin{document}

\begin{table}
\centering
\caption{The caption text}
\begin{tabular}{ccccccc}
\toprule
& \multicolumn{3}{c}{$x_1 = 0.4$} & \multicolumn{3}{c}{$x_1 = 0.5$} \\
\cmidrule(r){2-4} \cmidrule(l){5-7}
$\theta $ & $\eta$ & $\nu$ & $\rho$ & $\eta$ & $\nu$ & $\rho$ \\ \midrule
20 & 22.727 & 22.272 & 1.0204 & 39.976 & 37.827 & 1.0568\\ 
25 & 17.962 & 17.670 & 1.0165 & 30.827 & 29.273 & 1.0531\\ 
30 & 14.416 & 14.234 & 1.0127 & 24.157 & 23.027 & 1.0491\\ 
35 & 11.631 & 11.528 & 1.0090 & 19.205 & 18.373 & 1.0453\\ 
40 & 9.8771 & 9.8264 & 1.0052 & 15.486 & 14.867 & 1.0417\\ 
45 & 9.1780 & 9.1658 & 1.0013 & 12.577 & 12.115 & 1.0381\\ 
50 & error  & error  & error  & error  & error  & error \\ \bottomrule
\end{tabular}
\end{table}

\end{document}

答案2

带有siunitxfloatrow包的布局(与 不兼容float,但从 重新定义了宏float):

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath,amssymb,systeme}
\usepackage{makecell}
\setcellgapes{5pt}
\usepackage{floatrow}
\usepackage{siunitx}

\begin{document}

Some text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text.

\begin{table}[H]
\floatsetup[table]{floatrowsep=qquad}
\setlength{\tabcolsep}{4pt}
\sisetup{table-format =2.4, table-number-alignment=center}
\begin{floatrow}
\centering
\makegapedcells
\ttabbox{\caption{$x_1 = 0.4$}\label{x1: 4}}{
\begin{tabular}{|>{\centering}p{1cm}|*{3}{S |}}
\hline
{$\theta $} & {$\eta$} & {$\nu$} & {$\rho$} \\ \hline\hline
20 & 22.727 & 22.272 & 1.0204 \\ \hline
25 & 17.962 & 17.670 & 1.0165 \\ \hline
30 & 14.416 & 14.234 & 1.0127 \\ \hline
35 & 11.631 & 11.528 & 1.0090 \\ \hline
40 & 9.8771 & 9.8264 & 1.0052 \\ \hline
45 & 9.1780 & 9.1658 & 1.0013 \\ \hline
50 & {error} & {error} & {error} \\ \hline

\end{tabular}}
\ttabbox{\caption{$x_1 = 0.5$}\label{x1: 5}}
{\begin{tabular}{|>{\centering}p{1cm}|*{3}{S |}}
\hline
{$\theta $} & {$\eta$} & {$\nu$} & {$\rho$} \\ \hline\hline
20 & 39.976 & 37.827 & 1.0568 \\ \hline
25 & 30.827 & 29.273 & 1.0531 \\ \hline
30 & 24.157 & 23.027 & 1.0491 \\ \hline
35 & 19.205 & 18.373 & 1.0453 \\ \hline
40 & 15.486 & 14.867 & 1.0417 \\ \hline
45 & 12.577 & 12.115 & 1.0381 \\ \hline
50 & {error} & {error} & {error} \\ \hline
\end{tabular}}
\end{floatrow}
\end{table}

\end{document} 

在此处输入图片描述

相关内容