在 tikzpicture 中对齐 2 个不同尺寸的图像

在 tikzpicture 中对齐 2 个不同尺寸的图像
\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}

\usepackage{tikz}
\usetikzlibrary{positioning, calc}

\begin{document}

\begin{tikzpicture}[on grid]
\node[inner sep=0pt] (imga) at (0, 0)
    {\includegraphics[width=.35\textwidth]{example-image-a}};

\node[right = 10 of imga, inner sep=0pt] (imgb)
    {\includegraphics[width=.25\textwidth]{example-image-b}};

\node[below = 5 of imga, inner sep=0pt] (imgc)
    {\includegraphics[width=.25\textwidth]{example-image-c}};

\node[below = 5 of imgb, inner sep=0pt] (imge)
    {\includegraphics[width=.25\textwidth]{example-image}};

\node[inner sep=0pt] (imgd) at ($(imgc)!0.5!(imge)$)
    {\includegraphics[width=.25\textwidth]{example-image}};

\end{tikzpicture}

\end{document}

代码画出来tikzpicture如下:

在此处输入图片描述

图像 A 和图像 C 的尺寸不同。有没有办法水平对齐图像 A 和图像 C,以便 A 的左边距和 B 的左边距在同一行?

希望[on grid]不需要改变,因为我依赖它来进行其他节点的定位。

答案1

将锚点设为西,并使节点距离也设为西:

\node[below = 5 of imga.west, anchor=west] (imgc)
    {\includegraphics[width=.25\textwidth]{example-image-c}};
\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc,
                positioning}

\begin{document}
\begin{tikzpicture}[every node/.style ={inner sep=0pt},
                    on grid]
\node (imga) {\includegraphics[width=.35\textwidth]{example-image-a}};
\node[right = 10 of imga] (imgb)
    {\includegraphics[width=.25\textwidth]{example-image-b}};

\node[below = 5 of imga.west, anchor=west] (imgc)
    {\includegraphics[width=.25\textwidth]{example-image-c}};  % <---
\node[below = 5 of imgb, inner sep=0pt] (imge)
    {\includegraphics[width=.25\textwidth]{example-image}};
\node[inner sep=0pt] (imgd) at ($(imgc)!0.5!(imge)$)
    {\includegraphics[width=.25\textwidth]{example-image}};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容