Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
have you looked at the etoolbox? –  cmhughes Jan 5 at 17:35
    
@cmhughes No. Unfortunately I don't have enough knowledge about TeX and its primitives. –  Keks Dose Jan 5 at 17:38
add comment

2 Answers

up vote 5 down vote accepted
\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}
share|improve this answer
add comment

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}
share|improve this answer
1  
+1 for introducing \AtBeginEnvironment. –  I am who I say I am Jan 5 at 17:47
1  
Or \preto{\tabular}{\fontfamily{phv}\selectfont}, but one must know the definition of tabular for realizing this is possible. –  egreg Jan 5 at 19:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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