![Tikz 适合多边形到文本](https://linux22.com/image/382635/Tikz%20%E9%80%82%E5%90%88%E5%A4%9A%E8%BE%B9%E5%BD%A2%E5%88%B0%E6%96%87%E6%9C%AC.png)
答案1
使用 calc 库来做这件事相当容易。
\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\usetikzlibrary{shapes.geometric,calc}
\begin{tikzpicture}
\tikzset{interface/.style={draw,regular polygon,regular polygon sides=8}}
\node[draw] (ec) {Erasure correction};
\node[below of=ec] (eci) {Erasure Correction Interface};
\path let \p1=($(eci.east)-(eci.west)$) in
node[interface,minimum width=\x1+5pt] at (eci){};
\end{tikzpicture}
\end{document}
您也可以使用一些标准值来表示间隙。最终这取决于您究竟想要实现什么。有许多标准距离在起作用,一旦我更好地了解目标是什么,我就可以根据您的需要调整以下内容。
\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\usetikzlibrary{shapes.geometric,calc}
\begin{tikzpicture}
\tikzset{interface/.style={draw,regular polygon,regular polygon sides=8}}
\node[draw] (ec) {Erasure correction};
\node[below of=ec] (eci) {Erasure Correction Interface};
\path let \p1=($(eci.east)-(eci.west)$) in
node[interface,minimum width=\x1+2*\pgfkeysvalueof{/pgf/inner
xsep}+2*\pgflinewidth] at (eci){};
\end{tikzpicture}
\end{document}
更新: 至于澄清的问题:使用 很容易做出类似这样的事情path picture
。但是,我不知道是什么决定了切角的大小。所以我选择inner sep
因为 这样边界就不会碰到文本。
\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\usetikzlibrary{shapes.geometric,calc,positioning}
\begin{tikzpicture}[]
\tikzset{interface/.style={draw,regular polygon,regular polygon sides=8},
my octagon/.style={path picture={
\draw
([yshift=\pgfkeysvalueof{/pgf/inner ysep},xshift=\pgflinewidth/2] path picture bounding box.south west)
--([yshift=-\pgfkeysvalueof{/pgf/inner xsep},xshift=\pgflinewidth/2] path picture bounding box.north west)
--([xshift=\pgfkeysvalueof{/pgf/inner xsep},yshift=-\pgflinewidth/2] path picture bounding box.north west)
--([xshift=-\pgfkeysvalueof{/pgf/inner xsep},yshift=-\pgflinewidth/2] path picture bounding box.north east)
--([yshift=-\pgfkeysvalueof{/pgf/inner ysep},xshift=-\pgflinewidth/2] path picture bounding box.north east)
--([yshift=\pgfkeysvalueof{/pgf/inner ysep},xshift=-\pgflinewidth/2] path picture bounding box.south east)
--([xshift=-\pgfkeysvalueof{/pgf/inner xsep},yshift=\pgflinewidth/2] path picture bounding box.south east)
--([xshift=\pgfkeysvalueof{/pgf/inner xsep},yshift=\pgflinewidth/2] path picture bounding box.south west)
--cycle;
}}}
\node[draw] (ec) {Erasure correction};
\node[below=3mm of ec,my octagon] (eci) {Erasure Correction Interface};
\node[below=3mm of eci,my octagon,inner sep=5mm] (ecf) {Erasure Correction Failure};
\end{tikzpicture}
\end{document}
当然,可以将切角的尺寸与其他长度尺度联系起来,人们可以为此目的引入这些尺度。然而,在展示太多选项之前,我想知道旅程应该去哪里,也就是说,我需要更清晰的指示。