1

Input

\documentclass[version=last,paper=A4,parskip=half]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mlmodern}
\usepackage[american]{babel}
\usepackage[final,babel]{microtype}

\usepackage{lipsum}

\usepackage{tikz}
\usepackage{tcolorbox}

\usetikzlibrary{arrows.meta,calc,fit}
\tcbuselibrary{most}

\begin{document}
\lipsum[1-1]

{%
  \tcbset{%
    enhanced,%
    size=fbox,%
    on line,%
    box align=center,%
    fonttitle=\small,%
    fontupper=\small,%
    fontlower=\small,%
    halign title=center,%
    halign upper=center,%
    halign lower=center,%
  }%
  \begin{tcolorbox}[title=Microservices,remember as=JSON,width=.2\linewidth]
    JSON events\tcblower{}Kafka
  \end{tcolorbox}%
  \hfill%
  \begin{tcolorbox}[title=Databricks,remember as=Spark,width=.2\linewidth]
    Spark\tcblower{}EC2 \& EBS
  \end{tcolorbox}%
  \hfill%
  \begin{minipage}{.2\linewidth}
    \begin{tcolorbox}[remember as=Oracle]
      Oracle
    \end{tcolorbox}%
    \\%
    \begin{tcolorbox}[remember as=Delta]
      Delta Lake\tcblower{}S3
    \end{tcolorbox}
  \end{minipage}%
  \hfill%
  \begin{minipage}{.15\linewidth}
    \begin{tcolorbox}[remember as=Exasol]
      Exasol
    \end{tcolorbox}%
    \\%
    \begin{tcolorbox}[remember as=Presto]
      Presto
    \end{tcolorbox}%
  \end{minipage}%
  \begin{tikzpicture}[%
    overlay,%
    remember picture,%
    >=Stealth,%
    shorten >=1pt,%
    shorten <=1pt,%
    surround/.style 2 args={%
      draw,%
      rectangle,%
      thick,%
      dotted,%
      fit=#1,%
      inner sep=8pt,%
      label={[align=center,scale=0.75]#2},%
    },%
    ]

    \coordinate (Spark-SSE)  at ($(Spark.south)!0.5!(Spark.south east)$);
    \coordinate (Spark-NNE)  at ($(Spark.north)!0.5!(Spark.north east)$);
    \coordinate (Delta-SSW)  at ($(Delta.south)!0.5!(Delta.south west)$);
    \coordinate (Exasol-NNW) at ($(Exasol.north)!0.5!(Exasol.north west)$);

    \path[->]
    (JSON)      edge                                       (Spark)
    (Spark)     edge                                       (Oracle)
    (Oracle)    edge                                       (Exasol)
    (Spark)     edge                                       (Delta)
    (Delta)     edge[<->]                                  (Presto)
    (Delta-SSW) edge[out=-150,in=-30]
                node[midway,below,scale=0.75] {SNS \& SQS} (Spark-SSE)
    (Spark-NNE) edge[out=30,in=150]                        (Exasol-NNW);

    \node[surround={(Spark)}{Airflow}]                          (Scheduling) {};
    \node[surround={(Exasol)(Presto)}{Superset\\MicroStrategy}] (Reporting)  {};
  \end{tikzpicture}%
}

\lipsum[2-2]
\end{document}

Output

Click to view output with no spacing around overlaid TikZ picture

Question

How can I automatically add spacing around the overlaid TikZ picture so that its contents do not go over the surrounding text?

4
  • May be vspace{} before and after the drawing Commented Sep 7, 2021 at 8:42
  • 2
    I'd do your example only with TikZ nodes. No tcolorboxes and not overlayed. I think that it'll be easier this way. Only an idea... Commented Sep 7, 2021 at 10:49
  • 1
    You have several alignment issues between your tcolorboxes. I think it would be better if done only in a single tikzpicture, rather that with an overlay on your tcboxes. Maybe could you nest your tcboxes into tikz nodes if you really want to use tcolorbox.
    – SebGlav
    Commented Sep 7, 2021 at 11:06
  • @SebGlav — what alignment issues exactly? I don’t think there are any. But you and Juan are probably right that I should look into doing everything with TikZ nodes.
    – d125q
    Commented Sep 7, 2021 at 11:29

1 Answer 1

2

I would draw you image as pure TikZ picture and enclose it in a center environment. In the picture are not used remember picture and overlay options, which cause your problem. In comparison to your solution with tcolorbox code is simpler, more clear and shorter:

enter image description here

(red lines are text borders)

\documentclass[version=last,paper=A4,parskip=half]{scrartcl}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%
\usepackage{lipsum}                             % for dummy text
%---------------------------------------------------------------%

\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                fit,
                positioning,
                quotes,
                shapes.multipart}

\begin{document}
\lipsum[11]

\begin{center}
  \begin{tikzpicture}[
  node distance = 1mm and 0.05\linewidth,
every edge/.append style = {draw, -Stealth},
every label/.append style = {align=center},
FIT/.style = {draw, densely dashed, rounded corners=2pt,
              fit=#1, node contents={} },
MPV/.style = {
        rectangle split parts=3, 
        shape=rectangle split, 
        rectangle split draw splits=false,
        rectangle split part fill={black, gray!30},
        draw, rounded corners=1pt,
        inner sep=1mm, text width=0.2\linewidth, align=center,
        },
  N/.style = {draw, rounded corners=1pt, fill=gray!30,
        text width=0.18\linewidth, align=center}
                        ]
\node (n1)  [MPV] {%
        \nodepart{one}   \textcolor{white}{\textbf{Microservices}}
        \nodepart{two}   JSOM events
        \nodepart{three} Kafka};
        \draw[dashed]   (n1.two split west) -- (n1.two split east);
\node (n2)  [MPV, right=of n1] {%
        \nodepart{one}   \textcolor{white}{\textbf{Databricks}}
        \nodepart{two}   Spark
        \nodepart{three} EC2 \& EBS};
        \draw[dashed]   (n2.two split west) -- (n2.two split east);
    \node[FIT=(n2)];
\node (n3a) [N, right=of n2.one east] 
        {Oracle};
\node (n3b) [N,below=of n3a] 
        {Exasol\\S3};
        \draw[dashed]   (n3b.west) -- (n3b.east);
\node (n4a) [N, right=of n3a.south east]
        {Oracle};
\node (n4b) [N, below=of n4a]
        {Presto};
        \draw[dashed]   (n3b.west) -- (n3b.east);
    \node[FIT=(n4a) (n4b), label={Superset\\MicroStrategy}];
% connections
\draw   (n1) edge (n2)
        (n2) edge (n3a)
        (n2) edge (n3b)
        (n3a)   edge    (n4a);
\draw[Stealth-Stealth]  (n4b)   edge    (n3b);
%
\draw   (n2.75)    edge[bend left] (n4a)
        (n3b)   edge[bend left=30,"SNS \& SQS"] (n2.285);
%
\draw[-Stealth] (n1) -- (n2);
   \end{tikzpicture}                 
\end{center}
\lipsum[12]
\end{document}
1
  • Thank you very much — I was not aware of rectangle split!
    – d125q
    Commented Sep 7, 2021 at 13:42

You must log in to answer this question.

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