我正在尝试在 tikz 图像上绘图。当我添加箭头时,图片会向右移出框架。如您所见,我是 Latex 新手。我找不到合适的解决方案,也无法根据自己的需要调整找到的解决方案。对此有什么想法吗?
这是我的代码:
\documentclass{article}
\usepackage{graphicx}
\usepackage{rotating}
\usepackage{subfigure}
\usepackage{tikz}
\usepackage{tikz-imagelabels}
\usepackage{caption}
\usetikzlibrary{arrows,snakes,backgrounds}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}\node[anchor=south west,inner sep=0] (image) at (0,0){\includegraphics[width=18cm]{filename}};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
\draw[help lines,xstep=.1,ystep=.1] (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}; }
%
\draw [thick, ->] (-0.05, 0.57) -- (0.07, 0.57);
\filldraw [thick] (-0.18, 0.57) node[anchor=west] {Kühlkanäle};
%
\draw [thick, ->] (-0.05, 0.8) -- (0.2, 0.63);
\filldraw [thick] (-0.25, 0.8) node[anchor=west] {Stirnseitiger Reibring};
%
\draw [thick, ->] (-0.05, 0.4) -- (0.2, 0.4);
\filldraw [thick] (-0.25, 0.8) node[anchor=west] {Stirnseitiger Reibring};
\end{scope}
\end{tikzpicture}
\end{figure}
\end{document}
答案1
之所以发生偏移tikzpicture
,是因为 tikz 根据图片中提到的所有坐标计算边界框。这包括从图像中突出的标签。
包括以下行
\useasboundingbox (image.south east) rectangle (image.north west);
定义节点后image
。这告诉 tikz 使用此矩形作为边界框,而不是计算框本身。
答案2
18cm 对于图像来说有点大。但除此之外:您可以使用带覆盖的示波器:
\documentclass{article}
\usepackage{graphicx}
\usepackage{rotating}
\usepackage{subfigure}
\usepackage{tikz}
\usepackage{tikz-imagelabels}
\usepackage{caption}
\usetikzlibrary{arrows,snakes,backgrounds}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}\node[anchor=south west,inner sep=0] (image) at (0,0){\includegraphics[width=18cm]{example-image}};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
\draw[help lines,xstep=.1,ystep=.1] (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}; }
\begin{scope}[overlay] %<----
\draw [thick, ->] (-0.05, 0.57) -- (0.07, 0.57);
\filldraw [thick] (-0.18, 0.57) node[anchor=west] {Kühlkanäle};
%
\draw [thick, ->] (-0.05, 0.8) -- (0.2, 0.63);
\filldraw [thick] (-0.25, 0.8) node[anchor=west] {Stirnseitiger Reibring};
%
\draw [thick, ->] (-0.05, 0.4) -- (0.2, 0.4);
\filldraw [thick] (-0.25, 0.8) node[anchor=west] {Stirnseitiger Reibring};
\end{scope} %<--------
\end{scope}
\end{tikzpicture}
\end{figure}
\end{document}