我如何才能\sffamily
获得\pgfmathprintnumber
?
\documentclass[tikz, border=5mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
font=\Huge\sffamily, % wanted
align=left
]
\node[draw, label={1.23}]{good\\ 1.23};
\node[xshift=3cm, draw, label={\pgfmathprintnumber[]{1.23}},
]{bad \\ \pgfmathprintnumber[fixed]{1.23}};
\end{tikzpicture}
\end{document}
答案1
已编辑以避免丢失格式信息。我所做的是创建一个宏
\newcommand\pgfmathsfprintnumber[2][]{%
\pgfmathprintnumberto[#1]{#2}\z
\expandafter\zz\z}
\newcommand\zz[2]{#1{\mathsf{#2}}}
发送 ,\pgfmathprintnumber
不进行排版,而是放置在宏中\z
。它的格式是\pgfutilensuremath{1.23}
。所以我要做的是吸收两个参数并将它们重新表达为\pgfutilensuremath{\mathsf{1.23}}
\documentclass[tikz, border=5mm]{standalone}
\newcommand\pgfmathsfprintnumber[2][]{%
\pgfmathprintnumberto[#1]{#2}\z
\expandafter\zz\z}
\newcommand\zz[2]{#1{\mathsf{#2}}}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
font=\Huge\sffamily, % wanted
align=left
]
\node[draw, label={1.23}]{good\\ 1.23};
\node[xshift=3cm, draw, label={\pgfmathsfprintnumber{1.23}},
]{bad \\ \pgfmathsfprintnumber[fixed]{1.23}};
\end{tikzpicture}
\end{document}