如何在数字中用无衬线字体排版数学符号

如何在数字中用无衬线字体排版数学符号

我正在尝试在 tikz 图形中用无衬线字体排版数学,并且我遵循了在这里找到的一些指导,但没有得到结果。我正在添加 MWE,非常感谢您的帮助,以便正确完成。

\documentclass{standalone}

\input{../bookdef}
\input{../tikz-include}
\tikzset{every picture/.style={/utils/exec={\sffamily}},>=triangle 45}
\usepackage{float} % to easily modify floats
\usepackage{sansmath} % sans serif math
\usepackage{everyhook} % nice \every... patching
% restyle figures to make \everymath=\sansmath (float package)
\restylefloat{figure}
\floatevery{figure}{\PushPreHook{math}{\sansmath}}
% undo the change to \everymath at the end of the figure (etoolbox)
\apptocmd{\endfigure}{\PopPreHook{math}}{}{}

\usetikzlibrary{external}
\tikzexternalize

\tikzexternalize[prefix=./Chapter11]

\pgfplotsset{compat=1.16}
\begin{document}

\begin{tikzpicture}
\tikzset{
circ/.style={circle,draw,minimum width=0.7cm, minimum height=0.7cm},
box/.style = {rectangle, draw, minimum width=1cm, rounded corners},
font={\fontsize{10pt}{12}\selectfont}
}

\node[minimum size=2cm,regular polygon,draw,regular polygon sides=3,shape border rotate=-90,text width=0.5cm,inner sep=-2mm,outer sep=-0pt] (a) {\hspace{-6pt}\parbox{0.5cm}{Data\\[-4pt]Source}};
\node[circ,right= of a] (p2) {P};
\node[box, above right= of p2,yshift=-1cm] (w4) {$W_{4}$};
\node[box, below right= of p2,yshift=1cm] (w5) {$W_{5}$};
\node[fit=(p2)(w4) (w5), draw, dashed, inner sep=0.3cm] {};
\node[above=7pt of p2,xshift=8pt] (lbl1) {Operation 2};
\draw[->] (a) -- (p2);
\draw[->] (p2) -- (w4);
\draw[->] (p2) -- (w5);
\end{tikzpicture}
\end{document}

答案1

根据问题使用everymath sansmath 时遇到的问题将你的 mwe 降低到

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows,fit,positioning,,shapes.geometric}
\usepackage{sansmath} % sans serif math
\sansmath % if you use it globaly


\begin{document}
    \begin{tikzpicture}[
    node distance =1mm and 12mm,
circ/.style = {circle, draw, minimum width=0.7cm, minimum height=0.7cm},
 box/.style = {rectangle, draw, minimum width=1cm, rounded corners},
font =\sffamily% \sansmath % if you use it only in this picture

                        ]
\node[regular polygon,draw, regular polygon sides=3, shape border rotate=-90,
      minimum size=2cm, text width=1cm, inner sep=-1mm, outer sep=0pt] (a) {Data\\[-2pt]Source};
\node[circ,right= of a] (p2) {P};
\node[box, above right=of p2] (w4) {$W_{4}$};
\node[box, below right=of p2] (w5) {$W_{5}$};
\node[fit=(p2)(w4) (w5), draw, dashed,inner sep=3mm, xshift=-2mm] (FIT) {};
\node[below right] (lbl1) at (FIT.north west) {Operation 2};
\draw[->] (a) -- (p2);
\draw[->] (p2) -- (w4);
\draw[->] (p2) -- (w5);
    \end{tikzpicture}
\end{document}

你将获得:

在此处输入图片描述

相关内容