3

Hey I have this tikz picture:

\begin{tikzpicture}
  \tikzstyle{interface} = [draw,regular polygon,regular polygon sides=8];
  \node[draw] (ec) {Erasure correction};
  \node[interface, below of=ec] (eci) {Erasure Correction Interface};
\end{tikzpicture}

And the result is: enter image description here

I would like to fit the polygon to the text, such that is has a similar size to that of the standard node. How can I do that ?

  • AFAIK, this is not possible since your polygon fits the circle which diameter is your text (plus inner sep). – NBur Sep 13 '18 at 8:41
  • damn it. Do you have an alternative solution ? – Lars Nielsen Sep 13 '18 at 9:44
  • 2
    Add a negative inner sep=-5mm to reduce the margin between contents and border – Ignasi Sep 13 '18 at 10:08
  • 1
    I'd use \node[draw, rectangle, rounded corners, below of=ec] (eci) {Erasure Correction Interface}; – NBur Sep 13 '18 at 10:35
6

It is rather easy to do with the calc library.

\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}

enter image description here

You might use some standard values for the gap as well. In the end it depends on what you precisely want to achieve. There are a number of standard distances at play, once I know better what the goal is I may be able to adjust the following to your needs.

\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}

enter image description here

UPDATE: As for the clarified question: it is rather easy to cook up something along those lines using path picture. I did not know, however, what determines the sizes of the cut corners. So I choose inner sep since that way the boundary won't run into the text.

\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}

enter image description here

It is of course possible to tie the dimensions of the cut corners to other length scales, which one may introduce just for that purpose. However, before showing too many options I'd like to know where the journey is supposed to go, i.e. I need clearer instructions.

  • 1
    @LarsNielsen If you tell me what distance you want, I'll be happy to give it a shot. And if the answer is what you are after, could you perhaps consider accepting it? – user121799 Sep 14 '18 at 11:47
  • I would basically like the two horizontal sides to have the same distance as the the vertical once. and sorry for long response time. I have had an issue with my stackexchange account – Lars Nielsen Sep 20 '18 at 6:33
  • 1
    @LarsNielsen But then this will no longer be a regular polygon. Or am I missing something? So you want not to have a regular polygon but just a rectangle with cut corners? – user121799 Sep 20 '18 at 6:53
  • no it will not be a regular polygon, so you missed nothing :) – Lars Nielsen Sep 20 '18 at 7:44
  • @LarsNielsen I added a proposal how to do that. – user121799 Sep 20 '18 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.