1

I have this table that I want to align the numbers based on their decimal place while the numbers are still centered. I tried to siunitx package but it didn't work :(

Any help is highly appreciated! (Data is not real)

\usepackage[format=plain,
            labelfont=it,
            textfont=it]{caption}
\usepackage{array}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{tabu}
\usepackage{booktabs}
\usepackage[tableposition=top]{caption}

\begin{document}

\begin{table}[hbt!] \centering \caption{Time measurements for oil samples with different weights of additive X for 40 and 60$^\circ C$. Dynamic viscosity is then calculated using the viscometer constant, $C$.} \begin{tabular}[t]{c c c c c c} \toprule Concentration (wt%) & $T$ ($^\circ$C) & \multicolumn{3}{c}{$t$ ($s$, $\pm1$)} & Dynamic Viscosity ($cP$, $\pm0.1$)\ & & 1$^{\text{st}}$ & 2$^{\text{nd}}$ & 3$^{\text{rd}}$ & \ \midrule \multirow{2}{*}{0}& 40 & 10 & 10 & 10 & 68.3 \ & 60 & 10 & 10 & 10 & 4.3 \ \

    \multirow{2}{*}{1.875}& 40 & 10 & 10 & 10 & 42.3\\
       & 60 & 10 & 10 & 10 & 3.2\\ \\

    \multirow{2}{*}{2.5}& 40 & 10 & 10 & 10 & 31.4\\
       & 60 & 10 & 10 & 10 & 4.9\\ \\

    \multirow{2}{*}{5}& 40 & 10 & 10 & 10 & 12.2\\
       & 60 & 10 & 10 & 10 & 13.0\\ \\

    \multirow{2}{*}{7}& 40 & 10 & 10 & 10 & 43.2\\
       & 60 & 10 & 10 & 10 & 1.0\\
    \bottomrule

\end{tabular}
\label{tab:my_label}

\end{table} ```

Khalid
  • 41

2 Answers2

2

In addition to aliging the numbers in the data columns on their (explicit or implicit) decimal markers, you should also try to (a) make the table more compact by providing suitable line breaks in the header cells and (b) typeset scientific units and associated quantities more carefully. The latter objective may be achieved easily with the help of the \unit and \qty macros of the siunitx package.

enter image description here

\documentclass{article}
\usepackage[format=plain,font=it,tableposition=top]{caption}
\usepackage{array,siunitx,booktabs,amsmath}
\newcolumntype{T}[1]{S[table-format=#1]}
\newcommand\mytab[1]{%
  \smash[b]{\begin{tabular}[t]{@{}c@{}} #1 \end{tabular}}}

\begin{document}

\begin{table}[hbt!] \centering \caption{Time measurements for oil samples with different weights of additive~X for \qty{40}{\celsius} and \qty{60}{\celsius}. Dynamic viscosity is then calculated using the viscometer constant $C$.} \label{tab:my_label} \begin{tabular}{@{} T{1.3} *{4}{T{2.0}} T{2.1} @{}} \toprule \mytab{Concentration\(wt %)} & \mytab{Temp.\(\unit{\celsius})} & \multicolumn{3}{c}{Time (\unit{\second}, $\pm1$)} & \mytab{Dynamic viscosity\($cP$, $\pm0.1$)}\ \cmidrule(lr){3-5} && {1\textsuperscript{st}} & {2\textsuperscript{nd}} & {3\textsuperscript{rd}} \ \midrule 0 & 40 & 10 & 10 & 10 & 68.3\ & 60 & 10 & 10 & 10 & 4.3\ \addlinespace
1.875 & 40 & 10 & 10 & 10 & 42.3\ & 60 & 10 & 10 & 10 & 3.2\ \addlinespace
2.5 & 40 & 10 & 10 & 10 & 31.4\ & 60 & 10 & 10 & 10 & 4.9\ \addlinespace
5 & 40 & 10 & 10 & 10 & 12.2\ & 60 & 10 & 10 & 10 & 13.0\ \addlinespace
7 & 40 & 10 & 10 & 10 & 43.2\ & 60 & 10 & 10 & 10 & 1.0\ \bottomrule
\end{tabular} \end{table} \end{document}

Mico
  • 506,678
2

With tabularray package (version 2022B) and its libraries booktabs (for table rules) and siunitx (for S columns type, where numbers are aligned at decimal points) which load packages of the same name:

\documentclass{article}
\usepackage[format=plain,
            labelfont=it,
            textfont=it]{caption}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
  \ExplSyntaxOn
\NewChildSelector{eachtwo}
  {
    \int_step_inline:nnnn {3}{2}{\l_tblr_childs_total_tl}
      { \clist_put_right:Nn \l_tblr_childs_clist {##1} }
  }
\ExplSyntaxOff

\begin{document}

\begin{table}[hbt!] \centering \caption{Time measurements for oil samples with different weights of additive~X for \qty{40}{\celsius} and \qty{60}{\celsius}. Dynamic viscosity is then calculated using the viscometer constant $C$.} \label{tab:my_label} \begin{tblr}{colspec = {@{} S[table-format=1.3] *{4}{S[table-format=2.0]} S[table-format=2.1] @{}}, row{1,2} = {guard}, row{3-Z} = {rowsep=0pt}, row{eachtwo} = {abovesep=4pt} } \toprule \SetCell[r=2]{c} {Concentration\(wt %)} & \SetCell[r=2]{c} {Temp.\(\unit{\celsius})} & \SetCell[c=3]{c} Time (\unit{\second}, $\pm1$) & & & \SetCell[r=2]{c} {Dynamic viscosity\($cP$, $\pm0.1$)} \ \midrule & & {1\textsuperscript{st}} & {2\textsuperscript{nd}} & {3\textsuperscript{rd}} & \ \midrule 0 & 40 & 10 & 10 & 10 & 68.3 \ & 60 & 10 & 10 & 10 & 4.3 \ 1.875 & 40 & 10 & 10 & 10 & 42.3 \ & 60 & 10 & 10 & 10 & 3.2 \ 2.5 & 40 & 10 & 10 & 10 & 31.4 \ & 60 & 10 & 10 & 10 & 4.9 \ 5 & 40 & 10 & 10 & 10 & 12.2 \ & 60 & 10 & 10 & 10 & 13.0 \ 7 & 40 & 10 & 10 & 10 & 43.2 \ & 60 & 10 & 10 & 10 & 1.0 \ \bottomrule \end{tblr} \end{table} \end{document}

enter image description here

Zarko
  • 296,517