4

How can i let latex automatically choose the column width such that each entry does not go into \newline ? How can i manually set the width of each column while making sure that it all sums up to \columnwidth ?

\begin{table}[t]
    \begin{tabu} to \columnwidth { | X[l] || X[c] | X[c] | }
        \hline
        \textbf{Component} & \textbf{Time in ms} & \textbf{Time in \%} \\
        \hline
        Data processing & 42 & 33\\
        \hline
        RANSAC & 2 & 1 \\
        \hline  
        Region Proposals  & 82 & 64 \\
        \hline  
    \end{tabu}
    \caption{Breakdown in the running time our system with a single core machine. Time in ms is averaged across the validation set.}
    \label{tab:componentruntime}
\end{table}

enter image description here

5

Use good ol’ tabular* environment:

\documentclass[twocolumn]{article}

\usepackage{lipsum}

\begin{document}

\lipsum[2]

\begin{table}[htp]

\begin{tabular*}{\columnwidth}{  @{\extracolsep{\fill}} |l||c|c| @{} }
\hline
\textbf{Component} & \textbf{Time in ms} & \textbf{Time in \%} \\
\hline
Data processing & 42 & 33\\
\hline
RANSAC & 2 & 1 \\
\hline
Region Proposals  & 82 & 64 \\
\hline
\end{tabular*}

\caption{Breakdown in the running time our system with a single core 
  machine. Time in ms is averaged across the validation set.}
\label{tab:componentruntime}

\end{table}

\lipsum

\end{document}

enter image description here

The mandatory version with booktabs and no vertical rule. The left alignment in the first column makes the double vertical rule unnecessary (it never is, actually). Since entries are not split across lines, the horizontal rules can be reduced to a bare minimum.

\documentclass[twocolumn]{article}
\usepackage{booktabs}

\usepackage{lipsum}

\begin{document}

\lipsum[2]

\begin{table}[htp]

\begin{tabular*}{\columnwidth}{  @{\extracolsep{\fill}} lcc @{} }
\toprule
\textbf{Component} & \textbf{Time in ms} & \textbf{Time in \%} \\
\midrule
Data processing & 42 & 33\\
RANSAC & 2 & 1 \\
Region Proposals  & 82 & 64 \\
\bottomrule
\end{tabular*}

\caption{Breakdown in the running time our system with a single core 
  machine. Time in ms is averaged across the validation set.}
\label{tab:componentruntime}

\end{table}

\lipsum

\end{document}

enter image description here

By also loading siunitx you can easily get alignment for the figures.

\documentclass[twocolumn]{article}
\usepackage{booktabs}
\usepackage{siunitx}

\usepackage{lipsum}

\begin{document}

\lipsum[2]

\begin{table}[htp]

\begin{tabular*}{\columnwidth}{
  @{\extracolsep{\fill}}
  l
  S[table-format=2.0]
  S[table-format=2.0]
  @{}
 }
\toprule
\textbf{Component} & \textbf{Time in ms} & \textbf{Time in \%} \\
\midrule
Data processing & 42 & 33\\
RANSAC & 2 & 1 \\
Region Proposals  & 82 & 64 \\
\bottomrule
\end{tabular*}

\caption{Breakdown in the running time our system with a single core 
  machine. Time in ms is averaged across the validation set.}
\label{tab:componentruntime}

\end{table}

\lipsum

\end{document}

enter image description here

  • thanks ! do you know why my 2nd and 3rd entries aren't centered ? I have attached an image in my post. Its quite weird because changing the argument from c to l or r changes only the 2nd row onwards. Ive tried copy pasting your code but it hasn't changed anything. – RuiQi Jan 24 '17 at 13:57
  • @RuiQi I stopped worrying about tabu: just avoid it. – egreg Jan 24 '17 at 14:01
  • I meant that my 2nd and 3rd entries arent centered when I used your code (tabular) – RuiQi Jan 24 '17 at 15:26
  • @RuiQi I don't know what to say: I just compiled the example. Are you sure you have no stray character? What document class are you using? – egreg Jan 24 '17 at 15:39
  • great, I was looking for this forever – ricab May 2 '18 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.