我希望我的tikz
图像有不同的字体。我该如何更改我的tikzpicture
环境,以便默认情况下它会调用sansmath
环境并选择正确的字体系列。
现在看起来像这样(MWE):
\documentclass[10pt,a4paper]{article}
\renewcommand{\sfdefault}{PTSansNarrow-TLF} %Changes the default sans serif font, used for figures.
\usepackage{sansmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\pgfplotsset{/pgf/number format/assume math mode=true}
\begin{document}
\begin{sansmath}
\fontfamily{PTSansNarrow-TLF}{\fontsize{11}{11}\selectfont
\begin{tikzpicture}
\begin{axis}[xlabel = Period ($\pi$), ylabel = Amplitude ($\Omega$)]
\addplot {sin(deg(x))};
\end{axis}
\end{tikzpicture}
}
\end{sansmath}
\end{document}
我希望最终能得到一些结果,这样我就可以这样做:
\begin{newenvironment}
\begin{axis}[xlabel = Period ($\pi$), ylabel = Amplitude ($\Omega$)]
addplot {sin(deg(x))};
\end{axis}
\end{newenvironment}
答案1
这里可以使用通常的方法\newenvironment
。语法是
\newenvironment{environmentname}{initial material}{final material}
在你的情况下你可以写
\newenvironment{myplot}{\begin{sansmath}
\fontfamily{PTSansNarrow-TLF}\fontsize{11}{11}\selectfont
\begin{tikzpicture}
}{\end{tikzpicture}\end{sansmath}}
获得一个新的环境myplot
:
\documentclass[10pt,a4paper]{article}
\renewcommand{\sfdefault}{PTSansNarrow-TLF} %Changes the default sans serif font, used for figures.
\usepackage{sansmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\pgfplotsset{/pgf/number format/assume math mode=true}
\newenvironment{myplot}{\begin{sansmath}
\fontfamily{PTSansNarrow-TLF}\fontsize{11}{11}\selectfont
\begin{tikzpicture}
}{\end{tikzpicture}\end{sansmath}}
\begin{document}
\begin{myplot}
\begin{axis}[xlabel = Period ($\pi$), ylabel = Amplitude ($\Omega$)]
\addplot {sin(deg(x))};
\end{axis}
\end{myplot}
\end{document}