0

EDIT: it turned out, that my real file problem was caused by another package.

(This question is closely related to a prior question of mine Package dcolumn displays different fonts as that still didn't solve my original problem (see the comments).)

Im am using the beamer class. Hence the sans-serif font is the default in this document.

I have/want to use an OTF font, so my file relies on package fontspec.

There is a table, which incorporates a D-colunm from dcolumn package, as well as regular r or l columns. I was very surprised to find out, that the D column does not use sans-serif fonts!

I could boil down the problem to package fontspec.

Here is a MWE producing a correct output:

\documentclass{beamer}
\usepackage{dcolumn}
\newcolumntype{E}{D{,}{,}{-3}}
\begin{document}
\begin{frame}
  \frametitle{Correct Math Font}
  \begin{center}
    With PDF\LaTeX{} or Lua\LaTeX{} \\
    but without package \texttt{fontspec}\\
    \begin{tabular}{rE}
      1,23 & 1,23
    \end{tabular}
  \end{center}
\end{frame}
\end{document}

And this is the output, as expected.

Correct output

Now, simply add the line \usepackage{fontspec} to that MWE and it gets weird.

EDIT: Ulrike Fischer did answer and was able to solve the problem given in that MWE above. But using that solution on my real file, did not work. It turned out, that another package requires the package unicode-math which in turn brings up the same problem again. I edited the MWE below by inserting \usepackage{unicode-math} as well.

\documentclass{beamer}
\usepackage{dcolumn}
\usepackage{fontspec}
\usepackage{unicode-math}
\newcolumntype{E}{D{,}{,}{-3}}
\begin{document}
\begin{frame}
  \frametitle{Incorrect Math Font}
  \begin{center}
    With Lua\LaTeX{} and \\
    with package \texttt{fontspec}\\
    \begin{tabular}{rE}
      1,23 & 1,23
    \end{tabular}
  \end{center}
\end{frame}
\end{document}

This time, you get this output:

Incorrect output with rm fonts in the second column

As you can clearly see, the right column is in normal, upright roman font. Why is that and---even more important---how to fix this?

EDIT: Ulrike Fischers answer did solve my first question, before I had to edit it. So, technically speaking, her answer deserves the green check mark also (at least partially). After having upgraded my question with regard to the unicode-math package, the answer from Davislor solves my question completely!

2 Answers 2

2

In a comment, you followed up and said you need a version that works with unicode-math. Since your column package appears to switch to math mode, one way to make this work is to turn on professionalfonts and load the sans-serif faces for your math alphabets yourself.

\documentclass[professionalfonts]{beamer}
\usepackage{unicode-math}
\usepackage{dcolumn}
\newcolumntype{E}{D{,}{,}{-3}}

\setmainfont{NewComputerModernBook}
\setsansfont{NewComputerModernSansBook}
\setmonofont{NewComputerModernMonoBook}
\setmathfont{NewCMMath-Book.otf}
\setmathfont{NewCMSans10-Book}[range={up,"2C}]
\setmathfont{NewCMSans10-BookOblique}[range=it]
\setmathfont{NewCMSans10-Bold}[range=bfup]
\setmathfont{NewCMSans10-BoldOblique}[range=bfit]
\setmathrm{NewComputerModernSansBook}

\begin{document}
\begin{frame}
  \frametitle{Incorrect Math Font}
  \begin{center}
    With Lua\LaTeX{} and \\
    with package \texttt{fontspec}\\
    \begin{tabular}{rE}
      1,23 & 1,23
    \end{tabular}
  \end{center}
\end{frame}
\end{document}

New Computer Modern Sans sample

The range={up} option takes care of letters and digits. You also need to set any punctuation you need, such as, in this case, the comma (U+2C).

A simpler alternative would be to load a sans-serif math font, such as \setmathfont{KpMath-Sans.otf}. This lets you skip overriding its math alphabets. You would still want to \setmathrm or \setmainfont to a sans-serif font.

1
  • Thank you, this did the trick. :-)
    – Jan
    Commented Dec 6, 2020 at 17:54
3

If you don't want fontspec to affect the math setup you can use the no-math option

\documentclass{beamer}
\usepackage{dcolumn}
\usepackage[no-math]{fontspec}
\newcolumntype{E}{D{,}{,}{-3}}
\begin{document}
\begin{frame}
  \frametitle{Correct Math Font}
  \begin{center}
    With Lua\LaTeX{} and \\
    with package \texttt{fontspec}\\
    \begin{tabular}{rE}
      1,23 & 1,23
    \end{tabular}
  \end{center}
\end{frame}
\end{document}
5
  • Thank you very much!
    – Jan
    Commented Dec 6, 2020 at 13:34
  • Bad news. :-( I use the dtk-logo package, which---in turn---loads package unicode-math. This re -establishes the old problem again. Any suggestions how to fix that?
    – Jan
    Commented Dec 6, 2020 at 14:13
  • You also deserve the green marker! Sorry.
    – Jan
    Commented Dec 6, 2020 at 17:54
  • personally I don't care much, but normally you shouldn't edit a question and make an answer invalid, better ask a new question if you realize that you missed something important. Commented Dec 6, 2020 at 18:23
  • Oh.Thanks for the advice!
    – Jan
    Commented Dec 6, 2020 at 18:28

You must log in to answer this question.

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