3

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

1 Answer 1

6

\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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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