我尝试将包含 pic-templates 的 tikz-picture 与 tikzscale 一起使用,但通过 包含图像时,\includegraphics[]{}
我收到各种错误。另一方面,通过 包含图像时,\input{}
过程正常。我的主要文件是
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{makeidx}
\usepackage{graphicx}%\textsl{}
\usepackage{siunitx}
\usepackage{tikz}
\usepackage{tikzscale}
\begin{document}
% \input{test_pic.tikz} %Works
\begin{figure}[htpb]%Does not work
\centering
\includegraphics[width=.9\linewidth]{test_pic.tikz}
\end{figure}
\end{document}
我的 tikz 文件是
\usetikzlibrary{shapes,calc,quotes,positioning}
\tikzset{
demo_box/.pic = {
\coordinate (-in) at (0, 0);
\draw[pic actions] (0, -0.5) rectangle (0.5, 0.5);
\node[align=center, below] at(0, -0.75) {\tikzpictext};
}
}
\begin{tikzpicture}
\pic[fill=white] (demo_node) at (2, 0) {demo_box};
\end{tikzpicture}
在当前配置中我收到错误
! Dimension too large.
<recently read> \pgf@xc
l.11 ...fill=white] (demo_node) at (2, 0) {demo_box}
将我的 tikz 文件中倒数第二行更改为
\pic["Demo", fill=white] (demo_node) at (2, 0) {demo_box};
我得到的是以下错误:
! Package pgfkeys Error: I do not know the key '/tikz/"Demo"' and I am going to
ignore it. Perhaps you misspelled it.
有什么方法可以结合pic
和吗tikzscale
?这些错误来自哪里?
答案1
如果你使用
\begin{figure}[htpb]%Does work <<<<<<<<<<<<<<<<
\centering
\includegraphics{test_pic.tikz}
\end{figure}
\usetikzlibrary{shapes,calc,quotes,positioning}
在序言中而不是部分使用test_pic.tikz
,或者根本不使用,您将.tikz
在主文件的第 15 行中看到第 11 行的先前错误,指向原因! Package tikzscale Error: Requested to scale unscalable graphic.
\documentclass{article}
\usepackage{tikz}
\usepackage{tikzscale}
%\usetikzlibrary{shapes,calc,quotes,positioning}
\begin{document}
\centering
\input{test_pic.tikz} %Works (remove \usetikzlibrary{shapes,calc,quotes,positioning})
% \begin{figure}[htpb]%Does not work
% \centering
% \includegraphics[width=.9\linewidth]{test_pic.tikz}% line #15 <<<<<<<<<<<<<<
% \end{figure}
\begin{figure}[htpb]%Does work <<<<<<<<<<<<<<<<
\centering
\includegraphics{test_pic.tikz}
\end{figure}
\end{document}