sans serif math in tables and siunitx
If you specify the option detect-family
for siunitx
, the package would be able to detect that the units are used in sans-serif mode.
\usepackage[detect-family]{siunitx}
You could use the sansmath
package for switching to sans-serif math:
\usepackage{sansmath}
\newcolumntype{k}{>{\sansmath$}l<{$\unsansmath}}
Use \sansmath
and \unsansmath
outside math mode, so with dcolumn
before \DC@
and after \DC@end
, respectively:
\newcolumntype{d}[1]{>{\sansmath\DC@{.}{ ,}{#1}}l<{\DC@end\unsansmath}}
With siunitx
, there are a couple of potential approaches. First, as Stefan has said you can detect the current font:
\documentclass[paper=a4, fontsize=11pt]{scrartcl}
\usepackage{booktabs,lmodern,siunitx}
\usepackage{siunitx}
\newcolumntype{k}{%
>{$\mathsf\bgroup}l%
<{\egroup$}%
}
\begin{document}
\sffamily
\begin{center}
\sisetup{table-format = 2.4,detect-family}
\begin{tabular}{S
k
S[table-number-alignment = left]
S[table-number-alignment = right]}
\toprule
{Some Values} & {Some Values} & {Some Values / \si{kg/m^2}} & {Some Values} \\
\midrule
2.3456 & 2.3456 & 2.3456 & 2.3456 \\
{$\mathsf{a^2}$} & 34.2345 & 34.2345 & 34.2345 \\
56.7835 & 56.7835 & 56.7835 & 56.7835 \\
\bottomrule
\end{tabular}
\end{center}
\end{document}
The second approach is to set the font used by siunitx
for both text and math mode material to be sanserif
\documentclass[paper=a4, fontsize=11pt]{scrartcl}
\usepackage{booktabs,lmodern,siunitx}
\usepackage{siunitx}
\newcolumntype{k}{%
>{$\mathsf\bgroup}l%
<{\egroup$}%
}
\begin{document}
\sffamily
\begin{center}
\sisetup{table-format = 2.4, math-rm=\mathsf, text-rm=\sffamily}
\begin{tabular}{S
k
S[table-number-alignment = left]
S[table-number-alignment = right]}
\toprule
{Some Values} & {Some Values} & {Some Values / \si{kg/m^2}} & {Some Values} \\
\midrule
2.3456 & 2.3456 & 2.3456 & 2.3456 \\
{$\mathsf{a^2}$} & 34.2345 & 34.2345 & 34.2345 \\
56.7835 & 56.7835 & 56.7835 & 56.7835 \\
\bottomrule
\end{tabular}
\end{center}
\end{document}
In both cases, I've used table-format = 2.4
as a shortcut to set up the reserved space. This is often easier than doing things piece by piece.