两张长度不等的桌子并排摆放

两张长度不等的桌子并排摆放

我尝试了下面提到的解决方案这里,将两张长度不等的桌子并排摆放。

\documentclass{article}
\usepackage{subcaption,booktabs}
\usepackage{multirow, makecell}

\begin{document}

\begin{table}[htb]%\[!htb\]
\caption{Main caption.}
\begin{subtable}[t]{.3\linewidth}
\raggedright
\begin{tabular}{c c ccc}
\toprule 
\multirow{2.5}{*}{$N$} & {\multirow{2.5}{*}{\makecell[c]{ Multiple \\parameters}}}  &
\multicolumn{3}{c}{Values} \\
\cmidrule{3-5}
& & X & Y & Z  \\
\midrule
\textbf{1}\\\cmidrule{1-1}
& $D$ & 0.8 & 0.8 & 0.8  \\ 
& $S$  & 0.8 & 0.8 & 0.8  \\  
\textbf{2}\\\cmidrule{1-1}
& $D$ & 0.1 & 0.8 & 0.8  \\ 
& $S$  & 0.8 & 0.8 & 0.8  \\  
\textbf{3}\\\cmidrule{1-1}
& $D$ & 0.8 & 0.8 & 0.8   \\ 
& $W$  & 0.8 & 0.8 & 0.8  \\  
\textbf{4}\\\cmidrule{1-1}
& $S$ & 0.8 & 0.8 & 0.8   \\ 
& $W$  & 0.8 & 0.8 & 0.8  \\  
\textbf{5}\\\cmidrule{1-1}
& $S$ & 0.8 & 0.8 & 0.8   \\ 
& $A$  & 0.8 & 0.8 & 0.8  \\  
\bottomrule
\end{tabular}
 \end{subtable}%
  \begin{subtable}[t]{.3\linewidth}
    \raggedleft
\begin{tabular}{c c ccc}
\toprule 
\multirow{2.5}{*}{$N$} & {\multirow{2.5}{*}{\makecell[c]{ Multiple \\parameters}}}  &
\multicolumn{3}{c}{Values} \\
\cmidrule{3-5}
& & X & Y & Z  \\
\midrule
\textbf{1}\\\cmidrule{1-1}
& $D$ & 0.8 & 0.8 & 0.8  \\ 
& $S$  & 0.8 & 0.8 & 0.8  \\  
\textbf{2}\\\cmidrule{1-1}
& $D$ & 0.1 & 0.7 & 0.8  \\ 
& $S$  & 0.8 & 0.8 & 0.8  \\  
\textbf{3}\\\cmidrule{1-1}
& $D$ & 0.8 & 0.8 & 0.8   \\ 
& $W$  & 0.8 & 0.8 & 0.8  \\ 
\bottomrule
\end{tabular}
    \end{subtable}
\end{table}

\end{document}

输出为:

在此处输入图片描述

从上图可以看出,表格顶部没有对齐,而且重叠。我犯了什么错误?有人能帮我得到想要的输出吗?

答案1

使用floatrow包及其subfloatrow环境相当简单:

\documentclass{article}
\usepackage{subcaption,booktabs}
\usepackage{multirow, makecell}
\usepackage{floatrow}
\DeclareFloatSeparators{hfill}{\hfill}

\begin{document}

\begin{table}[!htb]%
\ttabbox{%
\begin{subfloatrow}[2]
\raggedright
\ttabbox{\caption{}}{%
\begin{tabular}{c c ccc}
\toprule
\multirow{2.5}{*}{$N$} & {\multirow{2.5}{*}{\makecell[c]{ Multiple \\parameters}}} &
\multicolumn{3}{c}{Values} \\
\cmidrule{3-5}
& & X & Y & Z \\
\midrule
\textbf{1}\\\cmidrule{1-1}
& $D$ & 0.8 & 0.8 & 0.8 \\
& $S$ & 0.8 & 0.8 & 0.8 \\
\textbf{2}\\\cmidrule{1-1}
& $D$ & 0.1 & 0.8 & 0.8 \\
& $S$ & 0.8 & 0.8 & 0.8 \\
\textbf{3}\\\cmidrule{1-1}
& $D$ & 0.8 & 0.8 & 0.8 \\
& $W$ & 0.8 & 0.8 & 0.8 \\
\textbf{4}\\\cmidrule{1-1}
& $S$ & 0.8 & 0.8 & 0.8 \\
& $W$ & 0.8 & 0.8 & 0.8 \\
\textbf{5}\\\cmidrule{1-1}
& $S$ & 0.8 & 0.8 & 0.8 \\
& $A$ & 0.8 & 0.8 & 0.8 \\
\bottomrule
\end{tabular}}
\hfill
\ttabbox{\caption{}}{\begin{tabular}{c c ccc}
\toprule
\multirow{2.5}{*}{$N$} & {\multirow{2.5}{*}{\makecell[c]{ Multiple \\parameters}}} &
\multicolumn{3}{c}{Values} \\
\cmidrule{3-5}
& & X & Y & Z \\
\midrule
\textbf{1}\\\cmidrule{1-1}
& $D$ & 0.8 & 0.8 & 0.8 \\
& $S$ & 0.8 & 0.8 & 0.8 \\
\textbf{2}\\\cmidrule{1-1}
& $D$ & 0.1 & 0.7 & 0.8 \\
& $S$ & 0.8 & 0.8 & 0.8 \\
\textbf{3}\\\cmidrule{1-1}
& $D$ & 0.8 & 0.8 & 0.8 \\
& $W$ & 0.8 & 0.8 & 0.8 \\
\bottomrule
\end{tabular}}
\end{subfloatrow}}
{\caption{Main caption}}
\end{table}

\end{document} 

在此处输入图片描述

相关内容