表格不并排对齐

表格不并排对齐

在此处输入图片描述

\usepackage{tabularx}
\usepackage{multicol}

\begin{table}[ht]
\begin{minipage}[b]{0.5\linewidth}%\centering
\begin{tabular}{|c|c|c|c|}
\hline
    & One & Twp & Three \\
 \hline
1 & Subject A: & Subject A & Subject  \\
2 & Subject B & Subject B& Subject  \\
3 & Subject C & Subject C & Subject   \\
4 & Subject D & Subject D & Subject  \\
4 & Subject E & Subject E & Subject   \\
5 &Subject F & Subject F & Subject  \\
6 & Subject G & Subject G & Subject  \\
7 &Subject H &Subject H &Subject   \\
\hline
\end{tabular}
\caption{Table 1}
\end{minipage}
\hspace{0.5cm}
\begin{minipage}[b]{0.5\linewidth}
\centering
\begin{tabular}{|c|c|c|c|}
\hline
    & One & Twp & Three \\
 \hline
1 & Subject A: & Subject A & Subject  \\
2 & Subject B & Subject B& Subject  \\
3 & Subject C & Subject C & Subject   \\
4 & Subject D & Subject D & Subject  \\
4 & Subject E & Subject E & Subject   \\
5 &Subject F & Subject F & Subject  \\
6 & Subject G & Subject G & Subject  \\
7 &Subject H &Subject H &Subject   \\
\hline
\end{tabular}
\caption{Table 2}
\end{minipage}
\end{table}

我尝试并排创建两个表格,但在 PDF 中它们似乎没有对齐。第二个表格比第一个表格略低,我不知道如何修复它。

如有任何建议,我们将不胜感激。

答案1

尝试这个:

\documentclass{article}
\usepackage{tabularx}
\usepackage{multicol}

\begin{document}
\begin{table}[ht]
\begin{minipage}[b]{0.5\linewidth}%\centering
\begin{tabular}{|c|c|c|c|}
\hline
    & One & Twp & Three \\
\hline
1 & Subject A: & Subject A & Subject  \\
2 & Subject B & Subject B& Subject  \\
3 & Subject C & Subject C & Subject   \\
4 & Subject D & Subject D & Subject  \\
4 & Subject E & Subject E & Subject   \\
5 &Subject F & Subject F & Subject  \\
6 & Subject G & Subject G & Subject  \\
7 &Subject H &Subject H &Subject   \\
\hline
\end{tabular}
\caption{Table 1}
\end{minipage}
\hspace{0.5cm}
\begin{minipage}[b]{0.5\linewidth}
\centering
\begin{tabular}{|c|c|c|c|}
\hline
    & One & Twp & Three \\
 \hline
1 & Subject A: & Subject A & Subject  \\
2 & Subject B & Subject B& Subject  \\
3 & Subject C & Subject C & Subject   \\
4 & Subject D & Subject D & Subject  \\
4 & Subject E & Subject E & Subject   \\
5 &Subject F & Subject F & Subject  \\
6 & Subject G & Subject G & Subject  \\
7 &Subject H &Subject H &Subject   \\
\hline
\end{tabular}
\caption{Table 2}
\end{minipage}
\end{table}

\end{document}

答案2

问题:

  • 您的表格超出了文本宽度,因为您使用了 2 倍加0.5\linewidth\hspace{0.5cm}这可能会导致对齐问题,并且通常会带来问题。

  • 您使用 将小页面对齐到底部[b],而不是顶部。我猜是因为标题,但这样您就无法控制顶部了。

我建议:

  • 始终注意行宽和文本宽度。注意:小页面之间的换行符或空白也算数,需要留出空间。%在行尾前插入可防止这种情况发生。

  • 使用可选的高度参数 或minipage\parbox您可以使用固定高度、顶部对齐(下方posinner-pos),或许\vfill可以实现顶部和底部对齐(标题)。

    句法:\begin{minipage}[pos][height][inner-pos]{width}

  • 进一步提示:垂直线确实会分散注意力。对我来说,一些水平线通常没问题。我强烈建议使用booktabs包装。只要看看好书,你就会发现精美的表格不会用垂直线打断行。

答案3

这似乎很有效。

\documentclass{article}
\usepackage{fullpage}
\begin{document}
\begin{table}
\noindent
\parbox{.5\textwidth}{%
\centering
\begin{tabular}{|c|c|c|c|}
\hline
    & One & Twp & Three \\
 \hline
1 & Subject A: & Subject A & Subject  \\
2 & Subject B & Subject B& Subject  \\
3 & Subject C & Subject C & Subject   \\
4 & Subject D & Subject D & Subject  \\
4 & Subject E & Subject E & Subject   \\
5 &Subject F & Subject F & Subject  \\
6 & Subject G & Subject G & Subject  \\
7 &Subject H &Subject H &Subject   \\
\hline
\end{tabular}
\caption{Table 1}
}%
\parbox{.5\textwidth}{%
\centering
\begin{tabular}{|c|c|c|c|}
\hline
    & One & Twp & Three \\
 \hline
1 & Subject A: & Subject A & Subject  \\
2 & Subject B & Subject B& Subject  \\
3 & Subject C & Subject C & Subject   \\
4 & Subject D & Subject D & Subject  \\
4 & Subject E & Subject E & Subject   \\
5 &Subject F & Subject F & Subject  \\
6 & Subject G & Subject G & Subject  \\
7 &Subject H &Subject H &Subject   \\
\hline
\end{tabular}
\caption{Table 2}
}%
\end{table}
\end{document}

这不是您问题的一部分,但我认为如果您遵循文档中给出的建议booktabs,您可以制作出更好看的表格。比较一下。

\documentclass{article}
\usepackage{fullpage}
\usepackage{booktabs}
\begin{document}
\begin{table}
\noindent
\parbox{.5\textwidth}{%
\centering
\begin{tabular}{rllll}
\toprule
    & \multicolumn{1}{c}{One}
    & \multicolumn{1}{c}{Two}
    & \multicolumn{1}{c}{Three} \\
\midrule
1 & Subject A: & Subject A & Subject  \\
2 & Subject B & Subject B& Subject  \\
3 & Subject C & Subject C & Subject   \\
4 & Subject D & Subject D & Subject  \\
4 & Subject E & Subject E & Subject   \\
5 &Subject F & Subject F & Subject  \\
6 & Subject G & Subject G & Subject  \\
7 &Subject H &Subject H &Subject   \\
\bottomrule
\end{tabular}
\caption{Table 1}
}%
\parbox{.5\textwidth}{%
\centering
\begin{tabular}{rllll}
\toprule
    & \multicolumn{1}{c}{One}
    & \multicolumn{1}{c}{Two}
    & \multicolumn{1}{c}{Three} \\
\midrule
1 & Subject A: & Subject A & Subject  \\
2 & Subject B & Subject B& Subject  \\
3 & Subject C & Subject C & Subject   \\
4 & Subject D & Subject D & Subject  \\
4 & Subject E & Subject E & Subject   \\
5 &Subject F & Subject F & Subject  \\
6 & Subject G & Subject G & Subject  \\
7 &Subject H &Subject H &Subject   \\
\bottomrule
\end{tabular}
\caption{Table 2}
}%
\end{table}
\end{document}

相关内容