一个表而不是三个单独的表中的多列

时间:2018-12-02 20:30:35

标签: latex

我要在一张桌子的背面有三列的主表。我使用了muticolumn,但是它不是一个包含三列的表,而是三个表。它是这样的: enter image description here

这是代码。我试图删除列之间的空间,使其看起来像一张桌子。任何帮助表示赞赏

\begin{table}[h!]
\center
\setlength{\tabcolsep}{2pt}
\caption{ Model of Dataset I Tested on Dataset III}
\label{my-label7}
\begin{tabular}{|l|l|l|l|l|l|l|l|l|l|l|l|l|l|l|l|l|l|l|l|l|l|l|}
\hline
\multicolumn{14}{|c|}{Model Based Approach } \\
\hline
Hosts &  A & B & D & G &  H &  I &  J  &  L &  M &  N &  P & Q & R \\ \hline
DR   & 1 & 0.85 & 0.6 & 1   & 1  & 1 & 1 & 1  & 1  & 1 & 1 & 1 & 1  \\ 
\hline
FPR & 0.04        &   0   & 0    & 0    & 0   & 0 & 0 &0   & 0 & 0 & 0 & 0 & 
0 \\ \hline

\end{tabular} 
\begin{tabular}{|l|l|l|l|l|l|l|}
\hline
\multicolumn{5}{|c|}{Instance Based Approach} \\
\hline
C  &  E &  F &  K &  O \\ \hline
1  & 0.79 & 1 & 1 & 1 \\ \hline
0 & 0 & 0.5 & 0 & 0 \\ \hline
\end{tabular}
\begin{tabular}{|l|l|}
\hline
\multicolumn{1}{|c|}{Average} \\
\hline
All   \\ \hline
\textbf{0.95}  \\ \hline
\textbf{0.03}  \\ \hline
\end{tabular}
\end{table}

1 个答案:

答案 0 :(得分:0)

该表被设置为三个不同的表,因为它是使用三个单独的tabular进行设置的。下面,我将它们组合在一起,但也使用[booktabs](// ctan.org/pkg/booktabs来减少基于行的方法。

enter image description here

\documentclass{article}

\usepackage{booktabs,makecell}

\begin{document}

\begin{table}
  \centering
  \setlength{\tabcolsep}{2pt}
  \caption{Model of Dataset I Tested on Dataset III}
  \begin{tabular}{ *{20}{l} }
    \toprule
    & \multicolumn{13}{c}{Model Based Approach} &
      \multicolumn{5}{c}{\makecell[b]{Instance Based \\ Approach}} &
      \multicolumn{1}{c}{Average} \\
    \cmidrule(lr){2-14}
      \cmidrule(lr){15-19}
      \cmidrule(lr){20-20}
    Hosts & A & B & D & G & H & I & J & L & M & N & P & Q & R &
      C & E & F & K & O &
      All \\
    DR    & 1 & 0.85 & 0.6 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 &
      1 & 0.79 & 1 & 1 & 1 &
      \textbf{0.95} \\
    FPR   & 0.04 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 &
      0 & 0 & 0.5 & 0 & 0 &
      \textbf{0.03} \\
    \bottomrule
  \end{tabular} 
\end{table}

\end{document}