我試圖在 tikz/pgf 繪圖中包含背景圖像。我需要能夠直接在影像的某些特徵上繪製節點,因此需要精確調整。
如果我能以某種方式將其修復到定義圖像角的兩個節點,這將是最簡單的,如下所示:
\documentclass{article}
\usepackage{pgf,tikz}
\begin{document}
\begin{tikzpicture}
\node at (0,0) {a};
\includegraphics{something.png}
\node at (2,2) {b};
\end{tikzpicture}
\end{document}
當然,這並不能達到我想要的效果,即縮放影像,使其右上角位於 (2,2) 且左下角位於 (0,0):
答案1
@percusse 的評論讓我找到了正確的答案。它涉及使用範圍環境。
以下程式碼摘自@Caramdir的回答使用 TikZ 在圖像上繪圖:
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=0.9\textwidth]{some_image.jpg}};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
\draw[red,ultra thick,rounded corners] (0.62,0.65) rectangle (0.78,0.75);
\end{scope}
\end{tikzpicture}
\end{document}