8

I made a coordinate system with pgfplots. Now I want the font to be in sans serif, so I tried the command \sffamily after document start (just like in the example). With this everything is in sans serif but the y-axis labels. I tried \begin{tikzpicture}[font=\sffamily] as well as \pgfplotsset{ticklabel style = {font=\sffamily}, y axis label/.append style={font=\sffamily}, } but all of this comes to the same result shown underneath the code.

Does anybody know how to get the font of the y axis in sans serif, too?

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}

\begin{document}
\sffamily

\begin{tikzpicture}
\begin{axis}[
    width=14cm,
    height=7cm,
    scale only axis,
    xmin=-5,xmax=105,
    ymin=0,ymax=12,
    x dir=reverse,
    axis y line*=right,
    axis x line*=top,
    xtick=\empty,
    extra x ticks={0,10,20,30,40,50,60,70,80,90,100},
    extra x tick labels={{0},{10},{20},{30},{40},{50},{60},{70},{80},{90},{100}},
    every x tick/.style={},
    xlabel=Palmfett / Gew.\%,
    xlabel style={at={(0.5,1.225)}},
    ]
\end{axis}

\begin{axis}[
    width=14cm,
    height=7cm,
    scale only axis,
    xmin=-5 ,xmax=105,
    ymin=0, ymax=12,
    axis y line*=left,
    axis x line*=bottom,
    xtick=\empty,
    extra x ticks={0,10,20,30,40,50,60,70,80,90,100},
    extra x tick labels={{0},{10},{20},{30},{40},{50},{60},{70},{80},{90},{100}},
    extra x tick style={grid=major},
    every x tick/.style={},
    xlabel=Bienenwachs / Gew.\%,
    ylabel=Martenshärte / N/mm$^2$
    ]

\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

0

2 Answers 2

4

If you only need to change the font of certain elements then you can define them so

\begin{tikzpicture}
\begin{axis}[
    width=14cm,
    height=7cm,
    scale only axis,
    xmin=-5,xmax=105,
    ymin=0,ymax=12,
    x dir=reverse,
    axis y line*=right,
    axis x line*=top,
    xticklabel={$\mathsf{\pgfmathprintnumber{\tick}}$},
    yticklabel={$\mathsf{\pgfmathprintnumber{\tick}}$},
    xlabel=Palmfett / Gew.\%,
    xlabel style={at={(0.5,1.225)}},
    ]
\end{axis}
\begin{axis}[
    width=14cm,
    height=7cm,
    scale only axis,
    xmin=-5 ,xmax=105,
    ymin=0, ymax=12,
    axis y line*=left,
    axis x line*=bottom,
    xticklabel={$\mathsf{\pgfmathprintnumber{\tick}}$},
    yticklabel={$\mathsf{\pgfmathprintnumber{\tick}}$},
    xlabel=Bienenwachs / Gew.\%,
    ylabel=Martenshärte / N/mm$^2$
    ]
\end{axis}
\end{tikzpicture}

This will keep the axis labels untouched but the tikc labels in sans-serif without going through the extra label declarations.

3

The tick labels are type set in math mode i.e., $0$ etc. So the \sffamily is not respected there. You can either force \sffamily in math mode as per the answers to this question or make ytick=\empty as you did for xticks and use extra y ticks. Also, it is enough to pass [font=\sffamily] to tikzpicture to change the font.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
%\usepackage{cmbright}
\pgfplotsset{compat=1.12}%,tick label style={font=\sffamily},}
\begin{document}
%\sffamily 

\begin{tikzpicture}[font=\sffamily]
\begin{axis}[
    width=14cm,
    height=7cm,
    scale only axis,
    xmin=-5,xmax=105,
    ymin=0,ymax=12,
    x dir=reverse,
    axis y line*=right,
    axis x line*=top,
    xtick=\empty,
    extra x ticks={0,10,20,30,40,50,60,70,80,90,100},
    extra x tick labels={{0},{10},{20},{30},{40},{50},{60},{70},{80},{90},{100}},
    ytick=\empty,
    extra y ticks={0,2,4,6,8,10,12},
    extra y tick labels={{0},{2},{4},{6},{8},{10},{12}},
    every x tick/.style={},
    xlabel=Palmfett / Gew.\%,
    xlabel style={at={(0.5,1.225)}},
    ]
\end{axis}

\begin{axis}[
    width=14cm,
    height=7cm,
    scale only axis,
    xmin=-5 ,xmax=105,
    ymin=0, ymax=12,
    axis y line*=left,
    axis x line*=bottom,
    xtick=\empty,
    extra x ticks={0,10,20,30,40,50,60,70,80,90,100},
    extra x tick labels={{0},{10},{20},{30},{40},{50},{60},{70},{80},{90},{100}},
    extra x tick style={grid=major},
    ytick=\empty,
    extra y ticks={0,2,4,6,8,10,12},
    extra y tick labels={{0},{2},{4},{6},{8},{10},{12}},
    every x tick/.style={},
    xlabel=Bienenwachs / Gew.\%,
    ylabel=Martenshärte / N/mm$^2$
    ]

\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

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