1

I was just wondering if there is a way to change the border style of a node so that one half is, for example, a rectangle and the other an ellipse or cloud or something. The image below visualizes this:

node (left half: rectangle, right half: ellipse

Does someone out there has an idea how to achieve this?

BACKGROUND: I want to use the borderstyle to define the element described by a node, e.g. a rectangle node denotes an element of type X, a node with an ellipse border denotes an element of type Y, and an element that has both types X and Y should be half rectangle, half ellipse. I know how to draw rectangles, ellipses, clouds, etc. but how can I merge them into one style?

CLRW97
  • 165
  • 2
    Did you try with rounded reectangle from the shapes.misc tikzlibrary? It's not elliptical, but it could fit your need. If not, you may try by drawing a pic and putting nodes on it. It's quite tedious but depending on what you need to use your node for, it could be a good idea. Please be more specific about your goal, so that we could help you. – SebGlav Apr 21 '21 at 10:46
  • Thank you, I have added background information to my question. I take a look at your mentioned library. – CLRW97 Apr 21 '21 at 10:55
  • Welcome to TeX.SE!! Perhaps this post can help you: https://tex.stackexchange.com/questions/580026/creating-an-ellipse-rectangle-shaped-node-in-tikz – Juan Castaño Apr 21 '21 at 11:46
  • Unfortunately, even if pic would be a solution, this does not provide all that node does, especially anchors. But depending on how you want to link these nodes, you can manage to create anchors in a pic. – SebGlav Apr 21 '21 at 11:55
  • @Juan Castaño: this is exactly what I was looking for. (NBur's answer, not the pic version). – CLRW97 Apr 21 '21 at 12:09

1 Answers1

2

I'll give you my two cents, just in case.

1. With shapes.misc library

    \begin{tikzpicture}
    \node[
        draw,
        rounded corners=3pt,
        minimum width=3cm,
        minimum height=2cm,
        rounded rectangle,
        rounded rectangle left arc=none,
        font=\sffamily\Large] {Hello};

\end{tikzpicture}

Fancy node 1

2. With a pic and manually inserted anchors

    \begin{tikzpicture}
    \tikzset%
        {
        pin/.style={Circle[]-,red},
        rectell/.pic={              
            \draw (0,0.5*3) coordinate(-north) -| (-0.5*5,0) coordinate(-west) |- (0,-0.5*3) coordinate(-south) arc(-90:0:0.5*5 cm and 0.5*3 cm) coordinate(-east) arc(0:90:0.5*5 cm and 0.5*3 cm) -- cycle;
            \node (-center) at (0,0) {#1}; 
            }
        }

    \draw (0,0) pic(A){rectell={\sffamily\Huge Hello}};

    \draw[pin] (A-center.center) --++ (3,3) node[above] {A-center};
    \draw[pin] (A-north) --++ (-1,1) node[above] {A-north};
    \draw[pin] (A-west) --++ (-1,1) node[above] {A-west};
    \draw[pin] (A-south) --++ (-1,-1) node[below] {A-south};
    \draw[pin] (A-east) --++ (1,1) node[above] {A-east};

\end{tikzpicture}

Fancy node 2

Complete code with preamble:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,shapes.misc}

\begin{document}

\begin{tikzpicture}

    \node[
        draw,
        rounded corners=3pt,
        minimum width=3cm,
        minimum height=2cm,
        rounded rectangle,
        rounded rectangle left arc=none,
        font=\sffamily\Large] {Hello};

\end{tikzpicture}


\bigskip


\begin{tikzpicture}

    \tikzset%
        {
        pin/.style={Circle[]-,red},
        rectell/.pic={              
            \draw (0,0.5*3) coordinate(-north) -| (-0.5*5,0) coordinate(-west) |- (0,-0.5*3) coordinate(-south) arc(-90:0:0.5*5 cm and 0.5*3 cm) coordinate(-east) arc(0:90:0.5*5 cm and 0.5*3 cm) -- cycle;
            \node (-center) at (0,0) {#1}; 
            }
        }

    \draw (0,0) pic(A){rectell={\sffamily\Huge Hello}};

    \draw[pin] (A-center.center) --++ (3,3) node[above] {A-center};
    \draw[pin] (A-north) --++ (-1,1) node[above] {A-north};
    \draw[pin] (A-west) --++ (-1,1) node[above] {A-west};
    \draw[pin] (A-south) --++ (-1,-1) node[below] {A-south};
    \draw[pin] (A-east) --++ (1,1) node[above] {A-east};

\end{tikzpicture}

\end{document}

EDIT: A PARAMETRIC PIC USED AS A NODE

If you want to draw a pic node and choose width and height, you can pass those parameters as arguments to the pic whan you call it.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\begin{document}
\begin{tikzpicture}

    \tikzset%
        {
        pin/.style={Circle[]-,red},
        %
        pics/rectell/.style args={#1/#2/#3}{code = {                
            \draw (0,0.5*#3) coordinate(-north) -| (-0.5*#2,0) coordinate(-west) |- (0,-0.5*#3) coordinate(-south) arc(-90:0:0.5*#2 cm and 0.5*#3 cm) coordinate(-east) arc(0:90:0.5*#2 cm and 0.5*#3 cm) -- cycle;
            \coordinate (-center) at (0,0) node {#1}; 
            }}
        }

    \draw (0,0) pic(A){rectell={\sffamily\Huge Width 7 Height 3}/7/3};

    \draw[pin] (A-center) --++ (3,2) node[above] {A-center};
    \draw[pin] (A-north) --++ (-1,1) node[above] {A-north};
    \draw[pin] (A-west) --++ (-1,1) node[above] {A-west};
    \draw[pin] (A-south) --++ (-1,-1) node[below] {A-south};
    \draw[pin] (A-east) --++ (1,1) node[above] {A-east};

    \draw (0,-6) pic{rectell={\sffamily\Huge W 4 H 5}/4/5};
\end{tikzpicture}

\end{document}

Args for pic

SebGlav
  • 19,186
  • Thank you for your detailled suggestion. I didn't work with pics before, so how could I cange the height of a pic? Simply by adding minimum height to the node in tikzset? Or has this to be done with by setting the drawing parameters? – CLRW97 Apr 21 '21 at 12:47
  • Unfortunately, pics don't work like nodes. You can either change the lengths into the pic declaration or pass them as parameters. – SebGlav Apr 21 '21 at 14:15
  • Okay, I was afraid of this. So I'll go for your first solution. Thanks – CLRW97 Apr 21 '21 at 14:23
  • I just edited my post to add the solution to pass lengths as arguments. It's not too worrying, in my opinion ;) – SebGlav Apr 21 '21 at 14:34