用图片剪辑两个节点

用图片剪辑两个节点

我想剪辑两个包含两张带圆角的图片的节点。

这是我的最小工作示例:

\documentclass[margin=1cm]{standalone}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\usetikzlibrary{positioning, fit}


\node[rounded corners, inner sep=0mm, outer sep=0mm, anchor=north west, text width=3cm] (image_a) at (0,0) {\includegraphics[width=3cm]{example-image-a}};
\node[inner sep=0mm, outer sep=0mm, anchor=north west, text width=3cm, below=0cm of image_a] (image_b) {\includegraphics[width=3cm]{example-image-b}};

\clip[rounded corners]  node [inner sep=0mm, outer sep=0mm, draw=red, rounded corners=2mm, fit={(image_a) (image_b)}] (image) {};
\end{tikzpicture}

\end{document}

不幸的是,它没有正确地剪切圆角:

在此处输入图片描述

当然,我不能不剪辑图像,因为这会在两幅图像之间产生圆角。

我怎样才能在红线处正确裁剪两个节点中的图像?

答案1

clipping使用以下选项的可能解决方案path picture

\documentclass[margin=1cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{positioning, fit}
\usepackage{tcolorbox}


\begin{document}

\begin{tikzpicture}

\path [path picture={\node at (path picture bounding box.center) {\includegraphics [width=4cm]{example-image-a}};}] (0,0)[rounded corners]|- ++(1.5,2.2)-|++(1.5,-0.75)[sharp corners]|-cycle;
\path [path picture={\node at (path picture bounding box.center) {\includegraphics [width=4cm]{example-image-b}};}]  (0,0)[rounded corners]|- ++(1.5,-2.2)-|++(1.5,0.75)[sharp corners]|-cycle;
\draw [rounded corners] (0,2.2) rectangle (3,-2.2);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容