1

Could any of you tell me how do I align the decimal points in the 8th column and why is it that I’m not seeing vertical column dividers in the first row except before classes?

\begin{center}
\begin{tabular}{r|c|r|r|l|l|l|r|l}
\multicolumn{1}{c}{$i$} & classes & \multicolumn{1}{c}{$x_i$} & \multicolumn{1}{c}{$f_i$} & \multicolumn{1}{c}{$f_{ri}$} & \multicolumn{1}{c}{$\sum f_{ri}$} & \multicolumn{1}{c}{$f_{tri}$} & \multicolumn{1}{c}{$f_{ti}$} & \multicolumn{1}{c}{$\sum f_{tri}$} \\\hline
1                       & 14–18 & 16                        & 28                        &                              &                                   & given                          & 27,7                         &                                    \\
2                       & 18–22 & 20                        & 18                        &                              &                                   & given                          & 18,3                         &                                    \\
3                       & 22–26 & 24                        & 11                        &                              &                                   & given                          & 11,05                        &                                    \\
4                       & 26–30 & 28                        & 9                         &                              &                                   & given                          & 6,5                          &                                    \\
5                       & 30–34 & 32                        & 2                         &                              &                                   & given                          & 3,8                          &                                    \\
6                       & 34–38 & 36                        & 2                         &                              &                                   & given                          & 2,2                          &                                    \\
7                       & 38–42 & 40                        & 0                         &                              &                                   & given                          & 1,9                          &                                    \\
8                       & 42–46 & 44                        & 1                         &                              &                                   & given                          & 0,7                          &                                    \\
9                       & 46–50 & 48                        & 1                         &                              &                                   & given                          & 0,43                         &                                    \\
10                      & 50–52 & 52                        & 1                         &                              &                                   & given                          & 0,24                         &                                   
\end{tabular}
\end{center}

Thank you so much!

Joseph
  • 11

2 Answers2

2

Could any of you tell me ... why is it that I’m not seeing vertical column dividers in the first row except before "classes"?

It's because of the \multicolumn{1}{c}{...} "wrappers"; if you want a vertical divider at the end of the column, write \multicolumn{1}{c|}{...}. For what it's worth, I would get rid of all vertical dividers. They aren't needed, and their major contribution is to create visual clutter. Instead, I would recommend you provide a bit more vertical breathing space to the table, e.g., after the 5th row of data.

Could any of you tell me how do I align the decimal points in the 8th column

Since you've set the siunitx tag and mention the package in the title of your posting, I assume you wish to use the S column type. To use the S column type for the 8th column of the table, replace r with S[table-format=2.2] in the header of the tabular environment. I further assume you want to use commas as decimal markers in the typeset output as well, not only in the input; if that's correct, add \sisetup{output-decimal-marker={,}} in the preamble (after loading siunitx).

enter image description here

\documentclass{article}
\usepackage{siunitx,booktabs}
\sisetup{output-decimal-marker={,}}

\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro

\begin{document}

\begin{center}
\begin{tabular}{rcrrlllS[table-format=2.2]l}
\mc{$i$} & classes & \mc{$x_i$} & \mc{$f_i$} & \mc{$f_{ri}$} & \mc{$\sum f_{ri}$} 
   & \mc{$f_{tri}$} & \mc{$f_{ti}$} & \mc{$\sum f_{tri}$} \\
\midrule
1 & 14--18 & 16  & 28  & & & given & 27,7  &  \\
2 & 18--22 & 20  & 18  & & & given & 18,3  &  \\
3 & 22--26 & 24  & 11  & & & given & 11,05 &  \\
4 & 26--30 & 28  & 9   & & & given &  6,5  &  \\
5 & 30--34 & 32  & 2   & & & given &  3,8  &  \\
\addlinespace
6 & 34--38 & 36  & 2   & & & given &  2,2  &  \\
7 & 38--42 & 40  & 0   & & & given &  1,9  &  \\
8 & 42--46 & 44  & 1   & & & given &  0,7  &  \\
9 & 46--50 & 48  & 1   & & & given &  0,43 &  \\
10& 50--52 & 52  & 1   & & & given &  0,24 &  \\
\end{tabular}
\end{center}
\end{document}
Mico
  • 506,678
  • Incidentally, the OP's code contains the unicode character to denote en-dashes. In the code above, I've replaced all instances of this character with -- (two dashes). – Mico Jun 26 '16 at 16:25
1

You can use dcolumn package:

\documentclass{article}
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{,}{,}{#1}}
\begin{document}
  \begin{tabular}{r|c|r|r|l|l|l|d{2,2}|l}
  \multicolumn{1}{c}{$i$} & classes & \multicolumn{1}{c}{$x_i$} & \multicolumn{1}{c}{$f_i$} & \multicolumn{1}{c}{$f_{ri}$} & \multicolumn{1}{c}{$\sum f_{ri}$} & \multicolumn{1}{c}{$f_{tri}$} & \multicolumn{1}{c}{$f_{ti}$} & \multicolumn{1}{c}{$\sum f_{tri}$} \\\hline
  1                       & 14–18 & 16                        & 28                        &                              &                                   & given                          & 27,7                         &                                    \\
  2                       & 18–22 & 20                        & 18                        &                              &                                   & given                          & 18,3                         &                                    \\
  3                       & 22–26 & 24                        & 11                        &                              &                                   & given                          & 11,05                        &                                    \\
  4                       & 26–30 & 28                        & 9                         &                              &                                   & given                          & 6,5                          &                                    \\
  5                       & 30–34 & 32                        & 2                         &                              &                                   & given                          & 3,8                          &                                    \\
  6                       & 34–38 & 36                        & 2                         &                              &                                   & given                          & 2,2                          &                                    \\
  7                       & 38–42 & 40                        & 0                         &                              &                                   & given                          & 1,9                          &                                    \\
  8                       & 42–46 & 44                        & 1                         &                              &                                   & given                          & 0,7                          &                                    \\
  9                       & 46–50 & 48                        & 1                         &                              &                                   & given                          & 0,43                         &                                    \\
  10                      & 50–52 & 52                        & 1                         &                              &                                   & given                          & 0,24                         &
  \end{tabular}
\end{document}

FWIW, I googled your question and found the answer here.