I'm trying to create a table using pgfplotstable
. It works almost fine, just asking myself why \sffamily
in front of \pgfplotstabletypeset
is not working.
2 Answers
The numbers in pgfplotstable
are typeset in math mode. In order to influence the way they are typed you either need to load a package that changes the math fonts or use a \mathversion
command. By default LaTeX only defines math versinos normal
and bold
. As you only need a limited number of symbols for typesetting numbers, you can set up a math version sans serif
as follows:
\documentclass{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.8}
\DeclareMathVersion{sansserif}
\SetSymbolFont{operators}{sansserif}{OT1}{cmss}{m}{n}
\pgfplotstableread{
level dof error1
1 4 2.50000000e-01
2 16 6.25000000e-02
3 64 1.56250000e-02
4 256 3.90625000e-03
5 1024 9.76562500e-04
6 4096 2.44140625e-04
7 16384 6.10351562e-05
8 65536 1.52587891e-05
9 262144 3.81469727e-06
10 1048576 9.53674316e-07
}\mytable
\begin{document}
\begin{minipage}[t]{0.4\linewidth}
\pgfplotstabletypeset{\mytable}
\end{minipage}
\qquad
\begin{minipage}[t]{0.4\linewidth}
\sffamily \mathversion{sansserif} \pgfplotstabletypeset{\mytable}
\end{minipage}
\end{document}
When \mathversion{sansserif}
is in force, any operator
font symbols are set to cmss
, the sans serif version of computer modern. (lmss
would be an obviosu alternative if using latin modern fonts). Now we can switch to sans serif for text via \sffamily
and for math via \mathversion{sansserif}
. Switch back with \normalfont
and \mathversion{normal}
.
pgfplotstable
relies on LaTeX's famous math mode to typeset its numbers. This, in turn, does not work with \sffamily
.
That said, I am always a little bit confused of what the actual answer is as I never really understood the details of math fonts. If I am not mistaken, one has to add some special \usepackage
instruction to replace math fonts throughout the document. But I hope that I am wrong.
Perhaps you should search for the answers to the question "How can I use sans serif fonts in math mode" -- the answer is applicable here as well.