2

I have a presentation in beamer with the metropolis theme. All the content of all tables should be written in mono/typewriter font. Ideally I would prefer to make the change globally, inside the preamble.

A workaround, which kinda works, but has to be set locally for each table, is to change the font inside the table environment. See the out-commented two lines.

\documentclass{beamer}
\usetheme{metropolis}

%\setmonofont{Courier Prime}  % (optional) more distinct typewriter font

\usepackage{booktabs}


\begin{document}


\begin{frame}{Typewriter table}

This text should have the default Beamer font.

\begin{table}
  \caption{Default text font}
  %{\ttfamily  % workaround start: until the closed curly bracket, should be typewriter font
  \begin{tabular}{cr}
    \toprule
    Begin \textbf{typewriter} & \textit{mono} \textit{\textbf{font}} \\
    \midrule
    A    &  0.1   \\
    Bc   &  1     \\
    Cde  & 23.45  \\
    Defg &  3.456 \\
    \bottomrule
  \end{tabular}
  %}  % workaround end
  \caption{Default text font}  % added to check both, top and bottom, description variants
\end{table}

This text should have the default Beamer font.

\end{frame}


\end{document}

Screencapture for the workaround enter image description here

1 Answer 1

6

Like this:

Edit: After reading your comments below, your question is not entirely clear, what all are your problems. Anyway, please one problem per question. Now I add one possible solution for option for compiling with LuaLaTeX where is used FiraSans and correct first version, where is now used default Beamer fonts fonts.

Regarding etoolbox: it is needed at older LaTeX version. At recent one definition for \AtBeginEnvironment is integrated in it (now I assume, that you have installed recent LaTeX).

An example compiled with pdfLaTeX:

\documentclass{beamer}
\usetheme{metropolis}

\usepackage{booktabs}
\AtBeginEnvironment{tabular}{\ttfamily} % global setting for tabular


\begin{document}


  \begin{frame}
    \frametitle{Typewriter table}
    
    This text should have the default Beamer.
    
    \begin{table}
      \caption{Default text font} 
      \begin{tabular}{cr}
        \toprule
        Begin \textbf{typewriter} & \textit{mono \textbf{font}}   \\
        \midrule
        A       &  0.1   \\
        Bc      &  1     \\
        Cde     & 23.45  \\
        Defg    &  3.456 \\
        \bottomrule
      \end{tabular}
    \caption{Default text font}  % added to check both, top and bottom, description variants
  \end{table}

  This text should have the default Beamer font.

\end{frame}


\begin{frame}
  \frametitle{Typewriter table}

  This text should have the default Beamer.
  
  \begin{table}
    \caption{Default text font}
    \begin{tabular}{cr}
    \toprule
    Begin typewriter & mono font \\     
    \midrule
    A       &  0.1   \\
    Bc      &  1     \\
    Cde     & 23.45  \\
    Defg    &  3.456 \\
    \bottomrule
    \end{tabular}
  \end{table}

This text should have the default Beamer font.

\end{frame}


\end{document}

enter image description here

An example compiled with LuadfLaTeX and using FiraSans fonts:

\documentclass{beamer}
\usetheme{metropolis}

\usepackage{booktabs}
\usepackage[sfdefault]{FiraSans}    
\AtBeginEnvironment{tabular}{\ttfamily} % global setting for tabular


\begin{document}


\begin{frame}
  \frametitle{Typewriter table}

  This text is in the FiraSans sans Serif fonts.
  
  \begin{table}
    \caption{Default text font}
    \begin{tabular}{cr} % in tabular are use \ttfamily as defined in FiraSans
      \toprule
      Begin \textbf{typewriter} & \textit{mono \textbf{font}}   \\
      \midrule
      A       &  0.1   \\
      Bc      &  1     \\
      Cde     & 23.45  \\
      Defg    &  3.456 \\
      \bottomrule
    \end{tabular}
    \caption{Default text font}  % added to check both, top and bottom, description variants
    \end{table}

This text should have the default Beamer font.

\end{frame}


\begin{frame}
  \frametitle{Typewriter table}

  This text should have the default Beamer.
  
  \begin{table}
  \caption{Default text font}
  \begin{tabular}{cr}
    \toprule
    Begin typewriter & mono font \\
    \midrule
    A       &  0.1   \\
    Bc      &  1     \\
    Cde     & 23.45  \\
    Defg    &  3.456 \\
    \bottomrule
    \end{tabular}
  \end{table}

  This text should have the default Beamer font.

\end{frame}


\end{document}

enter image description here

For defining use FiraSans font only for \ttfamily please ask new question.

6
  • Exactly what I thought of! (+1).
    – Bernard
    Jun 22 at 14:40
  • @Zarko: Thank You! This is very nice! Is etoolbox really required? If yes please comment why -- for me it works fine even without. If possible adjust the indentation inside the code in order be more readable. ... And correct my typo "Tyepwriter".
    – alex
    Jun 22 at 14:52
  • @Zarko: is there a possiblity to change the \ttfamily font only, when using lmodern? I've compiled with lualatex and xelatex and the loading of lmodern package changes all(!) default fonts of metropolis (Fira family).
    – alex
    Jun 22 at 15:10
  • @Zarko: continuation to the comment before: I've tried \setmonofont{Latin Modern Mono} instead of loading lmodern. However it doesen't preserve the boldface highlighting.
    – alex
    Jun 22 at 15:17
  • @alex you can use any monotype font which has bold and italic font. Yes, you can change \ttfamily font. Here on site are many questions (and answers) about this. Since I'm not expert for fonts, I need to search site to learn this, but this you can do yourself :-). About etoolbox: yes it is needed. Do you have problem to use it?
    – Zarko
    Jun 22 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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