0

How can one create a full width table in two column document without the error below plz ? this is my code

\documentclass{article}
\usepackage{spconf,amsmath,graphicx}
\usepackage{graphicx,subcaption}
\usepackage{lipsum}
\usepackage{subfig}
\usepackage{sidecap}
\usepackage{amsmath,graphicx,cite}
\usepackage{amssymb}
\usepackage{booktabs}      

\newcommand{\centerbox}[1]{\raisebox{1ex}{\raisebox{-0.5\height}{#1}}}

\def\x{{\mathbf x}}

\def\L{{\cal L}}

\begin{document}

\section{1}

\begin {table*} 
\begin{tabular*}{\textwidth}{@{\extracolsep{\stretch{1}}}*{7}{r}@{}}
\toprule

M & TA & MO & P & N & ID & CC & XC & KL \\ 
\hline
method & 0.79 & 0.59 & - & - &  4& 3 & 5\\ 
ED  [] & 5 & 7 & - & -& 6 \\
CR  &  4 & 7&- & - & 22 \\
NB[]& 2 & 75 & - & - & 6\\ 

\hline 
\end{tabular*}
\caption{Set of observations }
\end{table*}
\end{document}

enter image description here

2
  • You are aware that your document does not compile at all? You set 7 columns but use 9 in fact ....
    – user31729
    Aug 11, 2016 at 19:13
  • 1
    Well, I was all set to answer this, but I'm afraid I can't. First, you subject line doesn't seem to relate to your question at all; you don't have a two-column document here, either with the class option or with multicol. Further, you don't tell us which error is confusing you (I got several when I tried to run your code). Please prepare a minimal working example, and clearly explain your problem with a subject line that matches; it'll make it a lot easier for people to help you. Aug 11, 2016 at 19:15

1 Answer 1

2

From code I succeed to extract the following MWE:

\documentclass{article}
\usepackage{booktabs}

\begin{document}

\section{section}

\begin {table}[htb]
\begin{tabular*}{\textwidth}{@{\hskip 6pt\extracolsep{\stretch{1}}}*{9}{r}}
    \toprule
M       & TA    & MO    & P & N & ID & CC & XC & KL \\
    \midrule
method  & 0.79  & 0.59  & - & - & 4  & 3  & 5  &    \\
ED  []  & 5     & 7     & - & - & 6  &    &    &    \\
CR      & 4     & 7     & - & - & 22 &    &    &    \\
NB[]    & 2     & 75    & - & - & 6  &    &    &    \\
    \bottomrule
\end{tabular*}
\caption{Set of observations }
\end{table}
\end{document}

which gives:

enter image description here

I'm curious now: what is your problem?

For above image I remove all irrelevant packages and correct numbers of columns in your table and also complete ampersands in all rows where they missing (actually in all rows except the first). Was this problem?

Addendum: After exchange of opinions with Christian Hupfer, how the above table can be also set, I make (for my exercise) two more solutions. Both are added to first one that you can more easy compare their code and results. For them I add two packages: tabularx and siunitx:

\documentclass{article}
\usepackage{booktabs,tabularx}
\usepackage{siunitx}

\newcommand\mcx{\multicolumn{1}{>{\centering\arraybackslash}X}}

\begin{document}

\section{section}

\begin {table}[htb]
\begin{tabular*}{\textwidth}{@{\hskip 6pt\extracolsep{\stretch{1}}}*{9}{r}}
    \toprule
M       & TA    & MO    & P & N & ID & CC & XC & KL \\
    \midrule
method  & 0.79  & 0.59  & - & - & 4  & 3  & 5  &    \\
ED  []  & 5     & 7     & - & - & 6  &    &    &    \\
CR      & 4     & 7     & - & - & 22 &    &    &    \\
NB[]    & 2     & 75    & - & - & 6  &    &    &    \\
    \bottomrule
\end{tabular*}
\caption{Set of observations }
\end{table}

Similarly result can be obtained with \verb+tabularx+ packages

\begin {table}[htb]
\begin{tabularx}{\textwidth}{*{9}{>{\raggedleft\arraybackslash}X}}
    \toprule
M       & TA       & MO       & P       & N       & ID       & CC       & XC       & KL       \\
    \midrule
method  & 0.79     & 0.59     & {--}    & {--}    & 4        & 3        & 5        &          \\
ED  []  & 5        & 7        & {--}    & {--}    & 6        &          &          &          \\
CR      & 4        & 7        & {--}    & {--}    & 22       &          &          &          \\
NB[]    & 2        & 75       & {--}    & {--}    & 6        &          &          &          \\
    \bottomrule
\end{tabularx}
\caption{Set of observations}
\end{table}

One more solution with quite sophisticated table setting with exploiting packages \verb+tabularx+ and \verb+siunitx+:

\begin {table}[htb]
\begin{tabularx}{\textwidth}{r*{8}{S[table-format=2.2]}}
    \toprule
\mcx{M} & \mcx{TA} & \mcx{MO} & \mcx{P} & \mcx{N} & \mcx{ID} & \mcx{CC} & \mcx{XC} & \mcx{KL} \\
    \midrule
method  & 0.79     & 0.59     & {--}    & {--}    & 4        & 3        & 5        &          \\
ED  []  & 5        & 7        & {--}    & {--}    & 6        &          &          &          \\
CR      & 4        & 7        & {--}    & {--}    & 22       &          &          &          \\
NB[]    & 2        & 75       & {--}    & {--}    & 6        &          &          &          \\
    \bottomrule
\end{tabularx}
\caption{Set of observations}
\end{table}

\end{document}

enter image description here

4
  • What about tabularx instead of tabular*? I think the O.P. wants the table leaking into the margin even...
    – user31729
    Aug 11, 2016 at 19:38
  • @ChristianHupfer, I'm still in phase of guessing, what is OP problem. Of course the tabularx is good selection. Also to see, how to use S columns type for last eight columns ... I can add these options if OP will response to comments and my answer :-)
    – Zarko
    Aug 11, 2016 at 19:42
  • Expecting user feedback is sometimes .... well, fill in yourself ... ;-) I tried tabularx first, but I resented from answering. It's too unclear (for me) and I did not want to get a coward downvote again like some days ago. The S type is a good choice then, I think
    – user31729
    Aug 11, 2016 at 19:44
  • @saraamanda, if my answer really help you, you can vote or/and even accept it (click on check-mark on the top left side of answer) :-)
    – Zarko
    Aug 12, 2016 at 0:27

You must log in to answer this question.

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