1

enter image description here [taken from https://tex.stackexchange.com/a/396436/128718 ]

I want to use something like

\node[basic,anchor=north.west, xshift=5cm] {instructor.south.east}(department) {department,

instead of

\node[basic,right=5cm of instructor] (department) {department  

That means x-coordinate distance between north.west corner of department and south.east corner of instructor is 5cm.

MWE(taken from @marmot)

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{positioning,shapes.multipart,shapes}
\begin{document}
\tikzset{basic/.style={
        draw,
        rectangle split,
        rectangle split parts=2,
        rectangle split part fill={blue!20,white},
        minimum width=2.5cm,
        text width=2cm,
        align=left,
        font=\itshape
    },
    Diamond/.style={ diamond, 
                        draw, 
                        shape aspect=2, 
                        inner sep = 2pt,
                        text centered,
                        fill=blue!10!white,
                        font=\itshape
                      }}
\begin{tikzpicture}
\node[basic] (instructor) {instructor
\nodepart{second}
\underline{ID}\\
name\\
salary};
\node[basic,right=5cm of instructor] (department) {department
%I want to 
%\node[basic,anchor=north,yshift=-3cm] (department)(instructor.south) {department
\nodepart{second}
\underline{dept\_name}\\
building\\
budget};
\draw (instructor) -- (department) node[midway,Diamond]{member};
\end{tikzpicture}
\end{document}
3
3

UPDATE: I have completely misunderstood what you want. The syntax is

\node[basic,right=5cm of instructor.south,anchor=north] (department) ...

Here is the MWE for that:

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{positioning,shapes.multipart,shapes}
\begin{document}
\tikzset{basic/.style={
        draw,
        rectangle split,
        rectangle split parts=2,
        rectangle split part fill={blue!20,white},
        minimum width=2.5cm,
        text width=2cm,
        align=left,
        font=\itshape
    },
    Diamond/.style={ diamond, 
                        draw, 
                        shape aspect=2, 
                        inner sep = 2pt,
                        text centered,
                        fill=blue!10!white,
                        font=\itshape
                      }}
\begin{tikzpicture}
\node[basic] (instructor) {instructor
\nodepart{second}
\underline{ID}\\
name\\
salary};
\node[basic,right=5cm of instructor.south,anchor=north] (department) {department
\nodepart{second}
\underline{dept\_name}\\
building\\
budget};
\draw (instructor) -- (department) node[midway,Diamond]{member};
\end{tikzpicture}
\end{document}

enter image description here

ORIGINAL ANSWER: I was under the impression you wanted to combine Torbjørn's great answer with the "basic" style. That's possible, e.g.

\documentclass[tikz,border=3mm]{standalone}
\usepackage[simplified]{pgf-umlcd} %<- added simplified here in order to avoid
% empty splits
% redefine enviroment
\renewenvironment{class}[3][]%
{
\begin{classAndInterfaceCommon}{#1}{#2}{#3}
}%
{\calcuateNumberOfParts{}
% Thorbjorns only change was in the following line, where "anchor=north" was moved before "this umlcd style"
% but I replaced "this umlcd style" by "basic=\theumlcdClassSplitPartNum"
% and changed the way you define the position. Essentially you need to put 
% brackets around
\node[anchor=north,basic=\theumlcdClassSplitPartNum] (\umlcdClassName) at \umlcdClassPos
    {\textbf{\umlcdClassName}
\insertAttributesAndOperations{}
};

\end{classAndInterfaceCommon}
}
\usetikzlibrary{positioning,shapes.multipart,shapes}
\tikzset{basic/.style={
        draw,
        rectangle split,
        rectangle split parts=#1,
        rectangle split part fill={blue!20,white},
        minimum width=2.5cm,
        text width=2cm,
        align=left,
        font=\itshape
    },
    Diamond/.style={ diamond, 
                        draw, 
                        shape aspect=2, 
                        inner sep = 2pt,
                        text centered,
                        fill=blue!10!white,
                        font=\itshape
                      }}
\begin{document}
\begin{tikzpicture}
\begin{class}{foo}{(0,0)}
\attribute{+ Public}
\end{class}

\begin{class}{bar}{([yshift=-10mm]foo.south)}
\attribute{+ balance : Dollars}
\operation{+ deposit( amount : Dollars )}
\end{class}

\begin{class}[anchor=west]{baz}{([xshift=20mm]bar.east)}
\end{class}
\end{tikzpicture}
\end{document} 

enter image description here

This code works essentially like Torbjørn's except that you now have to put all the placement information in the third argument and put parentheses around, examples are provided above. As a bonus, the nodes won't be split any more if that's not necessary. Clearly, depending on what you want to do, you may want to increase the text width of the nodes and so on.

5
  • No need to make complex your code. I want to use your previous solution. Just make change in giving position. I want to use something like \node[basic,anchor=north.west, xshift=5cm] {instructor.south.east}(department) {department, instead of \node[basic,right=5cm of instructor] (department) {department
    – alhelal
    Mar 28 '18 at 8:17
  • see edited question.
    – alhelal
    Mar 28 '18 at 8:47
  • @alhelal Does \node[basic,right=5cm of instructor.south,anchor=north] (department) {department ... give you what you want?
    – user121799
    Mar 28 '18 at 10:45
  • Yes, this works.
    – alhelal
    Mar 28 '18 at 13:40
  • Then I guess you can make a solution with xshift and yshift
    – alhelal
    Mar 28 '18 at 13:41

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.