2

I am trying to make simple table with some numerical data. I used package booktabs and overall the table looks very good, but in my opinion it would be better to have columns equally width according to the widest column. Is it possible to make latex automatically stretch these columns equally ?

Thanks for any help.

Table example: Example table Code:

 \usepackage{tikz}
 \usepackage{booktabs}

 \begin{document}

 \begin{table}[ht]
 \centering
 \begin{tabular}[t]{ccccc}
 \toprule
 \# & \textsc{Precision} & \textsc{Recall} & \textsc{F1} &\textsc{MAP} \\
 \midrule
 0 & 0.0117 & 0.6838 & 0.0230 & 0.0112 \\
 1 & 0.0099 & 0.7084 & 0.0195 & 0.0109 \\
 2 & 0.0095 & 0.7096 & 0.0187 & 0.0105 \\
 3 & 0.0088 & 0.7215 & 0.0174 & 0.0101 \\
 4 & 0.0085 & 0.7401 & 0.0168 & 0.0096 \\
 5 & 0.0080 & 0.7467 & 0.0158 & 0.0087 \\
 6 & 0.0079 & 0.7571 & 0.0156 & 0.0088 \\
 7 & 0.0073 & 0.7794 & 0.0145 & 0.0087 \\
 8 & 0.0071 & 0.7902 & 0.0141 & 0.0085 \\
 9 & 0.0069 & 0.7981 & 0.0137 & 0.0084 \\
 10 & 0.0065 & 0.7990 & 0.0129 & 0.0078 \\
 \bottomrule
 \end{tabular}
 \end{table}
 \end{document}
| improve this question | | | | |
  • Welcome... \begin{tabular}[t]{@{\extracolsep\fill}ccccc@{\extracolsep\fill}} may helps you ... – MadyYuvi Apr 26 '19 at 12:36
  • Thank you very much for fast answer, I'll try it. – awarus Apr 26 '19 at 12:41
5

With the help of the array and the calc package you can achieve the following:

enter image description here

\documentclass{article}
\usepackage{array}
\usepackage{calc}
\usepackage{booktabs}

 \begin{document}
 \begin{table}[ht]
 \centering
 \begin{tabular}[t]{c*{4}{w{c}{\widthof{\textsc{Precision}}}}}
 \toprule
 \# & \textsc{Precision} & \textsc{Recall} & \textsc{F1} &\textsc{MAP} \\
 \midrule
 0 & 0.0117 & 0.6838 & 0.0230 & 0.0112 \\
 1 & 0.0099 & 0.7084 & 0.0195 & 0.0109 \\
 2 & 0.0095 & 0.7096 & 0.0187 & 0.0105 \\
 3 & 0.0088 & 0.7215 & 0.0174 & 0.0101 \\
 4 & 0.0085 & 0.7401 & 0.0168 & 0.0096 \\
 5 & 0.0080 & 0.7467 & 0.0158 & 0.0087 \\
 6 & 0.0079 & 0.7571 & 0.0156 & 0.0088 \\
 7 & 0.0073 & 0.7794 & 0.0145 & 0.0087 \\
 8 & 0.0071 & 0.7902 & 0.0141 & 0.0085 \\
 9 & 0.0069 & 0.7981 & 0.0137 & 0.0084 \\
 10 & 0.0065 & 0.7990 & 0.0129 & 0.0078 \\
 \bottomrule
 \end{tabular}
 \end{table}
 \end{document}
| improve this answer | | | | |
  • Thank you very much for great solution. – awarus Apr 26 '19 at 13:00
1

In addition to @leandriis suggestions, I suggest the following layout changes:

  1. Remove side bearing i.e. @{} in table preamble
  2. Reduce \tabcolsep
  3. All letters in heading in smallcaps
  4. Right align the columns
  5. Group the rows by a small space between each fourth row.

\documentclass{article}
\usepackage{array}
\usepackage{calc}
\usepackage{booktabs}
 \setlength{\tabcolsep}{1.5pt}
 \newcommand{\cc}[1]{\multicolumn{1}{r}{\textsc{\MakeLowercase{#1}}}}

 \begin{document}
 \begin{table}[ht]
 \centering
 \begin{tabular}[t]{@{}c*{4}{w{r}{\widthof{\textsc{Precision}}}}@{}}
 \toprule
 \# & \cc{Precision} & \cc{Recall} & F1 &\cc{MAP} \\
 \midrule
 0 & 0.0117 & 0.6838 & 0.0230 & 0.0112 \\
 1 & 0.0099 & 0.7084 & 0.0195 & 0.0109 \\
 2 & 0.0095 & 0.7096 & 0.0187 & 0.0105 \\
 3 & 0.0088 & 0.7215 & 0.0174 & 0.0101 \\[0.25\normalbaselineskip]
 4 & 0.0085 & 0.7401 & 0.0168 & 0.0096 \\
 5 & 0.0080 & 0.7467 & 0.0158 & 0.0087 \\
 6 & 0.0079 & 0.7571 & 0.0156 & 0.0088 \\
 7 & 0.0073 & 0.7794 & 0.0145 & 0.0087 \\[0.25\normalbaselineskip]
 8 & 0.0071 & 0.7902 & 0.0141 & 0.0085 \\
 9 & 0.0069 & 0.7981 & 0.0137 & 0.0084 \\
 10 & 0.0065 & 0.7990 & 0.0129 & 0.0078 \\
 \bottomrule
 \end{tabular}
 \end{table}
 \end{document}

enter image description here

| improve this answer | | | | |

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.