通过节点使用 fit 来适应盒子

通过节点使用 fit 来适应盒子

嗨,我尝试使用 fit 命令在节点周围创建一个框。但边缘节点应该只占框的一半。

\begin{tikzpicture}
    \node at (0,0) (CE1) {\includegraphics[height=3ex]{Bilder/Router.png}}; 
    \node at (2,0) (PE1) {\includegraphics[height=3ex]{Bilder/Router.png}}; 
    \node at (4,0) (P1) {\includegraphics[height=3ex]{Bilder/Router.png}};  
    \node at (6,0) (P2) {\includegraphics[height=3ex]{Bilder/Router.png}};  
    \node at (5,-2) (P3) {\includegraphics[height=3ex]{Bilder/Router.png}}; 
    \node at (8,0) (PE2) {\includegraphics[height=3ex]{Bilder/Router.png}}; 
    \node at (10,0) (CE2) {\includegraphics[height=3ex]{Bilder/Router.png}};    
    \node at (5,-3)(LDP)[scale=0.6, text=black] {directed LDP}; 
    \node (test)[fill=lightgrey , rounded corners, fit= (PE1.mid) (P1) (P2) (P3.south) (PE2.mid)] {};
 \end{tikzpicture}

当使用 PE1.mid 时,盒子并没有准确穿过 PE1 的中间,而是向左偏移。有没有办法准确穿过节点的中间?

谢谢你的帮助

斯特芬

答案1

我认为您正在寻找inner {x|y}sep=0pt。根据您的需要进行调整。以下代码使用inner xsep=0pt,结果是:

在此处输入图片描述

\documentclass[tikz,border=2mm]{standalone}

\usetikzlibrary{fit}

\begin{document}

\begin{tikzpicture}
    \node at (0,0) (CE1) {\includegraphics[height=3ex]{example-image-a}}; 
    \node at (2,0) (PE1) {\includegraphics[height=3ex]{example-image-b}}; 
    \node at (4,0) (P1) {\includegraphics[height=3ex]{example-image-c}};  
    \node at (6,0) (P2) {\includegraphics[height=3ex]{example-image-a}};  
    \node at (5,-2) (P3) {\includegraphics[height=3ex]{example-image-b}}; 
    \node at (8,0) (PE2) {\includegraphics[height=3ex]{example-image-c}}; 
    \node at (10,0) (CE2) {\includegraphics[height=3ex]{example-image-a}};    
    \node at (5,-3)(LDP)[scale=0.6, text=black] {directed LDP}; 

    \node (test)[draw, rounded corners, 
         fit= (PE1.mid) (P1) (P2) (P3.south) (PE2.mid), 
         inner xsep=0pt] {};
 \end{tikzpicture}

 \end{document}

相关内容