43

I have a problem for drawing a multicolumn table in ieeetran latex.

This is what I want to draw: enter image description here

However, I couldn't manage it. I am having problem to add OBR and AR rows. I tried some codes, none of them worked. My last trial is:

\begin{table}[!h]
\centering

    \caption{caption}     
    \label{tab:table}

    \begin{small}
    \begin{tabular}{|l|l|l|l|}
    \hline
    & \multicolumn{6} {c|} {\bfseries Dataset} & {\bfseries  A} &{\bfseries B}  & {\bfseries C}\\
    \cline{2-7}
    {\bfseries } & {\bfseries OBR} &{\bfseries AR}  & {\bfseries OBR} &{\bfseries AR} & {\bfseries OBR} &{\bfseries AR}\\
    \hline
    D1        & 2.1\%   &   2.1\%   2.1\%  & 2.1\%  &   2.1\%   2.1\%   \\
    \hline
    D2         & 11.6\% &11.6\% & 11.6\%  & 2.1\%   &   2.1\%   2.1\%\\
    \hline
    D3          & 5.5\%     &   5.5\%   & 5.5\%   & 2.1\%   &   2.1\%   2.1\%  \\
    \hline
    \end{tabular}
    \end{small} 
\end{table}

May I request anyone to help me for drawing this table? I will be very grateful.

0

2 Answers 2

69

A few initial comments:

  • I’m assuming you’re using the multirow package to try to print the multiple columns (you didn’t say, but it seems like the natural choice).

  • I’d suggest using the siunitx package to align the decimal points in your table.

  • The booktabs package has some good advice for nice-looking tables in LaTeX in the documentation. I’ve used it below, but you can remove the dependency by replacing \toprule, \midrule and \bottomrule with \hline.

As for why the current example isn’t compiling:

  • The tabular doesn’t have enough columns. You’ve passed the option {|l|l|l|l|}, which is four left-aligned columns with vertical bars between each of them. At its widest, the original table has seven columns, and you need to account for all of them. So this should be changed to something like {|l|l|l|l|l|l|l|}.

    If you use siunitx, then use {lSSSSSS}: the S is an option from siunitx which lines up the decimal points in your data. Feel free to change this back if you don’t want to/can’t use this package.

  • The multicolumn{6} {c|} takes the Dataset heading and fills six columns with it, then you have three more columns for A, B and C. This means that this row has nine columns overall, which is more than you need.

    Instead, you want something more like:

    \multirow{2}{*}{Dataset} &
      \multicolumn{2}{c}{A} &
      \multicolumn{2}{c}{B} &
      \multicolumn{2}{c|}{C} \\
    

    You need to make the final column c| so that you get the final vertical line at the end.

  • In the second row, you skip the first cell (which gets filled by **Dataset* from the previous row), and then fill the rest as normal:

    & O.B.R & A.R & O.B.R & A.R & O.B.R & A.R \\
    

    If you do use siunitx, then you need to wrap these in curly braces, so that the period doesn’t get read as a decimal point. If you don’t, then you get an error because it can’t line these numbers up.

    & {O.B.R} & {A.R} & {O.B.R} & {A.R} & {O.B.R} & {A.R} \\
    

If we modify your code with these suggestions in mind, we get something like this:

\documentclass{article}

\usepackage{multirow}

\begin{document}

\begin{table}
  \begin{tabular}{|l|l|l|l|l|l|l|}
    \hline
    \multirow{2}{*}{Dataset} &
      \multicolumn{2}{c}{A} &
      \multicolumn{2}{c}{B} &
      \multicolumn{2}{c|}{C} \\
    & O.B.R & A.R & O.B.R & A.R & O.B.R & A.R \\
    \hline
    D1 & 2.1\% & 2.1\% & 2.1\% & 2.1\% & 2.1\% & 2.1\% \\
    \hline
    D2 & 11.6\% & 11.6\% & 11.6\% & 11.6\% & 11.6\% & 11.6\% \\
    \hline
    D3 & 5.5\% & 5.5\% & 5.5\% & 5.5\% & 5.5\% & 5.5\% \\
    \hline
  \end{tabular}
\end{table}

\end{document}

and this is the result:

enter image description here

Here’s an example that includes siunitx and booktabs (I also put the % sign in the header to ease readability):

\documentclass{article}

\usepackage{booktabs}
\usepackage{multirow}
\usepackage{siunitx}

\begin{document}

\begin{table}
  \begin{tabular}{lSSSSSS}
    \toprule
    \multirow{2}{*}{Dataset} &
      \multicolumn{2}{c}{A (\%)} &
      \multicolumn{2}{c}{B (\%)} &
      \multicolumn{2}{c}{C (\%)} \\
      & {O.B.R} & {A.R} & {O.B.R} & {A.R} & {O.B.R} & {A.R} \\
      \midrule
    D1 & 2.1 & 2.1 & 2.1 & 2.1 & 2.1 & 2.1 \\
    D2 & 11.6 & 11.6 & 11.6 & 11.6 & 11.6 & 11.6 \\
    D3 & 5.5 & 5.5 & 5.5 & 5.5 & 5.5 & 5.5 \\
    \bottomrule
  \end{tabular}
\end{table}

\end{document}

which compiles to

enter image description here

1
  • 1
    You have provided a splendid reply, thank you very much! I have a question: is is possible to add a horizontal line below "A", "B" and "C" headings without messing with the "Dataset" heading? Jul 3 at 1:38
0
 \begin{tabular}{|l|l|l|l|l|l|l|}
    \hline 
   \multicolumn{1}{|c|}{Std} &
      \multicolumn{2}{c|}{1.5} &
      \multicolumn{2}{c|}{2} &
      \multicolumn{2}{c|}{3} \\ 
      \hline
    d& Mean & Std & Mean & Std & Mean & Std \\
    \hline
    D1 & 2.1\% & 2.1\% & 2.1\% & 2.1\% & 2.1\% & 2.1\% \\
    \hline
    D2 & 11.6\% & 11.6\% & 11.6\% & 11.6\% & 11.6\% & 11.6\% \\
    \hline
    D3 & 5.5\% & 5.5\% & 5.5\% & 5.5\% & 5.5\% & 5.5\% \\
    \hline
  \end{tabular}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .