答案1
使用 Caramdir 和 Jake 的答案来这个问题, 你可以这样做:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0)
{\includegraphics[width=0.5\textwidth]{mushroom}};
\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);
\draw[red,ultra thick] (0.78,0.7) -- (1.05,0.7)
node[draw,red,ultra thick,rounded corners,font=\footnotesize,,text
width=1.6cm,anchor=west]{This should be the text block};
\end{scope}
\end{tikzpicture}
\bigskip
Another way using \verb|node|s:
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0)
{\includegraphics[width=0.5\textwidth]{mushroom}};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
\node[draw,olive,minimum width=2.5cm,minimum height=1.4cm] (a) at (0.35,0.5) {};
\draw[olive] (a.west) -- +(-1cm,0cm)
node[draw,black,font=\footnotesize,,text
width=1.6cm,anchor=east]{This should be the text block};
\end{scope}
\end{tikzpicture}
\end{document}
答案2
谢谢你的例子。
这是我昨天做的代码:
\documentclass[a4paper, 11pt, oneside]{scrbook}
\usepackage{tikz,xcolor}
\definecolor{tadruby}{HTML}{8B0000}
\usepackage[left=2cm, right=1.5cm, top=1.5cm, bottom=1cm]{geometry}
\begin{document}
\begin{figure}[htb]
\centering
\begin{tikzpicture}
\node[anchor=south west, inner sep=0] (image) at (0,0) {\includegraphics[width=13cm]{Figures/mushroom.jpg}};
\draw[tadruby, very thick, rounded corners] (0, 8.05) rectangle (13, 7);
\node[draw=tadruby,text width=3cm] at (-2,7.5) {Test text};
\end{tikzpicture}
\end{figure}
\end{document}
但是现在我对你的代码进行了一些“玩弄”,想知道为什么范围内的单位从 0 开始到 1(从一个图形角到下一个图形角),而不是使用厘米单位?
答案3
Harish Kumar 的答案是解决向图形添加注释问题的出色而优雅的解决方案。因为原理是注释的坐标是图形宽度和高度的一小部分,所以我发现添加一个简单的网格来确定坐标很有用:
\documentclass[tikz,border=3mm]{standalone}
\newcommand{\mygrid}{%
\draw[white,thin,xstep=0.05,ystep=0.05] (0,0) grid (1,1);
\draw[white,thick,xstep=0.1,ystep=0.1] (0,0) grid (1,1);
}
\begin{document}
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) at (0,0)
{\includegraphics[width=0.5\textwidth]{mushroom}};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
\mygrid
\node[draw,red,minimum width=2.5cm,minimum height=1.4cm] (a) at (0.35,0.5) {};
\draw[olive] (a.west) -- +(-1cm,0cm)
node[draw,black,font=\footnotesize,,text
width=1.6cm,anchor=east]{This should be the text block};
\end{scope}
\end{tikzpicture}
\end{document}
\mygrid
完成后只需删除或注释掉即可。