嗨。我想在 LaTex 中创建此图形,而不是像以前那样(将两个图像放入 powerpoint 并添加文本框,将所有内容保存为 tiff 文件,然后转换为 eps 文件)才能在 LaTex 中使用。当前版本有点模糊,尤其是在文本框中。
为了清晰起见,我将 2 幅图像作为 eps 文件(和 matlab 图形)。我想将缩放后的图像叠加在未缩放图像的右象限上。我想添加箭头或黑线来标示缩放。
我尝试使用 TIKZ,但不知道如何复制该图像。
有什么想法吗?
谢谢!!
答案1
在我看来,准备两张图像并不理想:如果您想更改放大的区域,您必须在其他程序中准备单独的图像,仔细计算所需的裁剪。
TikZ 的强大功能可以通过spy
库为您完成此操作。然后,在间谍范围之外,可以添加注释,使用间谍节点名称来帮助定位它们。放大的图像在这里看起来像素化,但如果您的基础图像具有足够的分辨率,这将不是问题。
\documentclass[tikz]{standalone}
\usetikzlibrary{spy}
\tikzset{annot/.style={draw=black,fill=white,text=black}}
\begin{document}
\begin{tikzpicture}
\begin{scope}[spy using outlines={rectangle,magnification=3,connect spies,size=1.5cm}]
\node[inner sep=0,outer sep=0,anchor=south west] (image) at (0,0)
{\includegraphics[width=5cm]{example-image-a}};
\spy on (2.125,1.57) in node (zoom) at (4,2.75);
\end{scope}
\draw[blue] (zoom.south west) ++(0.4,0.2) -- ++(0.2,-0.8) node[annot,below] {Black};
\draw[blue] (zoom.north west) ++(0.25,-0.2) -- ++(-1,-0.1) node[annot,left] {Grey};
\end{tikzpicture}
\end{document}
该库拥有丰富的选项,可让您按照自己喜欢的方式设置插图样式。请查看第 68 节手册pgf
了解全部细节。:-)
答案2
这是一种可能性。当然,显示的网格线仅用于绘图阶段,在该阶段您要确定放置第二幅图像、方框和箭头所需的坐标。
\documentclass[tikz,border=5pt]{standalone}
\usepackage{graphicx}
\begin{document}
\begin{tikzpicture}
% http://tex.stackexchange.com/a/9561/ - Caramdir
\node (img1) [anchor=south west, inner sep=0pt] at (0,0) {\includegraphics{example-image-a}};
\begin{scope} [x={(img1.south east)}, y={(img1.north west)}]
% http://tex.stackexchange.com/a/9562/ - jake
\draw [help lines, step=.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 [red, thick] (.7,.3) rectangle +(.1,.1);
\node (img2) [anchor=north west, inner sep=0pt] at (.9,.2) {\includegraphics{example-image-b}};
\draw [ultra thick, ->] (.8,.3) -- (img2.north west);
\end{scope}
\end{tikzpicture}
\end{document}
要在叠加的图像上添加注释,可以使用相同技巧的变体:
\begin{scope}[shift=(img2.south west), x={(img2.south east)}, y={(img2.north west)}]
\draw [help lines, step=.1] (0,0) grid (1,1);
\foreach \x in {0,1,...,9} {
\node [anchor=north] at (\x/10,0) {0.\x};
\node [anchor=east] at (0,\x/10) {0.\x};
}
\node at (.7,.8) [anchor=north west, fill=white, align=center] {Here is an\\annotation};
\end{scope}
再次强调,网格线只是为了在施工期间提供帮助。
完整代码:
\documentclass[tikz,border=5pt]{standalone}
\usepackage{graphicx}
\begin{document}
\begin{tikzpicture}
% http://tex.stackexchange.com/a/9561/ - Caramdir
\node (img1) [anchor=south west, inner sep=0pt] at (0,0) {\includegraphics{example-image-a}};
\begin{scope} [x={(img1.south east)}, y={(img1.north west)}]
% http://tex.stackexchange.com/a/9562/ - jake
\draw [help lines, step=.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 [red, thick] (.7,.3) rectangle +(.1,.1);
\node (img2) [anchor=north west, inner sep=0pt] at (.9,.2) {\includegraphics{example-image-b}};
\draw [ultra thick, ->] (.8,.3) -- (img2.north west);
\end{scope}
\begin{scope}[shift=(img2.south west), x={(img2.south east)}, y={(img2.north west)}]
\draw [help lines, step=.1] (0,0) grid (1,1);
\foreach \x in {0,1,...,9} {
\node [anchor=north] at (\x/10,0) {0.\x};
\node [anchor=east] at (0,\x/10) {0.\x};
}
\node at (.7,.8) [anchor=north west, fill=white, align=center] {Here is an\\annotation};
\end{scope}
\end{tikzpicture}
\end{document}