我有一大堆显微镜图像要包含在报告中,其中一些图像包含我想要裁剪的无趣信息。由于我使用 TikZ 添加比例尺,因此需要精确知道所有图像尺寸,因此我使用 TikZ 来裁剪图像。
事实上,这会导致子图略微歪斜,见附图。我注意到,对于显示两个或多个不同体积的子图的图形,也存在同样的行为。
以下是代码:
\documentclass{memoir}
\usepackage{mwe}
\usepackage{siunitx}
\usepackage{graphicx}
\usepackage{tikz}
\newsubfloat{figure}
\begin{document}
\begin{figure}
\subbottom[]{
\tikz{
\draw (0,0) node[name=micrograph]{\includegraphics[width=.45\textwidth]{example-image}};
\draw[ultra thick, white] (micrograph.south west)++(0.05*0.45\textwidth,0.05*0.45\textwidth)--++(0.45*0.54177\textwidth,0)node[above,white,midway]{100 \si{\micro\meter}};}
}
\subbottom[]{
\tikz{
\clip (0,0)++(-.3\textwidth,-.3\textwidth) rectangle ++(.45\textwidth,.45\textwidth);
\draw (0,0) node[name=micrograph]{\includegraphics[width=.6\textwidth]{example-image}};
\draw[ultra thick, white] (micrograph.south west)++(0.05*0.5\textwidth,0.05*0.5\textwidth)--++(0.5*0.25806\textwidth,0)node[above,white,midway]{100 \si{\micro\meter}};}
}
\end{figure}
\end{document}
我如何确保两幅图像最终对齐?
答案1
问题在于您指定的剪辑矩形,它从-.3\textwidth
以下单位开始(0,0)
。
如果在每个 tikz 图片周围放置一个\fbox
,就可以很容易地检测到这一点,以显示图片的实际扩展:
\begin{figure}
\subbottom[]{
\fbox{\tikz{
\draw (0,0) node[name=micrograph]{\includegraphics[width=.45\textwidth]{example-image}};
\draw[ultra thick, white] (micrograph.south west)++(0.05*0.45\textwidth,0.05*0.45\textwidth)--++(0.45*0.54177\textwidth, 0)node[above,white,midway]{100 \si{\micro\meter}};}
}}
\subbottom[]{
\fbox{\tikz{
\clip[use as bounding box] (0,0)++(-.3\textwidth,-.3\textwidth) rectangle ++(.45\textwidth,.45\textwidth);
\draw (0,0) node[inner sep=0pt,name=micrograph]{\includegraphics[width=.6\textwidth]{example-image}};
\draw[ultra thick, white] (micrograph.south west)++(0.05*0.5\textwidth,0.05*0.5\textwidth)--++(0.5*0.25806\textwidth, 0)node[above,white,midway]{100 \si{\micro\meter}};}
}}
\end{figure}
我不确定你期望的结果。这是另一个示例,其中第二个图形被大大放大,稍微旋转,并任意裁剪到“感兴趣区域”。在这种情况下,裁剪矩形没有负原点,因此不会出现不需要的空白:
\begin{figure}
\subbottom[]{
\fbox{\tikz{
\draw (0,0) node[name=micrograph]{\includegraphics[width=.45\textwidth]{example-image}};
\draw[ultra thick, white] (micrograph.south west)++(0.05*0.45\textwidth,0.05*0.45\textwidth)--++(0.45*0.54177\textwidth, 0)node[above,white,midway]{100 \si{\micro\meter}};}
}}
\subbottom[]{
\fbox{\tikz{
\clip[use as bounding box] (0,0)++(.01\textwidth,.01\textwidth) rectangle ++(.45\textwidth,.45\textwidth);
\draw (0,0) node[inner sep=0pt,name=micrograph]{\includegraphics[angle=10,width=1.6\textwidth]{example-image}};
\draw[ultra thick, white] (micrograph.south west)++(0.05*0.5\textwidth,0.05*0.5\textwidth)--++(0.5*0.25806\textwidth, 0)node[above,white,midway]{100 \si{\micro\meter}};}
}}
\end{figure}