6

I'd like to put some lines in the preamble to change the font of all tabulars in the document. I know that I can easily define my own environment »mytabular«. But for different reasons I need to change tabular. I thought about simply adding (see MWE below) code to the macro, unfortunately without success.

\documentclass{article}

    \makeatletter
    \g@addto@macro\tabular\fontfamily{phv}\selectfont
    \makeatother

\begin{document}

This is some text.

\bigskip

\begin{tabular}{lr}
  Hello! & 1234 \\
\end{tabular}
\end{document}

Those tabulars will be used outside floats, so it does not help to change something in the table environment.

2
  • have you looked at the etoolbox?
    – cmhughes
    Commented Jan 5, 2014 at 17:35
  • @cmhughes No. Unfortunately I don't have enough knowledge about TeX and its primitives.
    – Keks Dose
    Commented Jan 5, 2014 at 17:38

2 Answers 2

5
\documentclass{article}
\let\Tabular\tabular
\let\endTabular\endtabular
\renewcommand\tabular{\sffamily\Tabular}
\renewcommand\endtabular{\endTabular\normalfont}

\begin{document}
This is some text.

\bigskip
\begin{tabular}{lr}
  Hello! & 1234 
\end{tabular}

foo
\end{document}
10

The etoolbox can help here; in particular, the command AtBeginEnvironment can be used

\AtBeginEnvironment{tabular}{\fontfamily{phv}\selectfont}

Here's the output, and a complete MWE to play with:

screenshot

\documentclass{article}
\usepackage{etoolbox}

\AtBeginEnvironment{tabular}{\fontfamily{phv}\selectfont}

\begin{document}

This is some text.

\begin{tabular}{lr}
  Hello! & 1234 \\
\end{tabular}
\end{document}
3
  • 1
    +1 for introducing \AtBeginEnvironment. Commented Jan 5, 2014 at 17:47
  • 1
    Or \preto{\tabular}{\fontfamily{phv}\selectfont}, but one must know the definition of tabular for realizing this is possible.
    – egreg
    Commented Jan 5, 2014 at 19:04
  • Very useful solution both in answer and comment thank you, much favoured over chosen answer as much more user friendly.
    – Fiztban
    Commented Jan 30, 2015 at 1:57

You must log in to answer this question.

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