如何将 pgfplot 环境的数学字体更改为 sans(如果需要,还可以使用 luaotfload 后备)?

如何将 pgfplot 环境的数学字体更改为 sans(如果需要,还可以使用 luaotfload 后备)?

我想将我的字体(尤其是图表中的数学字体)更改为无字体 Segoe UI。不幸的是,这行不通。

我已经尝试了以下建议:

  1. 仅更改图形的数学字体(包括图形内的 TikZ 环境)
  2. 包 \usepackage[nottext]{sansmathfonts}

我目前的解决方案部分有效,至少对所有拉丁字形有效,但特别是我的希腊字形和数学特定字符没有按照我的意图进行编译。我目前的解决方案的另一个让我不满意的地方是,我的全局设置 \pgfplotsset没有像我预期的那样产生全局影响。相反,我仍然必须将所有字形放入其中\mathsf{}(为了尝试每种类型的字形,我在示例中更频繁地使用它。)。

对我来说,最理想的情况是,我只有 XITS 和 XITS math 字体以及 Segoe UI,如果 Segoe UI 缺少​​任何字符,则需要回退选项。对于回退选项,我认为 Computer Modern Bright (cmbright) 是一个不错的选择,因为它看起来有些相似,并且应该具有很好的字形多样性。

\documentclass[
draft=false,
paper=a5,
twoside=on,
DIV=calc,
fontsize=10pt,
BCOR=15.0mm,
parskip=half,
cleardoublepage=empty,
headsepline,
pagesize=luatex,
]
{scrbook}

%%% BASIC
%%% ---------------------------------------------------------------------------
\usepackage[english,ngerman]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}


%%% FONTS
%%% ---------------------------------------------------------------------------
\usepackage{fix-cm}

\usepackage{luaotfload}
\usepackage{fontspec}
\usepackage{unicode-math} %[math-style=ISO]
\defaultfontfeatures{Scale=MatchLowercase, Ligatures=TeX}   
\setmathfont{XITS Math}
\setmainfont[    
Extension = .otf,
UprightFont = *-regular,
BoldFont = *-bold,
ItalicFont = *-italic,
BoldItalicFont = *-bolditalic,
Scale=1.0
]{XITS}

% Fallback font for the sans fonts in case glyphs are missing
\directlua
{luaotfload.add_fallback
    ("sansfallback",
    {
        "cmbright:mode=node;"
    }
    )
}

\setsansfont[    
Extension = .ttf,
UprightFont = *,
BoldFont = *b,
ItalicFont = *i,
BoldItalicFont = *z,
]{Segoe UI}
\setmathsf[RawFeature={fallback=sansfallback}]{Segoe UI}
\setmonofont{Inconsolatazi4-Regular.otf}

\usepackage{microtype}

%----------------------------------------------------------------------------------------
% SIGNS AND SYMBOLS
%----------------------------------------------------------------------------------------
\usepackage{textgreek} 
\usepackage[version=4]{mhchem} 
\usepackage{siunitx}[=v2]

%----------------------------------------------------------------------------------------
%   FIGURES & DIAGRAMS 
%----------------------------------------------------------------------------------------
\usepackage{standalone}
\usepackage{pgfplotstable} 
% NOTE: pgfplots uses tikz internally therefore loads already: pgfplots, tikz, xcolor, graphicx
\pgfplotsset{
    compat=1.17, % compat=newest
    %--- Fontset in the plots doen't work properly  
    tick label style = {font=\sffamily},
    every axis label/.append style = {font=\sffamily},
    every axis/.append style={font=\sffamily},
    every legend/.append style = {font=\sffamily},
    label style = {font=\sffamily},
    nodes near coords style={font=\sffamily},
}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{pgfplots.groupplots,mindmap,shapes,arrows,external}

%----------------------------------------------------------------------------------------
%   BIBLIOGRAPHY 
%----------------------------------------------------------------------------------------
\usepackage[backend=biber,natbib=true,doi=true,style=bath,sorting=ynt]{biblatex} % Use the bibtex backend 
%----------------------------------------------------------------------------------------
%   REFERENCING PACKAGES 
%----------------------------------------------------------------------------------------
% Extensive support for hypertext in LaTeX
\usepackage{caption}
\usepackage{subcaption}
\captionsetup{
    margin=0mm,
    font={small,sf},
    labelfont={bf}, 
    labelsep=quad, %endash,
    format=hang,%, hangindent=5mm
    justification=RaggedRight,
    figurename=Abb.,
    tablename=Tab.
}
\usepackage[ngerman,english]{varioref}

\usepackage{etoolbox}
\usepackage{auxhook}
\AtEndPreamble{
    \usepackage[colorlinks]{hyperref}
    \usepackage[noabbrev, capitalise, ngerman]{cleveref}
}

\addbibresource{refrences.bib} % The filename of the bibliography

\begin{document}
    
Einfacher Text mit einem Formelzeichen $\left\langle \bar{\alpha} \right\rangle$ wird in XITS geschrieben aber Diagramme sollen Segoe UI verwenden.
    
\begin{figure}[h!]
    \centering
    \begin{tabular}{ c  c  }
        \begin{tikzpicture}
            \begin{axis}[
                height=4.6cm,
                width=5.5cm,
                axis x line=middle, 
                axis y line=left,
                xmax=1*1.1,
                xmin=-6,
                xtick={-5,-2,0},
                xticklabels={$-\alpha_1 - \mathrm{d}\alpha$,$-\alpha_1$,$t=0$},
                ymin=0,
                ymax=1*1.1,
                ytick={0,1},
                xlabel={$\alpha$},
                tick label style={font=\sffamily},
                ]           
                \draw[name path=limit, black, dotted] (\pgfkeysvalueof{/pgfplots/xmin},1) -- (\pgfkeysvalueof{/pgfplots/xmax},1);
                \draw[name path=null, black] (\pgfkeysvalueof{/pgfplots/xmin},0) -- (\pgfkeysvalueof{/pgfplots/xmax},0);
                \addplot [gray] fill between [of=limit and null, soft clip={domain=-5:-2}];
            \end{axis}
        \end{tikzpicture}
        &
        \begin{tikzpicture}
            \begin{axis}[
                height=4.6cm,
                width=5.5cm,
                axis x line=middle, 
                axis y line=left,
                xmax=11,
                xmin=0,
                xtick={0,2,4,6},
                xticklabels={0,$\alpha_1$,$ $,$\alpha_1+\mathrm{d}\alpha$},
                ymin=0,
                ymax=0.5*1.1,
                ytick={0,0.5},
                yticklabels={0,$\frac{1}{\tau}$},
                xlabel={$\alpha$},
                ylabel={$\phi\left(\alpha\right)$},
                ]           
                \draw[name path=null, black] (\pgfkeysvalueof{/pgfplots/xmin},0) -- (\pgfkeysvalueof{/pgfplots/xmax},0);
                \addplot [name path=A,domain=0:10, samples=100, thick, black] {1/2*exp(-x/2)};
                \addplot [gray] fill between [of=A and null, soft clip={domain=2:6}];
            \end{axis}
        \end{tikzpicture}
        \\
        \begin{tikzpicture}
            \begin{axis}[
                height=4.6cm,
                width=5.5cm,
                axis x line=center, 
                axis y line=left,
                xmax=10*1.1,
                xmin=0,
                xtick={0,2,4,6},
                xticklabels={0,$\alpha_1$,$ $,$\alpha_1+\mathrm{d}\alpha$},
                ymin=0,
                ymax=1*1.1,
                ytick={0,1},
                xlabel={$\alpha$},
                ylabel={$\Phi\left(\alpha\right)$},
                tick label style={font=\sffamily}
                ]           
                \draw[name path=null, black] (\pgfkeysvalueof{/pgfplots/xmin},0) -- (\pgfkeysvalueof{/pgfplots/xmax},0);
                \addplot [domain=0:2, samples=100, thick, black] {1-exp(-x/2)};
                \addplot [name path=A,domain=2:10, samples=100, dashed] {1-exp(-x/2)};
                \draw[name path=one, black, dotted] (\pgfkeysvalueof{/pgfplots/xmin},1) -- (\pgfkeysvalueof{/pgfplots/xmax},1);
                \addplot [gray] fill between [of=A and one, soft clip={domain=2:6}];
            \end{axis}
        \end{tikzpicture}
        &
        \begin{tikzpicture}
            \begin{axis}[
                height=4.6cm,
                width=5.5cm,
                axis x line=center, 
                axis y line=left,
                xmax=10*1.1,
                xmin=0,
                xtick={0,2,4,6},
                xticklabels={0,$\alpha_1$,$ $,$\alpha_1+\mathrm{d}\alpha$},
                ymin=0,
                ymax=1*1.1,
                ytick={0,1},
                xlabel={$\alpha$},
                ylabel={$\Omega\left(\alpha\right)$},
                tick label style={font=\sffamily}
                ]           
                \draw[name path=null, black] (\pgfkeysvalueof{/pgfplots/xmin},0) -- (\pgfkeysvalueof{/pgfplots/xmax},0);
                \addplot [domain=0:2, samples=100, dashed] {exp(-x/2)};
                \addplot [name path=A,domain=2:10, samples=100, thick, black] {exp(-x/2)};
                \draw[black, dotted] (\pgfkeysvalueof{/pgfplots/xmin},1) -- (\pgfkeysvalueof{/pgfplots/xmax},1);
                \addplot [gray] fill between [of=A and null, soft clip={domain=2:6}];
            \end{axis}
        \end{tikzpicture}
    \end{tabular}
    \caption{Diagramm 1}
    \label{fig1}
\end{figure}

\begin{figure}[h!]
    \centering
    \begin{tikzpicture}
        \begin{axis}[
            height=9.3cm,
            width=9.3cm,
            axis lines=left,
            xmax=3,
            xmin=0,
            xtick={0,0.4},
            xticklabels={$\mathsf{0}$,$\mathsf{0,\!4}$},
            ymin=0,
            ymax=3,
            ytick={0,0.55},
            yticklabels={$\mathsf{0}$,$\mathsf{0,\!55}$},
            xlabel={X-Achse $\mathsf{n}$ in $\mathsf{h^{-1}}$},
            ylabel={Y-Achse $\left\langle\bar{\mathsf{n}}\right\rangle_\mathsf{i}$ in $\mathsf{h^{-1}}$},
            ]
            
            \addplot [domain=0:{\pgfkeysvalueof{/pgfplots/xmax}*0.93}, samples=100, thin, black!25!gray] {0.4} node[above,pos=0.99,color=black!25!gray] {$\mathsf{IV}$};
            \addplot [domain=0:{\pgfkeysvalueof{/pgfplots/xmax}*0.87}, samples=100, thin, black!25!gray] {0.5} node[above,pos=0.99,color=black!25!gray] {$\mathsf{III}$};
            \addplot [domain=0:{\pgfkeysvalueof{/pgfplots/xmax}*0.82}, samples=100, thin, black!25!gray] {0.6} node[above,pos=0.99,color=black!25!gray] {$\mathsf{II}$};
            \addplot [domain=0:{\pgfkeysvalueof{/pgfplots/xmax}*0.77}, samples=100, thin, black!25!gray] {0.7} node[above,pos=0.99,color=black!25!gray] {$\mathsf{I}$};
            
            \draw[name path=null, black, dotted] (0.4,\pgfkeysvalueof{/pgfplots/ymin}) -- (0.4,{\pgfkeysvalueof{/pgfplots/ymax}}) node[above,pos=0.95,color=black, rotate=90] {$\mathsf{EGE}$};
            \addplot [domain=0:{\pgfkeysvalueof{/pgfplots/xmax}}, samples=100, dotted, black] {0.55} node[above,pos=0.95,color=black] {$\mathsf{EGE}$};
            \draw[name path=null, thick, black] (0.4,0.55) -- (0.4,0.8);
            \addplot [domain=0.4:0.55, samples=100, thick, black] {0.55};

            \addplot [name path=Limit, domain=0:10, samples=100, thin, white] {3}; 
            \addplot [domain=0:{\pgfkeysvalueof{/pgfplots/xmax}}, samples=100, thin, black!25!gray] {0.3*2*x} node[above,pos=0.97,color=black!25!gray, rotate=31] {$\mathsf{0,\!3}$};
            \addplot [domain=0:{\pgfkeysvalueof{/pgfplots/xmax}}, samples=100, thin, black!25!gray] {0.4*2*x} node[above,pos=0.97,color=black!25!gray, rotate=38.7] {$\mathsf{0,\!4}$};
            \addplot [domain=0:{\pgfkeysvalueof{/pgfplots/xmax}}, samples=100, thin, black!25!gray] {0.5*2*x} node[above,pos=0.90,color=black, rotate=45] {$\mathsf{\varepsilon}_\mathsf{i}^\mathsf{a,r}\mathsf{=0,\!5}$};
            \addplot [domain=0:{\pgfkeysvalueof{/pgfplots/xmax}/1.2}, samples=100, thin, black!25!gray] {0.6*2*x} node[above,pos=0.95,color=black!25!gray, rotate=50.2] {$\mathsf{0,\!6}$};
            \addplot [domain=0:{\pgfkeysvalueof{/pgfplots/xmax}/1.4}, samples=100, thin, black!25!gray] {0.7*2*x} node[above,pos=0.95,color=black!25!gray, rotate=54.5] {$\mathsf{0,\!7}$};
            \addplot [name path=PFND, domain=0:{\pgfkeysvalueof{/pgfplots/xmax}/2}, samples=100, thin, black!25!gray] {2*x} node[above,pos=0.97,color=black, rotate=63.4] {$\mathsf{1}$};
            
            \addplot [name path=MX, domain=0.55:{\pgfkeysvalueof{/pgfplots/xmax}}, samples=100, thick, black] {x} node[above,pos=0.65,color=black, rotate=45] {$\mathsf{Strömungsform 2}$};
            \addplot [domain=0.4:{\pgfkeysvalueof{/pgfplots/xmax}/2}, samples=100, thick, black] {2*x}  node[above,pos=0.65,color=black, rotate=63.4] {$\mathsf{Strömungsform 1}$};
            
            \addplot [gray] fill between [of=Limit and PFND, soft clip={domain=0.01:{\pgfkeysvalueof{/pgfplots/xmax}/2}}];
            \draw[name path=null, black] (\pgfkeysvalueof{/pgfplots/xmin},0) -- (\pgfkeysvalueof{/pgfplots/xmax},0);
        \end{axis}
    \end{tikzpicture}
    \caption{Diagramm 2}
    \label{fig2}
\end{figure}

\end{document}

refrences.bib文件如下所示:

@report{Weltg.2005,
 author = {WHO},
 year = {2005},
 title = {Air quality guidelines for particulate matter, ozone, nitrogen dioxide and sulfur dioxide},
 url = {https://apps.who.int/iris/rest/bitstreams/65728/retrieve},
 urldate = {2021-10-29},
 publisher = {{WHO Press, World Health Organization}},
 editor = {Weltgesundheitsorganisation},
 pagetotal = {22},
 titleaddon = {Global update 2005},
 subtitle = {Summary of risk assessment}
}

相关内容