0

I'm trying to add a table to my IEEE paper but its width is too much. Please help me fix the width to make it fit.

\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts
\usepackage{cite}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{algorithmic}
\usepackage{graphicx}
\usepackage{float}
\usepackage{tabularx}

\usepackage{textcomp} \usepackage{xcolor} \def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}} \begin{document} . . . .

\begin{table}[h!] \centering \begin{tabularx}{0.3\textwidth}{|c c c c c c|} \hline Feature 1 & Feature 2 & Accuracy & Precision & Recall & Specificity \ [0.5ex] \hline\hline original dna size & compressed dna size & 0.999 & 0.999 & 0.999 & 0.999 \ \hline original dna size & compression ratio & 0.999 & 0.999 & 0.999 & 0.999 \ [1ex] \hline \end{tabularx} \caption{caption} \label{tab:my_label} \end{table} . . . . \end{document}

Heyb
  • 1
  • 2
  • 2
    If you're using tabularx you need to use at least one column that uses X to reach the total width goal, without an X-type column tabularx is just a tabular with extra input. – Skillmon Dec 11 '21 at 08:23
  • Not particularly. I'm not able to understand which solution to use and it looks like it doesn't help my case. Could you please suggest a solution for my scenario? – Heyb Dec 11 '21 at 08:23
  • @Skillmon, how do I use X and what is the meaning of it? – Heyb Dec 11 '21 at 08:25
  • I'd guess that the columns Accuracy, Precision, etc. will store numbers, so you might want to use a column type that neatly aligns numbers, like the S-type provided by siunitx. – Skillmon Dec 11 '21 at 08:25
  • Instead of a c-column use an X column, but that won't solve things for you here, it'll just look terrible. – Skillmon Dec 11 '21 at 08:26
  • @Skillmon, Please tell me what changes I need to make in the LaTex code to use S and X-types. – Heyb Dec 11 '21 at 08:26
  • @Skillmon, Yep it made things worse. – Heyb Dec 11 '21 at 08:27
  • Why do you need to have a table that is only 0.3\textwidth wide? Also, could you please post a compilable example (your code misses \documentclass, \begin{document}, \end{document}, and the required packages to compile (in this case only tabularx). – Skillmon Dec 11 '21 at 08:28
  • @skillmon, I have edited the code. Please see it now. – Heyb Dec 11 '21 at 08:32
  • @SujithK also, some better dummy data than xxx would be good as well, are the four following columns all numeric? The closer your MWE is to your actual document (while keeping it minimal, so no need to add text, just make your table closer to the real thing, no need to use your real data, just something close to it) the better we can suggest stuff. – Skillmon Dec 11 '21 at 08:34
  • Also, in your definition of \BibTeX: Don't use \rm and \sc, those macros are deprecated/unsupported by LaTeX since more than a decade! Instead use \rmfamily and \scshape. – Skillmon Dec 11 '21 at 08:36
  • @Skillmon, data for the table is updated. Ok I will use \rmfamily instead thanks! – Heyb Dec 11 '21 at 08:37

2 Answers2

2

Edit: I delete my first version of answer since was based on @Skillmon comments which he later converted in excellent answer (+1). So I decide first to delete mine.

But now renew it with an example, how can be used a relative new package tabularray for your table design:

\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts
\usepackage{textcomp}

\usepackage{xcolor} \usepackage{tabularray} % <--- new, used version 2021Q \UseTblrLibrary{booktabs, siunitx} % <--- new

\usepackage{lipsum}

\begin{document} \lipsum[1]

\begin{table}[h!] \centering \caption{caption} \label{tab:my_label} \begin{tblr}{colsep=4pt, colspec={@{} X[l] X[l] *{4}{S[table-format=1.3]} @{}}, } \toprule Feature 1 & Feature 2 & {{{Accuracy}}} & {{{Precision}}} &{{{ Recall}}} & {{{Specificity}}} \ \midrule original dna size & compressed dna size & 0.999 & 0.999 & 0.999 & 0.999 \ original dna size & compression ratio & 0.999 & 0.999 & 0.999 & 0.999 \ \bottomrule \end{tblr} \end{table} \lipsum[2-7] \end{document}

enter image description here

Zarko
  • 296,517
2

The following makes the following changes to your table:

  • Use \linewidth instead of 0.3\textwidth as the width the table might take

  • Actually make use of the X-type columns by defining a new column type (called L) that'll be a left-aligned X-type column (this way TeX won't try to set the contents of these columns flush, which would only throw overfull box warnings as that's nearly impossible with narrow columns)

  • Use the S-type column provided by siunitx for the numeric data (the table-format=1.3 means numbers have 1 digit before the decimal separator and 3 digits afterwards).

  • Drop the standard rules provided by the LaTeX kernel, instead use the rules \toprule, \midrule, \bottomrule provided by booktabs

  • To ease reading of the table put \addlinespace (also provided by booktabs) between rows which need more than a single line of text.

  • Reduce the space between columns to 3/4ths using \setlength\tabcolsep{.75\tabcolsep}.

  • Put the \caption above the tabular (that's what IEEEtran wants, compare the spacing of the caption to yours) and put the \label inside the mandatory argument of \caption (that is more robust in general).

  • Don't use h! only as the placement, instead I used htp! (LaTeX will turn h! to ht! anyway, and allowing no p leads to problems most of the times if your table gets too big). If you want "absolutely here and no where else" you should use H provided by the float package instead.

Everything combined:

\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts

\usepackage{tabularx} \usepackage{siunitx} \usepackage{booktabs}

\newcolumntype{L}{>{\raggedright\arraybackslash}X}

\usepackage{duckuments}% dummy content for the text, don't use it in your document

\begin{document} \blindduck

\begin{table}[htp!]% never use just h! \centering \caption{caption\label{tab:my_label}} \setlength\tabcolsep{.75\tabcolsep}% \begin{tabularx}{\linewidth}{L L *{4}{S[table-format=1.3]}} \toprule Feature 1 & Feature 2 & {Accuracy} & {Precision} & {Recall} & {Specificity} \ \midrule original dna size & compressed dna size & 0.999 & 0.999 & 0.999 & 0.999 \ \addlinespace original dna size & compression ratio & 0.999 & 0.999 & 0.999 & 0.999 \ \bottomrule \end{tabularx} \end{table}

\blindduck \end{document}

enter image description here

Skillmon
  • 60,462