实际上,我只是想将文档中的图形复制到另一个模板(mdpi 模板https://www.overleaf.com/latex/templates/mdpi-article-template/fcpwsspfzsph)我知道这个模板存在很大问题。
简化的部分我抄袭了:
\begin{figure}[ht]
\begin{tikzpicture}
\begin{scope}[ x={(image.south east)},y={(image.north west)}]
\node at (0.5,0.5) { \includegraphics[width=1\columnwidth]{figures/figure.png}};
%% HERE WILL BE SOME NOTATIONS/ETC (I USE THE COORDINATE SYSTEM TO DRAW THEM ON TOP OF THE IMAGE)
%% AND GRID that are commented
% \draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
% \draw[help lines,xstep=.05,ystep=.05] (0,0) grid (1,1);
% \foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
% \foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y};}
\end{scope}
\end{tikzpicture}
\caption{Test figure.}
\label{fig:figure1}
\end{figure}
当我尝试编译它时,我收到了一个相当意外的错误,即\begin{scope}[ x={(image.south east)},y={(image.north west)}]
对于Package pgf Error: "No shape named 'image' is known"
另一个模板来说,它运行完美。
可能存在什么问题?
提前感谢大家。谨致问候,
答案1
这与模板无关。答案很简单,就是少了一行:
\begin{figure}[ht]
\begin{tikzpicture}
\node[anchor=south west, inner sep=0] (image) at (0,0) {\includegraphics[width=0.8\columnwidth]{figures/figure1.png}};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
% \node at (0.5,0.5) { \includegraphics[width=1\columnwidth]{figures/figure1.png}};
%% HERE WILL BE SOME NOTATIONS/ETC (I USE THE COORDINATE SYSTEM TO DRAW THEM ON TOP OF THE IMAGE)
%% AND GRID that are commented
\draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
\draw[help lines,xstep=.05,ystep=.05] (0,0) grid (1,1);
\foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
\foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y};}
\end{scope}
\end{tikzpicture}
\caption{Test figure.}
\label{fig:figure1}
\end{figure}
感谢评论者。它之所以没有在另一个模板/环境中失败,是因为节点是全局定义的,并且image
使用了前一个实例的。