我有一个带有自定义字体的文档montserrat
。我还有以下情节:
\documentclass[a4paper]{standalone}
\usepackage[extralight,defaultfam,light,tabular,lining]{montserrat} % Font
% For bar chart
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymajorgrids=true,
scale only axis,
xtick={1,2,3,4,5},
xticklabels={Foo,Bar,Baz,FooBar,FooBaz},
every axis plot/.append style={
ybar,
bar width=20,
bar shift=0pt,
fill
},
ymin=0,
]
\addplot[purple] coordinates {(1,1)};
\addplot[red] coordinates {(2,2)};
\addplot[yellow] coordinates {(3,3)};
\addplot[gray] coordinates {(4,6)};
\addplot[blue] coordinates {(5,2)};
\end{axis}
\end{tikzpicture}
\end{document}
montserrat
不幸的是,只有 x 轴似乎适应了 montserrat 字体,即 y 轴仍使用默认的 latex 字体。我怎样才能让 y 轴也以该字体显示?
答案1
感谢 Henri Menke 用户。
\documentclass[a4paper]{standalone}
\usepackage[extralight,defaultfam,light,tabular,lining]{montserrat} % Font
\usepackage[italic]{mathastext}
% For bar chart
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymajorgrids=true,
scale only axis,
xtick={1,2,3,4,5},
xticklabels={Foo,Bar,Baz,FooBar,FooBaz},
every axis plot/.append style={
ybar,
bar width=20,
bar shift=0pt,
fill
},
ymin=0,
]
\addplot[purple] coordinates {(1,1)};
\addplot[red] coordinates {(2,2)};
\addplot[yellow] coordinates {(3,3)};
\addplot[gray] coordinates {(4,6)};
\addplot[blue] coordinates {(5,2)};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
告诉pgfplots
刻度标签应该是文本\normalfont
。
\documentclass[a4paper,border=2]{standalone}
\usepackage[extralight,defaultfam,light,tabular,lining]{montserrat} % Font
% For bar chart
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymajorgrids=true,
scale only axis,
tick label style={font=\normalfont},
xtick={1,2,3,4,5},
xticklabels={Foo,Bar,Baz,FooBar,FooBaz},
ytick={0,1,2,3,4,5,6},
yticklabels={0,1,2,3,4,5,6},
every axis plot/.append style={
ybar,
bar width=20,
bar shift=0pt,
fill
},
ymin=0,
]
\addplot[purple] coordinates {(1,1)};
\addplot[red] coordinates {(2,2)};
\addplot[yellow] coordinates {(3,3)};
\addplot[gray] coordinates {(4,6)};
\addplot[blue] coordinates {(5,2)};
\end{axis}
\end{tikzpicture}
\end{document}