2

I'm trying to create latex command for specific node layout in tikz:

\begin{tikzpicture}
    \node (anode) [lestyle, rectangle split, rectangle split parts=2]
    {
        \textbf{node A}
        \nodepart{second}description of A
    };
    \node (bnode) [lestyle, rectangle split, rectangle split parts=2, below=of anode]
    {
        \textbf{node B}
        \nodepart{second}description of B
    };
\end{tikzpicture}

The layout of node internals will be more complex and I will have a lot of similar nodes. So, I want it to put common layout inside custom function. However, I want to allow properties to be added from outside of command, since nodes will differ in more properties than below.

I've created custom LaTex command for node.

\newcommand{\nodele}[2]{
    \node (mynodele) [lestyle, rectangle split, rectangle split parts=2]
    {
        \textbf{#1}
        \nodepart{second}#2
    }
}

and picture:

\begin{tikzpicture}
    \nodele{node A}{description of A};
    \nodele{node B}{description of B};
\end{tikzpicture}

The problem is: I can't set their names with (name) like in first example. Also, can't add custom properties (any, not only below) to node.

1 Answer 1

3

The obvious choice is to make another input for the options

%    \usetikzlibrary{shapes,positioning}

\def\nodele[#1]#2#3{
    \node[rectangle split, rectangle split parts=2,#1]
    {
        \textbf{#2}
        \nodepart{second}#3
    }
}

\begin{tikzpicture}
    \nodele[red,at={(3,1)},name=a]{node A}{description of A};
    \nodele[blue,below=of a]{node B}{description of B};
\end{tikzpicture}

enter image description here

3
  • Wow, nice solution. Isn't that hard/complex as I expected, but is it possible to have name in brackets (a) instead of name=a?
    – kravemir
    Commented Feb 6, 2015 at 10:42
  • @Miro Add another input if you want [#1](#2)#3#4 :) But it would get also tedious to type these in if you have too many
    – percusse
    Commented Feb 6, 2015 at 10:46
  • I thought I understand little bit LaTeX. ...I've got now no idea how LaTeX works, but \def\nodele(#1)[#2]#3#4 works perfectly ^_^
    – kravemir
    Commented Feb 6, 2015 at 10:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .