如何将不等长的表格并排放置,使小表格的文本居中

如何将不等长的表格并排放置,使小表格的文本居中

根据 egreg 的回答,我并排制作了 2 个表格:迷你页面内的表格位置

\documentclass{article}
\usepackage{booktabs,lipsum,calc}

\newsavebox{\leftbox}
\newsavebox{\rightbox}

\begin{document}
\begin{table}[tbh!]

\begin{lrbox}{\leftbox}
\addtolength{\tabcolsep}{2pt}%
\begin{tabular}{ | p{1.7cm} | p{4cm}| p{0.8cm} | }
  \hline
  col 1-1 & col 1-2 & col 1-3 \\
  \hline
\end{tabular}
\end{lrbox}

\begin{lrbox}{\rightbox}
\begin{tabular}{ |c|c| }
  \hline
  col 2-1 & col 2-2\\
  \hline
\end{tabular}
\end{lrbox}

\centering
\makebox[0pt]{%
\begin{minipage}[b]{\wd\leftbox} % A minipage that covers half the page
\centering
\caption{obs=1000, Coverage Probability}
\usebox{\leftbox}
\end{minipage}\quad
\begin{minipage}[b]{\wd\rightbox}
\centering
\caption{obs=1000, Test Statistic}
\usebox{\rightbox}
\end{minipage}%
}
\end{table}
\end{document}

它给出了这个:

在此处输入图片描述

如您所见,表格并不相等,并且第二个表格的描述缩小太多。

我怎样才能将第二个表格放在左侧空白处的中央并使描述文本更宽?因此文本从第一个表格右边距延伸到页面右边距。

答案1

对于这种情况,仍然可以使用原来的想法,但需要进行一些修改:

\documentclass{article}
\usepackage{booktabs,lipsum,calc}

\newsavebox{\leftbox}
\newsavebox{\rightbox}

\begin{document}
\begin{table}[tbh!]

\begin{lrbox}{\leftbox} % this is the wider table (top alignment)
\begin{tabular}[t]{ | p{1.7cm} | p{4cm}| p{0.8cm} | }
  \hline
  col 1-1 & col 1-2 & col 1-3 \\
  \hline
\end{tabular}
\end{lrbox}

\begin{lrbox}{\rightbox} % the narrower table (top alignment)
\begin{tabular}[t]{ |c|c| }
  \hline
  col 2-1 & col 2-2\\
  \hline
\end{tabular}
\end{lrbox}

\centering
\makebox[0pt]{%
\begin{minipage}[t]{\wd\leftbox} % A minipage that contains the wider table
\centering
\caption{obs=1000, Coverage Probability}
\usebox{\leftbox}
\end{minipage}\quad
%%%% The narrower table is set in a box as wide as allowed
%%%% The complex of the tables will stick out at left and right
%%%% Play with the coefficient (here 1.1) until the caption
%%%% to the narrower table fits
\begin{minipage}[t]{1.1\columnwidth-1em-\wd\leftbox}
\centering
\caption{obs=1000, Test Statistic}
\usebox{\rightbox}
\end{minipage}%
}
\end{table}
\end{document}

查看代码中关于修改外观的注释。

在此处输入图片描述

相关内容