TransWikia.com

How can I change the font family in pgfplots?

TeX - LaTeX Asked by MindV0rtex on December 17, 2020

I am using the classicthesis package in LyX to typeset my thesis. I have a plot produced with pgfplots. It uses math fonts same as elsewhere in the text, which is inconsistent with other plots of mine (imported from Matlab), where Arial is used for tick and axes labels. So my question is, how can I change the font family for the text used in my pgfplots plot (i.e. the caption font should NOT change)? The minimal TeX code would be:

documentclass[12pt,a4paper]{report}
usepackage[latin1]{inputenc}
usepackage[sc,osf]{mathpazo}
usepackage[euler-digits]{eulervm}
usepackage{pgfplots}
pgfplotsset{compat=1.3}
begin{document}
begin{figure}
centering
pgfplotsset{every axis/.append style={
thick,
tick style={semithick}}}
begin{tikzpicture}
begin{axis}[
height=8cm,
width=15cm,
xlabel = {$x$},
ylabel = {$phi(x)$},
domain = 0:1,
xtick={0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0},
ytick={0.0,0.1,0.2,0.3,0.4,0.5},
grid=major,
no markers,
cycle list name=linestyles
]
addplot {0.5-abs(x-0.5)};
end{axis}
end{tikzpicture}
caption{Solution of Eikonal equation on a 1D domain $Omega=[0;1]$}
end{figure}
end{document}

So I would like all the tick numbers, and x and phi(x) labels to be in Arial, while the bottom caption to remain in Palatino.

2 Answers

Simply using pgfplotsset and sffamily is probably not sufficient for you, since your numbers and labels are in math mode. It can be achieved with the sansmath package, such as

usepackage{helvet}
usepackage[eulergreek]{sansmath}
pgfplotsset{
  tick label style = {font=sansmathsffamily},
  every axis label = {font=sansmathsffamily},
  legend style = {font=sansmathsffamily},
  label style = {font=sansmathsffamily}
}

You probably have still to take care of Greek letters though, if you use eulervm. Without that package, sansmath works well. Or, omit sans serif style for the label, and do it manually at this specific place, such as

xlabel = {$mathsf{x}$},
ylabel = {$phimathsf{(x)}$},

All together I got with your code all labels in sans serif, while the caption remains in serif font:

plot

Correct answer by Stefan Kottwitz on December 17, 2020

This is more of an extended comment than an answer, but I think it might be useful for others.

Following page 75 of the pgfplots manual (Revision 1.17 (2020/02/29))

pgfplotsset{
  xticklabel={$mathsf{pgfmathprintnumber{tick}}$},
  yticklabel={$mathsf{pgfmathprintnumber{tick}}$},
}

Answered by user224544 on December 17, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP