我在 tikzpicture 环境中使用 TikZ 节点来实现所有子图的放置。在附图中,可以看到第二行的总水平宽度超过了第一行。第三行也是如此。
怎样才能使图形右外侧的所有垂直边框完全对齐?
附件是我当前的工作示例。
\documentclass[tikz]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{amsmath}
\usetikzlibrary{pgfplots.groupplots}
\usetikzlibrary{positioning,fit,calc}
\begin{document}
\newlength{\mywidth}
\settowidth{\mywidth}{\includegraphics[scale=1]{example-image-a}}
\newlength{\myheight}
\settoheight{\myheight}{\includegraphics[scale=1]{example-image-a}}
\begin{tikzpicture}
\node [draw,rectangle,ultra thick] (mge) {\includegraphics[width=\mywidth]{example-image-a}};
\node[draw,rectangle,ultra thick,right = 0pt of mge.east,anchor=west] (maj) {\includegraphics[height=\myheight]{example-grid-100x100pt}};
%%%%%%%%%%%%%%%%%%%
\path let \p{1}=(mge.west),\p{2}=(maj.east),\n{x dist}={0.50*abs(\x{2}-\x{1}-\the\pgflinewidth)} in
node[draw,rectangle,ultra thick,below = 0pt of mge.south west, anchor=north west] (loess) {\includegraphics[width=\n{x dist}]{example-image-b}};
\path let \p{1}=(mge.west),\p{2}=(maj.east),\n{x dist}={0.50*abs(\x{2}-\x{1}-\the\pgflinewidth)},\p3=(loess.south),\p4=(loess.north),\n{y dist}={abs(\y{4}-\y{3}-2*\pgflinewidth)} in
node[draw,rectangle,ultra thick,right= 0pt of loess.east, anchor=west,minimum height=\n{y dist}] (masses) {\includegraphics[width=\n{x dist}]{example-image-c}};
%%%%%%%%%%%%%%%%%%%
\path let \p{1}=(mge.west),\p{2}=(maj.east),\n{x dist}={abs(\x{2}-\x{1}-\the\pgflinewidth)} in
node[draw,rectangle,ultra thick,below = 0pt of loess.south west,anchor=north west] (chi2) {\includegraphics[width={\n{x dist}}]{example-image-golden}};
\node[above=0pt of mge.north west,anchor=south west]{\Huge{ESO349-010}};
\end{tikzpicture}
\end{document}
答案1
下面的代码似乎工作正常。基本上你只需要考虑ultra thick
线宽和inner sep
节点,正如我在评论中提到的那样。更详细地说:
从前两幅图的左到右移动,占据水平空间的元素是
(lw)(is)(img1)(is)(lw)(lw)(is)(img2)(is)(lw)
或者
4×lw + 4×is + (img1 + img2)
其中lw
是线的线宽ultra thick
,是节点的is
默认值,是图像的宽度。锚点位于绘制线的外边框上,因此在您的代码中 是所有这些元素的总和。inner sep
img
\x{2}-\x{1}
几乎。是inner sep
节点内容到周围路径的距离,边框node
绘制在此路径的中间。这意味着线宽的一半延伸到 定义的区域inner sep
。以下示例显示了这一点:
\documentclass[tikz,border=3pt]{standalone}
\begin{document}
\begin{tikzpicture}
\node [line width=4pt,inner sep=0pt,draw=blue,draw opacity=0.5] (a) {text};
\fill[red] (a.west) circle[radius=0.5pt];
\end{tikzpicture}
\end{document}
这意味着你的两张图片的宽度变成
\x{2} - \x{1} = 2×lw + 4×is + (img1 + img2)
因此,第二行两个图像的宽度变为
0.5×[\x{2} - \x{1} - (2×lw + 4×is)]
线的宽度ultra thick
在手册中给出为1.6pt
,默认inner sep
值为0.333em
。
次要评论:\Huge
不是接受参数的命令,应该是{\Huge text}
,而不是\Huge{text}
。在节点中不需要括号对。
\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{positioning,calc}
\begin{document}
\begin{tikzpicture}
\newlength{\mywidth}
\settowidth{\mywidth}{\includegraphics[scale=1]{example-image-a}}
\newlength{\myheight}
\settoheight{\myheight}{\includegraphics[scale=1]{example-image-a}}
\node [draw,rectangle,ultra thick] (mge) {\includegraphics[width=\mywidth]{example-image-a}};
\node[draw,rectangle,ultra thick,right = 0pt of mge.east,anchor=west] (maj) {\includegraphics[height=\myheight]{example-grid-100x100pt}};
%%%%%%%%%%%%%%%%%%%
% 1.6pt: width of an ultra thick line
% 0.333em: default inner sep of nodes
\path let
\p{1}=(mge.west),
\p{2}=(maj.east),
\n{x dist}={0.50*(\x{2}-\x{1})-1.6pt - 2*0.333em}
in
node[draw,rectangle,ultra thick,below = 0pt of mge.south west, anchor=north west] (loess) {\includegraphics[width=\n{x dist}]{example-image-b}}
node[draw,rectangle,ultra thick,below=0pt of maj.south east, anchor= north east] (masses) {\includegraphics[width=\n{x dist}]{example-image-c}};
%%%%%%%%%%%%%%%%%%%
\path let
\p{1}=(mge.west),
\p{2}=(maj.east),
\n{x dist}={\x{2}-\x{1}-1.6pt-2*0.333em}
in
node[draw,rectangle,ultra thick,below = 0pt of loess.south west,anchor=north west] (chi2) {\includegraphics[width={\n{x dist}}]{example-image-golden}};
\node[above=0pt of mge.north west,anchor=south west]{\Huge ESO349-010};
\end{tikzpicture}
\end{document}