0

I've been playing around with custom arcs, but I can't seem to figure out how to set the arc radius automatically. Goal is to create a node that bounds two semi-circles and gets wider as needed

Links to the desired image at at the end

https://i.stack.imgur.com/E4qag.jpg

\usepackage{xparse}
\NewDocumentCommand{\mynode}{%
O{}
m
m
m
O{}
}{
{
\node [#1] (#2)  at #3 {#4};

\def\ra{.3cm}

\draw  [#5]  (#2.north west) arc
    [
        start angle=90,
        end angle=270,
        x radius=\ra,
        y radius=\ra
    ] ;
    

\draw [#5] (#2.north east)to [in=0,out=180] (#2.north west);
\draw [#5] (#2.south east)to [in=0,out=180] (#2.south west);

\draw  [#5]  (#2.south east) arc
    [
        start angle=270,
        end angle=450,
        x radius=\ra,
        y radius=\ra
    ] ;

 
}
}


[![This is what I want to make][2]][2]


  [1]: https://i.stack.imgur.com/E4qag.jpg
  [2]: https://i.stack.imgur.com/iuZgn.jpg
2
  • The linked image uses circular arcs: x radius = y radius. It is basically a rectangle with rounded corners. OTOH, if you want elliptical nodes, see tex.stackexchange.com/questions/399116/… Mar 11 at 3:25
  • Thank you. I really want the circular arcs. Just can’t use a macro to calculate their radii Mar 11 at 3:35

1 Answer 1

1

This uses \pgfextracty etc. to get the height of the node. I also combined all your draws into one path.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{xparse}
\newlength{\mydiameter}
\NewDocumentCommand{\mynode}{% #1 = node options (optional), #2 = node name, #3 = coordinates, #4 = text, #5 = draw options (optional)
O{}
m
m
m
O{}
}{%
{%
\node [#1] (#2)  at #3 {#4};

\pgfextracty{\mydiameter}{\pgfpointdiff{\pgfpointanchor{#2}{south}}{\pgfpointanchor{#2}{north}}}%

\draw  [#5]  (#2.north west) arc
    [
        start angle=90,
        end angle=270,
        radius={0.5\mydiameter}
    ] -- (#2.south east) arc
    [
        start angle=-90,
        end angle=90,
        radius={0.5\mydiameter}
    ] -- cycle;
}%
}

\begin{document}
\begin{tikzpicture}
\mynode{A}{(0,0)}{Test}
\end{tikzpicture}
\end{document}

demo

1
  • wow perfect! thank you. good clean example. Mar 11 at 16:27

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.