我想为序言中的所有 pgf/tikz 图形设置字体系列和大小。但是当我使用 tikzscale 时,这会被忽略。有人能帮忙吗?
\documentclass[a4paper,12pt]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{tikz}
\usepackage{tikzscale}
\tikzset{every picture/.style={font=\sffamily\huge}}
\begin{document}
\input{figure.tikz} %here \sffamily\huge is working
\includegraphics[width=12cm]{figure.tikz} %here \sffamily\huge is ignored
\end{document}
带有图形文件
\begin{tikzpicture}
\node at (0,0) {Foobar};
\draw[dashed] (-5,0) -- (5,0);
\end{tikzpicture}
答案1
我不确定这可能会有什么副作用,但基于Kypm 的回答,您可以将以下内容添加到序言中,这样无需修改代码本身就可以工作tikzpicture
:
\makeatletter
\RenewDocumentCommand{\tikzscale@prepareTikzpicture}{}{%
\tikzset{every picture/.append style={scale=\tikzscale@scale,every picture/.style={}}}%
}
\makeatother
答案2
该课程every picture
由 重置tikzscale
。
查看代码我们可以看到
\NewDocumentCommand{\tikzscale@prepareTikzpicture}{}{% \tikzset{every picture/.style={scale=\tikzscale@scale,every picture/.style={}}}% }
解决方法是使用另一种样式。以下是示例。
主文件:
\documentclass[varwidth,border=1cm,convert]{standalone}
\usepackage{tikz}
\usepackage{tikzscale}
\tikzset{test/.style={font=\sffamily\huge}}
\begin{document}
\input{tikzscale_font.tikz} %here \sffamily\huge is working
\includegraphics[width=12cm]{tikzscale_font.tikz} %here \sffamily\huge is working now too
\end{document}
以及tikzscale_font.tikz
:
\begin{tikzpicture}[test]
\node at (0,0) {Foobar};
\draw[dashed] (-5,0) -- (5,0);
\end{tikzpicture}