3

enter image description here

I would like to align the numbers on their decimal point. I used the following code for my table:

\usepackage{siunitx}
\usepackage{dcolumn}

 \begin{table}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabular}{cc|cccc}
    \toprule
    \multicolumn{2}{c}{\multirow{2}[2]{*}{Variable}} & \multirow{2}[2]{*}{Mean } & \multicolumn{1}{r}{\multirow{2}[2]{*}{Standard Deviation}} & \multirow{2}[2]{*}{Skewness} & \multirow{2}[2]{*}{Kurtosis} \\
    \multicolumn{2}{c}{} &       &       &       &  \\
    \midrule
    \multicolumn{2}{c|}{} &       &       &       &  \\
    \multicolumn{2}{c|}{a} &     6.23 &   1.89 &   0.65 & 2.00 \\
    \multicolumn{2}{c|}{b} &   25.74 & 14.84 &   0.85 & 2.73 \\
    \multicolumn{2}{c|}{c} &   30.94 & 17.05 &   0.00 & 1.96 \\
    \multicolumn{2}{c|}{d} &   42.88 & 15.40 &   0.78 & 3.15 \\
    \multicolumn{2}{c|}{e} &   30.14 & 14.39 &   1.39 & 4.28 \\
    \multicolumn{2}{c|}{f} &   23.03 & 14.26 &   1.84 & 6.13 \\
    \multicolumn{2}{c|}{g} &   51.67 & 17.66 &  -0.29 & 2.30 \\
    \multicolumn{2}{c|}{h} &   41.48 & 19.96 &   0.70 & 2.66 \\
    \multicolumn{2}{c|}{i} &   52.89 & 23.54 &  -0.36 & 2.33 \\
    \multicolumn{2}{c|}{j} &   40.23 & 20.99 &   0.01 & 2.03 \\
    \multicolumn{2}{c|}{k} &  46.38 & 16.54 &   1.03 & 3.02 \\
    \multicolumn{2}{c|}{l} & 100.09 &   1.05 &  -1.35 & 6.44 \\
    \multicolumn{2}{c|}{m} &  99.57 &   1.36 &  -0.45 & 2.06 \\
    \bottomrule
    \end{tabular}%
  \label{tab:addlabel}%
\end{table}%

Thank you very much!

1
  • Welcome to tex.stack...
    – MadyYuvi
    Jun 25, 2019 at 10:59

4 Answers 4

3

You have several redundancies in your code. The two columns before | are not used; also \multirow seems completely unnecessary. Empty rows are not the best way to add vertical spacing (which doesn't seem good, by the way).

Use S from siunitx, specifying the column format.

\documentclass{article}
\usepackage{siunitx,booktabs}

\begin{document}

\begin{table}[htbp]
\centering

\caption{Add caption}\label{tab:addlabel}

\begin{tabular}{
  l
  S[table-format=3.2]
  S[table-format=2.2]
  S[table-format=-1.2]
  S[table-format=1.2]
}
\toprule
Variable & {Mean} & {Standard Deviation} & {Skewness} & {Kurtosis} \\
\midrule
a &   6.23 &  1.89 &  0.65 & 2.00 \\
b &  25.74 & 14.84 &  0.85 & 2.73 \\
c &  30.94 & 17.05 &  0.00 & 1.96 \\
d &  42.88 & 15.40 &  0.78 & 3.15 \\
e &  30.14 & 14.39 &  1.39 & 4.28 \\
f &  23.03 & 14.26 &  1.84 & 6.13 \\
g &  51.67 & 17.66 & -0.29 & 2.30 \\
h &  41.48 & 19.96 &  0.70 & 2.66 \\
i &  52.89 & 23.54 & -0.36 & 2.33 \\
j &  40.23 & 20.99 &  0.01 & 2.03 \\
k &  46.38 & 16.54 &  1.03 & 3.02 \\
l & 100.09 &  1.05 & -1.35 & 6.44 \\
m &  99.57 &  1.36 & -0.45 & 2.06 \\
\bottomrule
\end{tabular}

\end{table}

\end{document}

enter image description here

4

I propose this variant, based on siunitx. I loaded caption to have a correct spacing between caption and table. normally, rules from booktabs shouldn't be used with vertical rules, due the padding around the horizontal rules. However, a single thicker vertical grey rule is acceptable (to my eyes). I didn't use multirow, replacing it with\setcellgapesfrommakecell`.

\documentclass{report}
\usepackage{siunitx}
\usepackage[svgnames]{xcolor}
\usepackage{caption, booktabs, multirow, makecell}

\begin{document}

\begin{table}[!htb]%
\sisetup{table-format=2.2, table-number-alignment=center}
\setcellgapes{3pt}\makegapedcells
\centering
\caption{Add caption}
\begin{tabular}{c!{\color{LightGrey!80}\vline width 2.5pt}S[table-format=3.2]S S[table-format=-1.2]S}
\toprule
\multicolumn{1}{c}{Variable} & {Mean} & {\makecell{Standard\\ Deviation}} & {Skewness} & {Kurtosis} \\
\midrule
a & 6.23 & 1.89 & 0.65 & 2.00 \\
b & 25.74 & 14.84 & 0.85 & 2.73 \\
c & 30.94 & 17.05 & 0.00 & 1.96 \\
d & 42.88 & 15.40 & 0.78 & 3.15 \\
e & 30.14 & 14.39 & 1.39 & 4.28 \\
f & 23.03 & 14.26 & 1.84 & 6.13 \\
g & 51.67 & 17.66 & -0.29 & 2.30 \\
h & 41.48 & 19.96 & 0.70 & 2.66 \\
i & 52.89 & 23.54 & -0.36 & 2.33 \\
j & 40.23 & 20.99 & 0.01 & 2.03 \\
k & 46.38 & 16.54 & 1.03 & 3.02 \\
l & 100.09 & 1.05 & -1.35 & 6.44 \\
m & 99.57 & 1.36 & -0.45 & 2.06 \\
\bottomrule
\end{tabular}%
\end{table}%

\end{document} 

enter image description here

6
  • thank you for your reply. i have also other tables and for all tables their numbers should be aligned on their decimal points. Is it possible to have this feature for all tables in general? thank you
    – tibiooo
    Jun 26, 2019 at 10:11
  • You have to use the S column type for that.
    – Bernard
    Jun 26, 2019 at 12:30
  • I tried it, but didn't work for me. When i know how many S i have to replace for c?
    – tibiooo
    Jun 26, 2019 at 12:35
  • As many as columns with numbers having to be aligned. However, remember that a cell in an S column may have non-aligned content (e.g. the column head). In this case, put the content between a pair of braces, so it be centred.
    – Bernard
    Jun 26, 2019 at 12:44
  • 1
    @Mico: Matter of personal taste… (actually I'd prefer to have all lines grey, but I thought it would make things needlessly complex).
    – Bernard
    Jun 26, 2019 at 14:10
2

Not sure what is the purpose to use \multirow in this table! Hope the below modified tag may suits with you:

\documentclass{book}
\usepackage{siunitx}
\usepackage{multirow,dcolumn,booktabs}
\begin{document}

\newcolumntype{d}[1]{D{.}{.}{#1}}%

\begin{table}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabular}{cc|d{3,2}d{2,2}d{2,2}d{1,2}}
    \toprule
    Variable & &\multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{Standard Deviation} & \multicolumn{1}{c}{Skewness} & \multicolumn{1}{c}{Kurtosis} \\
    \midrule
    \multicolumn{2}{c|}{} &       &       &       &  \\
    \multicolumn{2}{c|}{a} &     6.23 &   1.89 &   0.65 & 2.00 \\
    \multicolumn{2}{c|}{b} &   25.74 & 14.84 &   0.85 & 2.73 \\
    \multicolumn{2}{c|}{c} &   30.94 & 17.05 &   0.00 & 1.96 \\
    \multicolumn{2}{c|}{d} &   42.88 & 15.40 &   0.78 & 3.15 \\
    \multicolumn{2}{c|}{e} &   30.14 & 14.39 &   1.39 & 4.28 \\
    \multicolumn{2}{c|}{f} &   23.03 & 14.26 &   1.84 & 6.13 \\
    \multicolumn{2}{c|}{g} &   51.67 & 17.66 &  -0.29 & 2.30 \\
    \multicolumn{2}{c|}{h} &   41.48 & 19.96 &   0.70 & 2.66 \\
    \multicolumn{2}{c|}{i} &   52.89 & 23.54 &  -0.36 & 2.33 \\
    \multicolumn{2}{c|}{j} &   40.23 & 20.99 &   0.01 & 2.03 \\
    \multicolumn{2}{c|}{k} &  46.38 & 16.54 &   1.03 & 3.02 \\
    \multicolumn{2}{c|}{l} & 100.09 &   1.05 &  -1.35 & 6.44 \\
    \multicolumn{2}{c|}{m} &  99.57 &   1.36 &  -0.45 & 2.06 \\
    \bottomrule
    \end{tabular}%
  \label{tab:addlabel}%
\end{table}%


\end{document}
2

Your MWE is not complete. I had to add the booktabs package and the multirow package.

Here, the solution is to use the S column (from the siunitx package).

\documentclass{article}
\usepackage{siunitx}
\usepackage{dcolumn}
\usepackage{booktabs}
\usepackage{multirow}

\begin{document}

 \begin{table}[htbp]
  \centering
  \caption{Add caption}
  \begin{tabular}{cc|SSSS}
    \toprule
    \multicolumn{2}{c}{\multirow{2}[2]{*}{Variable}} & {\multirow{2}[2]{*}{Mean}} & {\multirow{2}[2]{*}{Standard Deviation}} & {\multirow{2}[2]{*}{Skewness}} & {\multirow{2}[2]{*}{Kurtosis}} \\
    \multicolumn{2}{c}{} &       &       &       &  \\
    \midrule
    \multicolumn{2}{c|}{} &       &       &       &  \\
    \multicolumn{2}{c|}{a} &     6.23 &   1.89 &   0.65 & 2.00 \\
    \multicolumn{2}{c|}{b} &   25.74 & 14.84 &   0.85 & 2.73 \\
    \multicolumn{2}{c|}{c} &   30.94 & 17.05 &   0.00 & 1.96 \\
    \multicolumn{2}{c|}{d} &   42.88 & 15.40 &   0.78 & 3.15 \\
    \multicolumn{2}{c|}{e} &   30.14 & 14.39 &   1.39 & 4.28 \\
    \multicolumn{2}{c|}{f} &   23.03 & 14.26 &   1.84 & 6.13 \\
    \multicolumn{2}{c|}{g} &   51.67 & 17.66 &  -0.29 & 2.30 \\
    \multicolumn{2}{c|}{h} &   41.48 & 19.96 &   0.70 & 2.66 \\
    \multicolumn{2}{c|}{i} &   52.89 & 23.54 &  -0.36 & 2.33 \\
    \multicolumn{2}{c|}{j} &   40.23 & 20.99 &   0.01 & 2.03 \\
    \multicolumn{2}{c|}{k} &  46.38 & 16.54 &   1.03 & 3.02 \\
    \multicolumn{2}{c|}{l} & 100.09 &   1.05 &  -1.35 & 6.44 \\
    \multicolumn{2}{c|}{m} &  99.57 &   1.36 &  -0.45 & 2.06 \\
    \bottomrule
    \end{tabular}%
  \label{tab:addlabel}%
\end{table}%
\end{document}

enter image description here

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.