2

I'm new to tikz. I'm trying to create something like this: enter image description here

The two tcolorboxes work fine outside of being nodes. After googling and reading tikz documentation, I'm still at a loss for how to draw an arrow! Here's my MWE that is sad and needs smarts beyond my capacity at this moment.

\documentclass[12pt,fleqn,twoside]{report}
\usepackage{tcolorbox}
\usepackage{tikz}

\tcbset{%
    boxrule=4pt, 
    colback=white, %background color
    colframe=blue, % frame colour
    halign=center,
    valign=center, 
    halign lower=center,
    align lower =center,
    sharp corners=all,
    center title,
    lower separated=false,
    fonttitle=\sffamily\bfseries\large,
    }

\begin{document}

\begin{tikzpicture}[node distance=2cm,baseline=-0.5ex,  arrow/.style = {thick,-stealth}]
    \node(NodeName1){
        \begin{tcolorbox}[title=Box1Title]
        Blah box1 text
        \end{tcolorbox}
    };
\node(NodeName2){
    \begin{tcolorbox}[title=Box2Title]
        Blah box2 text
        \end{tcolorbox}
        };
\draw(NodeName1);   
\draw[->] (NodeName1) -- (NodeName2);
\draw(NodeName2);
\end{tikzpicture}

\end{document}

2 Answers 2

2

arrow is not the problem (actually it appears), but your nodes overlaps (are not displaced one against other) and consequently its length is zero pt. also you have errors in your code (undefined options) and since width of boxes are not defined, it use default width, e.g. text width ...

\documentclass[12pt,fleqn,twoside]{report}
\usepackage[many]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, % for arrows style
                positioning  % for positioning of boxes
               }
\tcbset{%
    boxrule=4pt,
    colback=white, % background color
    colframe=cyan, % frame colour
        halign=center,
        valign=center,
    sharp corners=all,
    center title,
    lower separated=false,
    fonttitle=\sffamily\bfseries\large,
    width=4cm % added
    }
% for show only picture
\usepackage[tightpage, active]{preview}
\setlength\PreviewBorder{3mm}
\PreviewEnvironment{tikzpicture}

    \begin{document}
\begin{tikzpicture}[node distance=2cm]
    \node(NodeName1){
        \begin{tcolorbox}[title=Box 1 Title]
        Box 1 text
        \end{tcolorbox}
    };
\node(NodeName2) [right=of NodeName1] {  % added position of second box
    \begin{tcolorbox}[title=Box 2 Title]
        Box 2 longer text text text text text
        \end{tcolorbox}
        };
\draw[blue, line width=2mm,-{Triangle[angle=60:1pt 3]}] (NodeName1) -- (NodeName2);
\end{tikzpicture}
    \end{document}

see if obtained image is what you looking for:

enter image description here

edit: code and explanation is slightly improved

0
4

You don't have to included your tcolorboxes as tikznodes inside a tikzpicture for drawing arrows between them. In fact a tcolorbox is more or less a tikzpicture.

With enhanced tcolorboxes, you can use remember as= ... option to assign a name to each box and use these names for reference in a tikzpicture. This is what is shown in following example.

enhanced options has bee added to tcbset declaration (load tcolorbox with most option). Then a nobeforeafter option has been used in each box to keep them on the same line and remember as option for naming them.

An external picture has been used to draw the arrow between these boxes:

\documentclass[12pt,fleqn,twoside]{report}
\usepackage[most]{tcolorbox}
\usepackage{tikz}

\tcbset{%
    enhanced,
    boxrule=4pt, 
    colback=white, %background color
    colframe=blue, % frame colour
    halign=center,
    valign=center, 
    halign lower=center,
    valign lower =center,
    sharp corners=all,
    center title,
    lower separated=false,
    fonttitle=\sffamily\bfseries\large,
    }

\begin{document}

\begin{tcolorbox}[title=Box1Title, width=.4\linewidth, nobeforeafter, remember as=NodeName1]
        Blah box1 text
\end{tcolorbox}
\hfill
\begin{tcolorbox}[title=Box2Title, width=.4\linewidth, nobeforeafter, remember as=NodeName2]
        Blah box2 text
\end{tcolorbox}

\tikz[overlay, remember picture] \draw[->, line width=4pt, blue] (NodeName1)--(NodeName2);

\end{document}

enter image description here

3
  • Thank you @Ignasi. You gave me alternate solution that I can use elsewhere. I understand tikz more by looking at your response.
    – PepPaddy
    Commented Sep 13, 2017 at 18:18
  • NOTE: #2 (above #3) solution shows two boxes with unequal amounts of text in each box. However, the box with more text (the right-most box) is centered with respect to the box with less text (the left-most box). When I add more text to Box2 in this example, the two boxes are no longer centered. This may or may not be important to you.
    – Wayne
    Commented Jul 28, 2020 at 13:10
  • @Wayne. Adding option ` box align=center` you get centered boxes.
    – Ignasi
    Commented Jul 28, 2020 at 14:48

You must log in to answer this question.

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