我尝试在 tikz-node 中以无衬线字体打印四舍五入的数字。但是,它不起作用。我如何才能将数字四舍五入并以无衬线字体打印?
\documentclass{standalone}
\usepackage{tikz}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
\begin{tikzpicture}
\node at (0,0) {3.14}; %how it should be
\node at (1,1) {\pgfmathprintnumber[fixed, precision=2]{3.14159265358979323}}; %not working
\end{tikzpicture}
\end{document}
答案1
您也可以使用选项assume math-mode
。\pgfmathprintnumber
这样就不会自动切换到数学模式,数字将按原样打印。
\documentclass{standalone}
\usepackage{tikz}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
\begin{tikzpicture}
\node at (0,0) {3.14}; %how it should be
\node at (1,1) {\pgfmathprintnumber[fixed, precision=2,assume math mode]{3.14159265358979323}};
\end{tikzpicture}
\end{document}
答案2
您可以使用\mathsf
:
\documentclass{standalone}
\usepackage{tikz}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
\begin{tikzpicture}
\node at (0,0) {3.14};
\node at (1,1) {$\mathsf{\pgfmathprintnumber[fixed, precision=2]{3.14159265358979323}}$};
\end{tikzpicture}
\end{document}
或者您可以sansmath
本地加载并启用\mathversion{sans}
:
\documentclass{standalone}
\usepackage{sansmath}
\usepackage{tikz}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
\begin{tikzpicture}
\mathversion{sans}
\node at (0,0) {3.14};
\node at (1,1) {\pgfmathprintnumber[fixed, precision=2]{3.14159265358979323}};
\end{tikzpicture}
\end{document}