2

I have this table, in which I want to report some results and I am using acmart class. One extra column keeps getting introduced. Here is my code:

   \documentclass[sigconf]{acmart}
   \usepackage[utf8]{inputenc}
   \usepackage{placeins}
   \usepackage{booktabs,subcaption,amsfonts,dcolumn}
   \title{table example}
   \date{June 2020}
   
   \begin{document}
   
   \maketitle
   
   \section{Introduction}
   \begin{table*}[t]
          \large
          \begin{tabular*}{\textwidth}{|l|l|l|}
          \toprule
          Model &  Accuracy1 & Accuracy2 \\ \midrule
          Model1&0.421& 18.47 \\ 
          Model2 &0.46& 23.62\\
           
          Model3&0.49 &25.7 \\
          \bottomrule
          \end{tabular*}
          \caption{Caption}
          \label{tab: tab1}
          \end{table*}
   
   
   \end{document}

I get stretched horizontal lines. Why is that? How can I centrally align this table with proper horizontal rules? enter image description here

3
  • 2
    You can try to use tabular environment (without a star at the end) and delete the {\textwidth} part. There are examples here: tex.stackexchange.com/questions/341205/….
    – Ekin
    Commented Jun 28, 2020 at 23:23
  • Do you really want the table to be centered with respect to both columns of the text? From your screenshot I suspect the table actually is narrow enough to fit into a single column. If you want to center the table within one column you can use \begin{table} \centering.
    – leandriis
    Commented Jun 29, 2020 at 5:20
  • Please also be warned that the horizontal lines from the booktabs package are designed to be used without vertical lines. This is why you see small gaps in the vertical lines around the intersections.
    – leandriis
    Commented Jun 29, 2020 at 5:22

1 Answer 1

3

The tabular* is clumped together on the left because it had a required total width of \textwidth, but the columns have no ability to stretch out to fill the width. The basic answer is to put \extracolsep{\fill} in the tabular declaration, but that makes its own different ugly result.

The vertical lines give trouble in two ways: (1) The booktabs definitions don't work with them, leaving gaps at the horizontal rules; (2) the \extracolsep problem is that the spaces stretch only on one side of each vertical line.

Before launching into messy solutions, let me exhort others to post answers using tabularx perhaps using decimal alignment; or using even better tabular layout packages that do it elegantly!

First try: natural width without vertical lines -- Would this be reasonable? Some \quad spacing is inserted to make the wider column headings be centered over the columns

   \centering
   \begin{tabular}{lll}\toprule
      Model & Accuracy1& Accuracy2 \\ \midrule
      Model1&\quad 0.421&\quad  18.47 \\ 
      Model2 &\quad 0.46&\quad  23.62\\
      Model3 &\quad 0.49 &\quad 25.7 \\ \bottomrule
   \end{tabular}

Second try: stretched width without vertical lines -- This repeats the manual spacing with \quad to center the heads over their columns, but alternatives are possible, as done further down.

   \begin{tabular*}{\textwidth}{@{\qquad\extracolsep{\fill}}lll@{\qquad}}\toprule
      Model & Accuracy1& Accuracy2 \\ \midrule
      Model1&\quad 0.421&\quad  18.47 \\ 
      Model2 &\quad 0.46&\quad  23.62\\
      Model3&\quad 0.49 &\quad 25.7 \\ \bottomrule
   \end{tabular*}

Third try, ruled tabular at natural width -- One must forego the extra spacing around the horizontal lines done by booktabs, but the result of that is too ugly to tolerate (\extrarowheight does not solve the problem). Let's define some "struts" to enforce extra spacing around \hline

\newcommand\highstrut{\leavevmode\raise\jot\copy\strutbox}
\newcommand\deepstrut{\leavevmode\lower\jot\copy\strutbox}

Then use them in a ruled tabular above and below any \hline

  \centering
  \begin{tabular}{|l|l|l|}
     \hline \highstrut
     Model & Accuracy1 & Accuracy2\deepstrut \\ \hline
     \highstrut
     Model1 &\quad 0.421&\quad  18.47 \\ 
     Model2 &\quad 0.46&\quad  23.62\\
     Model3 &\quad 0.49 &\quad 25.7 \deepstrut\\ \hline
  \end{tabular}

Fourth try: stretched with vertical lines -- where the spacing hits the fan. Since the only flexible spacing is between columns, and the rules are put in the column, one can't have equal spacing around the vertical lines unless they are placed in separate columns, and for that you need to abandon LaTeX's | and use special "rule" columns like r@{\vline}. Note the double & signs! Think of them as representing the |. Also, as long as there are large spaces between the columns, the headings can be centered over the (narrower) columns by letting them overhang the columns (\hidewidth plus ~).

      \begin{tabular*}{\textwidth}{@{}
         r@{\vline\extracolsep{\fill}} l
         r@{\vline}l r@{\vline}l r@{\vline\extracolsep{0pt}}}
      \hline 
      \highstrut & Model && \hidewidth~  Accuracy1\hidewidth~  &&
        \hidewidth~ Accuracy2\hidewidth~ &\deepstrut \\ \hline
      \highstrut & Model1 && 0.421 && 18.47 &\\ 
      & Model2 && 0.46 && 23.62&\\
      & Model3 && 0.49 && 25.7 &\deepstrut\\
      \hline
      \end{tabular*}

Typeset four tabulars

You must log in to answer this question.

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