1

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}
\usepackage{tgpagella, tgadventor}
\setmainfont[Ligatures=TeX, Numbers=Lowercase]{texgyrepagella-regular.otf}
\setsansfont[Ligatures=TeX, Numbers=Uppercase]{texgyreadventor-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}
2
  • 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, 2015 at 13:31
  • 1
    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, 2015 at 16:12

1 Answer 1

0

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}
\setsansfont[Ligatures=TeX, Numbers=Uppercase]{texgyreadventor-regular.otf}

\usepackage{etoolbox}
\AtBeginEnvironment{tabularx}{%
   \sffamily\addfontfeature{Numbers={Monospaced, Uppercase}}%
}


\begin{document}
%\floatevery{table}{\sffamily\addfontfeature{Numbers={Uppercase,Monospaced}}}

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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .