3

I am trying to let this table to fit in one column in my research paper, I tried to use \setlength{\tabcolsep}{1pt} command but did not work.

\begin{table}[ht]  
\setlength{\tabcolsep}{1pt}
    \centering
      \vspace{-0.5cm}
        \begin{tabular}{|c||c|c|c|c|c|c|}
            \hline
            \multicolumn{7}{|c|}{Precision} \\
            \hline
            Classifier & Text-specific (1) & N-grams (2) & Post-specific (3) & 1 \& 2 & 1 \& 3 & All\\
            \hline
            \perceptron & 0.78 & 0.82 & 0.24 & 0.81 & 0.77 & 0.83\\
            \decisiontree & 0.65 & 0.79 & 0.56 & 0.75 & 0.65 & 0.73\\
            \svm & 0.74 & 0.72 & 0.50 & 0.80 & 0.73 & 0.85\\
            \isolationforest & 0.54 & 0.51 & 0.52 & 0.53 & 0.54 & 0.53\\
            \hline
        \end{tabular}
    \caption{Precision results of the classifiers for different feature subsets. 1 \& 2 is the combination of text-specific features
\& n-grams. 1 \& 3 is the combination of text- and post-specific
features.}
\label{table:classifier_feature_subsets_prec} 
\end{table}

part of preamble:

\def\year{2018}\relax
%File: formatting-instruction.tex
\documentclass[letterpaper]{article} %DO NOT CHANGE THIS
\usepackage{aaai18}  %Required
\usepackage{times}  %Required
\usepackage{helvet}  %Required
\usepackage{courier}  %Required
\usepackage{url}  %Required
\usepackage{graphicx}  %Required

\usepackage[usenames,dvipsnames,table,xcdraw]{xcolor}
\usepackage{todonotes}
\usepackage{hyperref}
\usepackage{csquotes}
\usepackage{xspace}
\usepackage{pgfplots}
\usepackage{chapterbib}
\newcommand{\decisiontree}{Decision Tree\xspace}
\newcommand{\decisiontrees}{Decision Tree\xspace}
\newcommand{\svm}{One-Class~SVM\xspace}
\newcommand{\svms}{One-Class~SVMs\xspace}
\newcommand{\perceptron}{Perceptron\xspace}
\newcommand{\perceptrons}{Perceptrons\xspace}
\newcommand{\isolationforest}{Isolation Forest\xspace}
\newcommand{\isolationforests}{Isolation Forests\xspace}


\frenchspacing  %Required
\setlength{\pdfpagewidth}{8.5in}  %Required
\setlength{\pdfpageheight}{11in}  %Required
%PDF Info Is Required:
  \pdfinfo{
5
  • 1
    Please tell us which document class you use. Is it IEEEtran? Which options do you pass to the document class? How are the macros \perceptron, \decisiontree, etc defined?
    – Mico
    Commented Aug 17, 2017 at 10:04
  • @Mico I already had a .csv file where I have the records that I want to plot and that works fine. I am using \usepackage{aaai18}. But fot this table I am passing the values directly into cells and not from a separate document.
    – Krebto
    Commented Aug 17, 2017 at 10:16
  • 1
    Which document class do you use? And, is the aaai18 package available online somewhere? It doesn't seem to be distributed with TeXLive.
    – Mico
    Commented Aug 17, 2017 at 10:23
  • @mico \documentclass[letterpaper]{article}
    – Krebto
    Commented Aug 17, 2017 at 11:10
  • 1
    you add image of code ... be so kind and replace it with code.
    – Zarko
    Commented Aug 17, 2017 at 11:16

2 Answers 2

4

an alternative ...

using threepartable and tabular*:

\documentclass[letterpaper, twocolumn]{article}
\usepackage[margin=1in]{geometry}

\usepackage{booktabs,threeparttable}

\usepackage{lipsum}

\begin{document}
\lipsum[11]
\begin{threeparttable}[htb]
    \caption{Precision results of the classifiers for different feature subsets.}
\label{table:classifier_feature_subsets_prec}
    \small
    \setlength\tabcolsep{0pt}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}} l cc cc cc @{}}
    \toprule
&   \multicolumn{6}{c}{Precision} \\
        \cmidrule{2-7}
Classifier          & (1)\tnote{a}  
                            & (2)\tnote{b}
                                    & (3)\tnote{c} 
                                            & (1\&2)\tnote{d}  
                                                    & (1\&3)\tnote{e}  
                                                            & All\\
        \midrule
Perceptron          & 0.78  & 0.82  & 0.24  & 0.81  & 0.77  & 0.83\\
Decision Tree       & 0.65  & 0.79  & 0.56  & 0.75  & 0.65  & 0.73\\
One-Class~SVM       & 0.74  & 0.72  & 0.50  & 0.80  & 0.73  & 0.85\\
Isolation Forest    & 0.54  & 0.51  & 0.52  & 0.53  & 0.54  & 0.53\\
        \bottomrule
\end{tabular*}
\begin{tablenotes}[para,flushleft,small]
\item[a] 1: Text-specific,
\item[b] 2: N-grams,
\item[c] 3: Post-specific,
\item[d] (1\&2): combination of Text-specific and  N-grams,
\item[e] (1\&3): combination of Text-specific and  Post-specific
\end{tablenotes}
\end{threeparttable}
\end{document}

enter image description here

1
  • +1 for the use of a tabular* environment. :-)
    – Mico
    Commented Aug 17, 2017 at 13:59
4

Here are two possible solutions.

  • The first takes your basic layout -- rather busy-looking, with lots of vertical lines -- and switches to a tabularx enviroment so that the material can fit. Note that it's still necessary to switch to \footnotesize and to use hardly any intercolumn whitespace.

  • The second solution strives to give the table a more open "look", by getting rid of all vertical lines and using well-spaced horizontal rules instead of \hline. A (beneficial) by-product of this approach is that it becomes possible to use \small instead of \footnotesize and to employ a bit more intercolumn whitespace. Note that I've also simplified the caption, by moving material that's really part of the table legend to just below the table itself.

enter image description here

\documentclass[letterpaper]{article}
\usepackage{aaai18} % from http://www.aaai.org/Conferences/AAAI/2018/aaai18call.php
\usepackage{times,helvet,courier,xcolor}
\usepackage{tabularx,ragged2e,booktabs,caption}
\newcolumntype{C}{>{\Centering\arraybackslash}X} % 
\frenchspacing
\begin{document}

\begin{table}[h]  
\footnotesize
\setlength{\tabcolsep}{1pt} % hardly any whitespace between columns!
\setlength\extrarowheight{1pt}
\textcolor{red}{Table with vertical lines}

\begin{tabularx}{\columnwidth}{|l||*{6}{C|}}
    \hline
    \multicolumn{7}{|c|}{Precision} \\
    \hline
    Classifier    & Text-specific (1) 
    & N-grams (2) & Post-specific (3) 
    & 1 \& 2      & 1 \& 3     & All\\
    \hline
    Perceptron       & 0.78 & 0.82 & 0.24 & 0.81 & 0.77 & 0.83\\
    Decision Tree    & 0.65 & 0.79 & 0.56 & 0.75 & 0.65 & 0.73\\
    One-Class SVM    & 0.74 & 0.72 & 0.50 & 0.80 & 0.73 & 0.85\\
    Isolation Forest & 0.54 & 0.51 & 0.52 & 0.53 & 0.54 & 0.53\\
    \hline
\end{tabularx}

\caption{Precision results of the classifiers for different feature subsets. 
1 \& 2 is the combination of text-specific features and n-grams. 
1 \& 3 is the combination of text- and post-specific features.}
\label{table:classifier_feature_subsets_prec} 
\end{table}


\begin{table}[h]
\small % "\footnotesize" not needed here
\captionsetup{size=small}
\textcolor{red}{No vertical lines; well-spaced horizontal lines; simplified caption}

\setlength{\tabcolsep}{2pt} % a bit more whitespace
\begin{tabularx}{\columnwidth}{@{} l *{5}{C} c @{}}
    \toprule
     Classifier & \multicolumn{6}{c@{}}{Precision} \\
    \cmidrule(l){2-7}
    & Text-specific (1) & N-grams (2) & Post-specific (3)
    & 1 \& 2 & 1 \& 3 & All\\
    \midrule
    Perceptron       & 0.78 & 0.82 & 0.24 & 0.81 & 0.77 & 0.83\\
    Decision Tree    & 0.65 & 0.79 & 0.56 & 0.75 & 0.65 & 0.73\\
    One-Class SVM    & 0.74 & 0.72 & 0.50 & 0.80 & 0.73 & 0.85\\
    Isolation Forest & 0.54 & 0.51 & 0.52 & 0.53 & 0.54 & 0.53\\
    \bottomrule
\end{tabularx}

\smallskip
1 \& 2 is the combination of text-specific features and n-grams.

1 \& 3 is the combination of text- and post-specific features.

\caption{Precision results of classifiers for various feature subsets.}
\label{table:new}
\end{table}

\end{document} 
4
  • Nice solution. I am getting an error message with the capital C here: "\begin{tabularx}{\columnwidth}{|l||*{6}{C|}}" . When I change it to a small c, it works. But... I would like to understand why because it's likely not a typo. Can you explain please?
    – pitosalas
    Commented Apr 24, 2018 at 15:48
  • @pitosalas - Did you notice the instruction \newcolumntype{C}{>{\Centering\arraybackslash}X} in the preamble?
    – Mico
    Commented Apr 24, 2018 at 15:58
  • No-I missed it. I am new to this, so what did that do?
    – pitosalas
    Commented Apr 24, 2018 at 15:59
  • @pitosalas - The instruction sets up a new column type, called C. The code snippet >{\Centering\arraybackslash}X means, essentially, "centered version of the X column type". (The X column type is provided by the tabularx package.) Later on, the instruction \begin{tabularx}{\columnwidth}{@{} l *{5}{C} c @{}} means: "set up a tabularx environment with width \columnwith, no padding at either the left or right hand edges, one column of type l, five columns of type C, and one column of type c.
    – Mico
    Commented Apr 24, 2018 at 16:04

You must log in to answer this question.

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