1

I am trying to connect two inner tcolorboxes with a arrow. I have also seen this and this answer, unfortunately it was not helpful with my problem. A minimum example is below. I am grateful for any help. It should be noted that I would like to find a solution that does not require the manual setting of coordinates, since the target diagrams are complex. Each node has its own height, only the width of the nodes is constant enter image description here

\documentclass[tikz]{standalone}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}

\newtcolorbox{rosnode}[1]{
    colback=white!85!gray,
    colframe=gray,
    coltitle=white,
    boxrule=2pt,
    halign=center,
    valign=center,
    sharp corners=all,
    center title,
    % lower separated=false,
    width=5cm,
    title={#1}
}

\newtcolorbox{rosservice}[1]{
    colback=white!85!gray,
    colframe=gray,
    coltitle=white,
    boxrule=2pt,
    halign=center,
    valign=center,
    arc=0.4mm,
    center title,
    % lower separated=false,
    left skip=-0.3cm,
    right skip=-0.3cm,
    title={#1}
}

\begin{document}
\begin{tikzpicture}[node distance=1cm, every node/.style={inner sep=0,outer sep=0}]
    \node(Node1) {
        \begin{rosnode}{Node1}
            Box 1 longer text text text text text
            \begin{rosservice}{InnerBox1}
                Box text
            \end{rosservice}
        \end{rosnode}
    };
    \node(Node2) [right=of Node1] {
        \begin{rosnode}{Node2}
            Box 2 text 
            \begin{rosservice}{InnerBox2}
                Box text
            \end{rosservice}
        \end{rosnode}
    };
    \draw[gray,line width=0.8mm,-{Triangle[angle=60:1pt 3]}] (Node1) -- (Node2);
\end{tikzpicture}
\end{document}

1 Answer 1

3

Welcome to TeX.SX! I am unsure whether this complexity with placing tcolorboxes inside TikZ nodes is really needed, but I will keep your set up since I don't know what you want to achieve with this.

In order to refer to the outer frame of a tcolorbox using TikZ macros such as \draw, you can use the remember as option on the relevant tcolorbox. You also need to add the option enhanced for this tcolorbox. Having done this, you can refer to this box using a tikzpicture with the options remember picture, overlay.

See the following adjustments to your original code:

\documentclass{standalone}
\usepackage[most]{tcolorbox}
\usetikzlibrary{arrows.meta, positioning}

\newtcolorbox{rosnode}[1]{
    colback=white!85!gray,
    colframe=gray,
    coltitle=white,
    boxrule=2pt,
    halign=center,
    valign=center,
    sharp corners=all,
    center title,
    % lower separated=false,
    width=5cm,
    title={#1}
}

\newtcolorbox{rosservice}[2][]{
    enhanced,
    colback=white!85!gray,
    colframe=gray,
    coltitle=white,
    boxrule=2pt,
    halign=center,
    valign=center,
    arc=0.4mm,
    center title,
    % lower separated=false,
    left skip=-0.3cm,
    right skip=-0.3cm,
    title={#2},
    #1
}

\begin{document}

\begin{tikzpicture}[node distance=1cm, every node/.style={inner sep=0,outer sep=0}]
    \node(Node1) {
        \begin{rosnode}{Node1}
            Box 1 longer text text text text text
            \begin{rosservice}[remember as=InnerBox1]{InnerBox1}
                Box text
            \end{rosservice}
        \end{rosnode}
    };
    \node(Node2) [right=of Node1] {
        \begin{rosnode}{Node2}
            Box 2 text 
            \begin{rosservice}[remember as=InnerBox2]{InnerBox2}
                Box text
            \end{rosservice}
        \end{rosnode}
    };
\end{tikzpicture}

\begin{tikzpicture}[remember picture, overlay]
    \draw[gray, line width=0.8mm, -{Triangle[angle=60:1pt 3]}] (InnerBox1.east) -- (InnerBox2.west);
\end{tikzpicture}

\end{document}

enter image description here

In this case, it might be a good idea to change the color of the arrow to make it more visible.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .