如何在 tics 和 pgfplot 標籤中獲得相同的字體?

如何在 tics 和 pgfplot 標籤中獲得相同的字體?

我嘗試在 pgf 圖中所有可能的位置使用相同的字體。在這個論壇上待了很多小時並嘗試了書面解決方案後,我不知道。

非常感謝您提前的幫忙。

問候,Th。

\documentclass{scrartcl}

\usepackage{fontspec}
\setmainfont{Arial}

\usepackage{etoolbox}
% change fonts to sans serif then `tikzpicture' environment is started
\BeforeBeginEnvironment{tikzpicture}{
    \begingroup
        \changeFonts
}
% end scope (for font change)
\AfterEndEnvironment{tikzpicture}{
    \endgroup
}
\usepackage{sansmath}
% create a command to switch fonts in `tikzpicture' environments to a
% sans serif font
\newcommand*\changeFonts{
   \sffamily\sansmath
}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

10 <> $\mathsf 10$!

\begin{figure}[htbp]
\centering
\begin{tikzpicture}
\begin{axis}[xlabel={Abscissa, $x_\mathsf{10}$}, ylabel={Ordinate, $y$}]
\addplot {x^2};
\end{axis}
\end{tikzpicture}
\caption{A figure with a \texttt{pgfplots} axis.}
\end{figure}

\end{document}

答案1

您可以將所有刻度標籤字體變更為 sansserif

\pgfplotsset{my style/.append style={xticklabel={$\mathsf{\pgfmathprintnumber{\tick}}$},

 yticklabel={$\mathsf{\pgfmathprintnumber{\tick}}$} } }

然後新增my style到軸選項:

begin{axis}[my style, xlabel={Abscissa, $x_\mathsf{10}$}, ylabel={Ordinate, $y$}]

相關內容