Same font style for all tikzpicture elements

fontstikz-pgf

I want all labels and elements of a tikzpicture barplot to have the same font style.

\documentclass{scrartcl} 
\usepackage{tikz, pgfplots}

\begin{document}
    \sffamily
    \begin{center}
        {\Large \textbf{Title}}
        
        \begin{tikzpicture}[font=\sffamily]
            \tikzstyle{every node}=[font=\sffamily]
            \begin{axis}[
                ybar,
                xticklabel={$\mathsf{\pgfmathprintnumber{\tick}}$},
                yticklabel={$\mathsf{\pgfmathprintnumber{\tick}}$},
                xtick={1, 2},
                xticklabels={A, B},
                ]
                \addplot [color = red]coordinates {
                    (1,1000000) 
                    (2,2000000) 
                };                          
            \end{axis}
        \end{tikzpicture}
    \end{center}
\end{document}

I almost got it, but the power of ten is still in serif font.

enter image description here

Best Answer

\sffamily is not enough because numbers and labels are in math mode.

The package sansmath will do the tick.

The command \sansmath behaves as \boldmath does.

a

\documentclass{scrartcl} 
\usepackage{pgfplots}

\usepackage{sansmath}% added <<<<<<<<<<<<<<<<

\begin{document}
    
    \sffamily
    \begin{center}
        {\Large \textbf{Title}} 
            
        \begin{tikzpicture}[font=\sansmath\sffamily] % changed <<<<<<<<<<<<<<<<<<
            \begin{axis}[
                ybar,
                xticklabel={$\mathsf{\pgfmathprintnumber{\tick}}$},
                yticklabel={$\mathsf{\pgfmathprintnumber{\tick}}$},
                xtick={1, 2},       
                xticklabels={A, B},
                ]
                \addplot [color = red]coordinates {
                    (1,1000000) 
                    (2,2000000) 
                };                          
            \end{axis}
        \end{tikzpicture}
    \end{center}

\end{document}

See Change font family in pgfplots

Related Question