# Selecting font features for tabular data

I am writing my thesis using (among others) the KOMA-script and fontspec packages. I would like to select the default sans serif font (and add some font features) for my tables. I know how to do this by manually selecting the font for each table (I add \sffamily\addfontfeature{Numbers=Uppercase,Monospaced}), but I would prefer to do this for the whole document in the preamble. KOMA-script allows me to select specific fonts for captions using \addtokomafont{…}{…}, but I cannot find a way to do this for the actual tabular data in the tables. Is there a way?

Below is a minimal working example.

\documentclass{scrartcl}
\usepackage{fontspec}
\usepackage{tabularx}
\setmainfont[Ligatures=TeX, Numbers=Lowercase]{texgyrepagella-regular.otf}

\begin{document}

test, 1, 2, 3, 5, 7, 9, $1, 2, 3, 5, 7, 9$.

\begin{table}
\begin{tabularx}{.25\linewidth}{lc}
&   Test    \\
a   &   1, 5    \\
b   &   2, 7    \\
c   &   3, 9    \\
\end{tabularx}
\end{table}
\end{document}

• As you have not given an MWE, I can't test this, but maybe \floatevery{table}{\sffamily\addfontfeature{Numbers=Uppercase,Monospaced}} from the float package can do what you want. – LaRiFaRi Mar 5 '15 at 13:31
• Instead of using float, which is kind of a big whacky hammer compared to KOMA you can use etoolbox and append your font setup to the table-environment, maybe. Please provide a minimal working example to reduce guesswork on our side. – Johannes_B Mar 6 '15 at 16:12

Thanks to the comment from Johannes_B and an earlier post here, my problem has been solved; see below. etoolbox works perfectly. I've tried LaRiFaRi's solution too, but couldn't get it to work.

\documentclass{scrartcl}
\usepackage{fontspec}
\usepackage{tabularx}
%\usepackage{float}
\setmainfont[Ligatures=TeX, Numbers=Lowercase]{texgyrepagella-regular.otf}

\usepackage{etoolbox}
\AtBeginEnvironment{tabularx}{%
}

\begin{document}
test, 1, 2, 3, 5, 7, 9, $1, 2, 3, 5, 7, 9$.
`