Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to know the easiest way to ensure that the content inside a tabular, including siunitx columns is set using a/the sans serif math font. The normal document is set in serif font.

This approach shows some of my attempts:

\documentclass[paper=a4, fontsize=11pt]{scrartcl}
\usepackage{lmodern}
\usepackage{amsmath}
\usepackage{dcolumn}
\usepackage{siunitx}

\makeatletter 
% dcolumn column
\newcolumntype{d}[1]{>{\DC@{.}{ ,}{#1}}l<{\DC@end}}
% sans serif d-column (from http://www.torsten-schuetze.de/tex/tabsatz-2004.pdf)
\newcolumntype{j}[1]{%
>{\DC@{.}{,}{#1}\mathsf\bgroup}l%
<{\egroup\DC@end}%
}
% sans serif column, including math
\newcolumntype{k}{%
>{$\mathsf\bgroup}l%
<{\egroup$}%
}
\makeatother

\begin{document}%

% table with d-columns: fails to compile
\begin{tabular}{j{4.2}d{4.2}ll}
\hline
2.3456 & 2.3456 & 2.3456 & 2.3456 \\
34.2345 & 34.2345 & 34.2345 & 34.2345 \\
56.7835 & 56.7835 & 56.7835 & 56.7835 \\
\hline
\end{tabular}

\mbox{}\vspace{1em}\\

% using siunitx commands instead
\sisetup{table-figures-integer = 2, table-figures-decimal = 4, math-rm=\mathsf}
\sffamily
\begin{tabular}{S
k
S[table-number-alignment = left]
S[table-number-alignment = right]}
\hline
{Some Values} & {Some Values} & {Some Values / \si{kg/m^2}} & {Some Values} \\
\hline
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 \\
\hline
\end{tabular}

\end{document}%

The first tabular fails to compile. The second is set in sans serif except the \si{} command. However the code looks quite complicated. Appended is the result.

enter image description here

share|improve this question
1  
Not part of the question, but you could just use table-format = 2.4 in place of table-figures-integer = 2, table-figures-decimal = 4. –  Joseph Wright Nov 14 '11 at 13:24
add comment

2 Answers 2

up vote 5 down vote accepted

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.

share|improve this answer
    
Thanks for the answer. I am working on a talk for students and this version is what I am going to present. The complete lecture will be available next week. –  Matthias Pospiech Nov 14 '11 at 15:41
    
The decimal separator is not set to sans-serif. Visible e.g. with locale=DE. How can I get that corrected? –  LaRiFaRi Jul 23 '13 at 16:19
    
I found it myself: \sisetup{detect-family, mode=text} –  LaRiFaRi Jul 24 '13 at 8:04
add comment

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}}
share|improve this answer
    
Alternatively, for siunitx you'd set both math-rm = \mathsf and text-rm = \sffamily. [I'd nearly got an answer read for that plus detect-family :-)] –  Joseph Wright Nov 14 '11 at 13:23
    
@Stefan Kottwitz: As far as I understand the sansmath package works only with a few font packages. I for example am using charter and the math version, together with frutiger as a sans font. Also I do not really want to use the dcolumn package. @JosephWright: setting math-rm and text-rmseems to work. –  Matthias Pospiech Nov 14 '11 at 13:37
    
@JosephWright: You could write an answer which Matthias could accept. –  Stefan Kottwitz Nov 14 '11 at 13:49
    
This is a case where I think \sansmath\( and \)\unsansmath are better than using $ since then it's clear what's inside and what's outside mathmode… –  Seamus Nov 14 '11 at 14:28
    
@StefanKottwitz Done –  Joseph Wright Nov 14 '11 at 15:36
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.