3

Here is my table. I would like to fit its width so it will fit my rest of paper alignment. Maybe there is a need to transfer the headline into 2 rows or any other way to fit the rest of text width.

\documentclass{article}
\usepackage{float}
\usepackage{showframe}

 \begin{document}
 \begin{abstract}
 zzz
 \end{abstract}

 \section{Introduction}
 This is my table that its width is too big:
    \begin{table}[H]
        \centering
        \begin{tabular}{||c c c c c ||} 
            \hline
            ID & UCI Dataset Name & No. of samples & No. of attributes & No. of classes \\ [0.5ex] 
            \hline\hline
            DS1 & Cardiotocography & 2126 & 23  & 3 \\ 
            \hline
            DS2 & Wall-Following Robot Navigation Data & 5456 & 24  & 4 \\ 
            \hline
            DS3 & Spambase & 4601 & 57  & 2 \\
            \hline
            DS4 & MAGIC Gamma Telescope & 19020 & 11 & 2 \\
            \hline
            DS5 & Letter Recognition & 20000 & 16 & 26 \\
            \hline
            DS6 & MiniBooNE particle identification & 130065 & 50 & 2 \\ [1ex] 
            \hline
        \end{tabular}
    \caption{Datasets used for empirical evaluation}
    \label{table:1}
 \end{table}
 \end{document}

enter image description here

4
  • Please make your code snipped as complete document starting with \documentclass{...} and ending with \end{document} with all necessary packages in preamble, which are needed for work of your code snipped.
    – Zarko
    Commented Jan 21, 2016 at 17:13
  • What margins do you use?
    – Alenanno
    Commented Jan 21, 2016 at 17:29
  • @Alenanno, I add showframes to show OP, what margins has is default with \documentclass{article}. I'm sure, that real margins are smaller, however, he doesn't provide any information about this.
    – Zarko
    Commented Jan 21, 2016 at 19:13
  • @Zarko I think he used the default margins (which are really huge).
    – Alenanno
    Commented Jan 21, 2016 at 19:32

2 Answers 2

5

One more solution. In it I stol Alenanno's column heads look and introduce few new package:

  • booktabs (as Alenanno) for table rules
  • makecell for setting column's heads
  • tabularx for determine table width to \textwidth
  • siunitx for use S column type which gives nice number formating

To limit rows to only one line text, I suggest to reduce font size to \small. With this measures the table becomes:

enter image description here

The complete code (containing only table) is:

\documentclass{article}
    \usepackage{booktabs,makecell,tabularx}
    \renewcommand\theadfont{\small}
    \newcolumntype{L}{>{\raggedright\arraybackslash}X}
    \usepackage{siunitx}

\begin{document}
    \begin{table}[h]
    \centering
    \setlength{\tabcolsep}{5pt}
    \small
\begin{tabularx}{\textwidth}{c L S[table-format=6.0]*{2}{S[table-format=2.0]}}
    \toprule
\thead{ID}  &   \thead{UCI Dataset Name} 
                &   {\thead{Samples\\(numbers)}}
                    &   {\thead{Attributes\\(numbers)}} 
                        &   {\thead{Classes\\number}}           \\
    \midrule
DS1 & Cardiotocography                      & 2126  & 23    & 3     \\
DS2 & Wall-Following Robot Navigation Data  & 5456  & 24    & 4     \\
DS3 & Spambase                              & 4601  & 57    & 2     \\
DS4 & MAGIC Gamma Telescope                 & 19020 & 11    & 2     \\
DS5 & Letter Recognition                    & 20000 & 16    & 26    \\
DS6 & MiniBooNE particle identification     & 130065& 50    & 2     \\
    \bottomrule
\end{tabularx}
    \caption{Datasets used for empirical evaluation}
    \label{table:1}
    \end{table}
 \end{document}

Edit: ups, I didn't upload last code and image version .... now this is corrected.

3

You can cut some extra length putting (number) on a new line, then using adjustbox.

Output

enter image description here

Code

\documentclass{article}
\usepackage{adjustbox}
\usepackage{array,booktabs}

\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

\begin{document}
\begin{table}[!htb]
    \centering
\begin{adjustbox}{max width=\textwidth}
\begin{tabular}{ccC{1.5cm}C{1.8cm}C{1.5cm}}
 \toprule
ID & UCI Dataset Name & Samples {\footnotesize (number)} & Attributes {\footnotesize (number)} & Classes {\footnotesize (number)} \\
\midrule
DS1 & Cardiotocography & 2126 & 23  & 3 \\ 
DS2 & Wall-Following Robot Navigation Data & 5456 & 24  & 4 \\ 
DS3 & Spambase & 4601 & 57  & 2 \\
DS4 & MAGIC Gamma Telescope & 19020 & 11 & 2 \\
DS5 & Letter Recognition & 20000 & 16 & 26 \\
DS6 & MiniBooNE particle identification & 130065 & 50 & 2 \\
\bottomrule
\end{tabular}
\end{adjustbox}    
\caption{Datasets used for empirical evaluation}
\label{table:1}
\end{table}
\end{document}

You must log in to answer this question.

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