整个 tikz 图形的独特字体

整个 tikz 图形的独特字体

使用 tikzpicture 环境,我希望图形的所有元素都使用一种字体 (helvetica)。在下面给出的示例代码中,只有图例和轴标签采用 helvetica 字体。

提前感谢您对我的请求的关注。

代码示例


\documentclass[a4paper,12pt,oneside,final,french]{book}

\headheight = 15pt 
\usepackage[margin=2.5cm, left=3cm, top=2.5cm, bottom=2.5cm]{geometry}

\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}

\usepackage{helvet} 
\renewcommand{\familydefault}{\sfdefault}
\usepackage{xcolor}

\definecolor{Noir50}{RGB}{50, 50, 50}
\definecolor{Noir100}{RGB}{100, 100, 100}
\definecolor{Noir150}{RGB}{150, 150, 150}
\definecolor{Noir200}{RGB}{200, 200, 200}

\usepackage{graphicx,subcaption}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}


\begin{document}

\begin{figure}
    \centering
    \begin{tikzpicture} 
        \begin{axis}[ height=6cm, width=0.7\textwidth, axis lines=left,ymin=-3500, ymax=3500,xmin=-6, xmax=6, xlabel={Label 1},ylabel={Label 2}] 
            \addplot[smooth,mark=square,Noir50] {-x^5 - 242}; 
            \addlegendentry{model} 
            \addplot[smooth,mark=*,Noir100] coordinates { 
            (-4.77778,2027.60977) (-3.55556,347.84069) (-2.33333,22.58953) (-1.11111,-493.50066) (0.11111,46.66082) (1.33333,-205.56286) (2.55556,-341.40638) (3.77778,-1169.24780) (5.00000,-3269.56775) }; \addlegendentry{estimate} 
        \end{axis} 
    \end{tikzpicture}
    \caption{Example of curve}
\end{figure}

\end{document}

样本渲染 在此处输入图片描述

答案1

刻度标签默认以数学模式排​​版,请参阅手册/pgfplots/xticklabel={<command>}中的选项文档。pgfplots

要将 helvetica 也设置为数学字体,请参阅数学字体 Helvetica 非斜体。请注意,这通常会产生全局影响。另请查看相关问题:https://tex.stackexchange.com/search?q=%5Bpgfplots%5D+tick+label+font

要在文本模式下排版刻度标签,请尝试

xticklabel={\pgfmathprintnumber{\tick}},
/pgf/number format/assume math mode=true

完整示例

\documentclass[a4paper,12pt,oneside,final,french]{book}

\headheight = 15pt 
\usepackage[margin=2.5cm, left=3cm, top=2.5cm, bottom=2.5cm]{geometry}

\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}

\usepackage{helvet} 
\renewcommand{\familydefault}{\sfdefault}
\usepackage{xcolor}

\definecolor{Noir50}{RGB}{50, 50, 50}
\definecolor{Noir100}{RGB}{100, 100, 100}
\definecolor{Noir150}{RGB}{150, 150, 150}
\definecolor{Noir200}{RGB}{200, 200, 200}

\usepackage{graphicx,subcaption}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}


\begin{document}

\begin{figure}
    \centering
    \pgfset{}
    \begin{tikzpicture} 
        \begin{axis}[ height=6cm, width=0.7\textwidth, axis lines=left,ymin=-3500, ymax=3500,xmin=-6, xmax=6, xlabel={Label 1},ylabel={Label 2},
        xticklabel={\pgfmathprintnumber{\tick}},
        /pgf/number format/assume math mode=true
        ] 
            \addplot[smooth,mark=square,Noir50] {-x^5 - 242}; 
            \addlegendentry{model} 
            \addplot[smooth,mark=*,Noir100] coordinates { 
            (-4.77778,2027.60977) (-3.55556,347.84069) (-2.33333,22.58953) (-1.11111,-493.50066) (0.11111,46.66082) (1.33333,-205.56286) (2.55556,-341.40638) (3.77778,-1169.24780) (5.00000,-3269.56775) }; \addlegendentry{estimate} 
        \end{axis} 
    \end{tikzpicture}
    \caption{Example of curve}
\end{figure}

\end{document}

在此处输入图片描述

相关内容