输入
\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}
输出
问题
如何自动在叠加的 TikZ 图片周围添加间距,以使其内容不会覆盖周围的文本?
答案1
我会把你画成纯钛的样子钾Z 图片并将其封闭在center
环境中。图片中未使用导致问题的remember picture
选项overlay
。相比之下,您的解决方案tcolorbox
代码更简单、更清晰、更简短:
(红线为文字边框)
\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}