2

How can I get \sffamily for a \pgfmathprintnumber?

enter image description here

\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 Answer 1

1

EDITED to avoid losing format information. What I did is create a macro

\newcommand\pgfmathsfprintnumber[2][]{%
  \pgfmathprintnumberto[#1]{#2}\z 
  \expandafter\zz\z}
\newcommand\zz[2]{#1{\mathsf{#2}}}

that sends the \pgfmathprintnumber not to be typeset, but placed in a macro \z. It is of the format \pgfutilensuremath{1.23}. So what I do is absorb two arguments and re-express them as \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}

enter image description here

1
  • Helps me good. ;)
    – cis
    May 21, 2021 at 14:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .