3

I have used my very basic knowledge of tikz to make the image on the LHS (or top, depending on device viewer), whereas what I actually want in the image on the RHS (created with mathematica):

This is the code I used:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata,arrows,calc,positioning}

\begin{document}

\begin{figure}%[H]
\centering
\begin{tikzpicture}[>=stealth', shorten >=1pt, auto,
node distance=2cm, scale=1, 
transform shape, align=center, 
state/.style={circle, draw, minimum size=2cm}],

\tikzset{arrowhead=2cm}

\node[state]  (GS) {Person};  
\node[state,  right=of GS]  (G1) {work};
\node[state, above right=of GS] (G2) {family};
\node[state, above left=of GS] (G3) {friends};
\node[state, left=of GS] (G4) {partner \\wife};
\node[state, below left=of GS] (G5) {community};
\node[state, below right=of GS] (G6) {local \\agencies};

\path[->] (GS) edge node {} (G1)
          (GS) edge node {} (G2)
          (GS) edge node {} (G3)
          (GS) edge node {} (G4)
          (GS) edge node {} (G5)
          (GS) edge node {} (G6);

\end{tikzpicture}
\end{figure}
\end{document}

I have tried but failed to legend and style the arrow lines to get the desired effect.

3 Answers 3

2

First of all note that your code gives the error I do not know the key '/tikz/arrowhead', to which you passed '2cm', and I am going to ignore it. There is no such key to adjust the size of arrow tips, which I assume is what you were trying to do(?).

To actually modify the tip sizes, load the arrows.meta library instead of the old and deprecated arrows library. arrows.meta define a set of new tips including Stealth (note capital S), which can take various settings. For example, you can use

>={Stealth[width=7pt, length=8pt]}

to get a bigger tip. Note that the braces ({}) are necessary to hide the ] from the parsers, otherwise that closing bracket will be seen as the closing bracket for \begin{tikzpicture}[...]

To make a dashed line, use dashed, e.g. Draw a dash-dotted line

For the legend draw a line, and add a node to the right of the end point, i.e. something like \draw (a,b) -- +(1.5,0) node[right] {foo}; for some useful choice of the coordinate (a,b). The + before (1.5,0) means that it is a relative coordinate. In the code below I placed it relative to the community node.

I also remove the empty nodes at each edge, because if you're not labeling the edges those nodes are just not needed.

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{
  automata,
  arrows.meta, % instead of the deprecated arrows
  calc,
  positioning
}

\begin{document}

\begin{figure}%[H]
\centering
\begin{tikzpicture}[
 >={Stealth[width=7pt, length=8pt]},
 shorten >=1pt, auto,
 node distance=2cm, scale=1, 
 transform shape, align=center, 
 state/.style={circle, draw, minimum size=2cm}
]

\node[state]  (GS) {Person};  
\node[state,  right=of GS]  (G1) {work};
\node[state, above right=of GS] (G2) {family};
\node[state, above left=of GS] (G3) {friends};
\node[state, left=of GS] (G4) {partner \\wife};
\node[state, below left=of GS] (G5) {community};
\node[state, below right=of GS] (G6) {local \\agencies};

\path[->] (GS) edge (G1)
          (GS) edge[dashed] (G2)
          (GS) edge[dashed] (G3)
          (GS) edge[dashed] (G4)
          (GS) edge[dashed] (G5)
          (GS) edge[dashed] (G6);


\draw (G5.south west) ++(-1.5,-1.5) coordinate (tmp) -- +(1.5,0) node[right] {Relationship};
\draw [dashed] (tmp)  ++(0,-0.5) -- +(1.5,0) node[right] {Relationship needed};
\end{tikzpicture}
\end{figure}
\end{document}
3
  • many thanks! If I wanted 5 nodes, could I specify degrees/radians? ie instead of (G5.south west) and below left?
    – martin
    Commented Jan 15, 2022 at 15:42
  • 1
    @martin For the legend position you could use e.g. (G5.200) ++(-1,5, -1..5) if you want to. If you're talking about the general layout of the diagram, you can use polar coordinates, e.g \node[state] (G2) at (72:3cm) {family};. That assumes that GS is positioned at (0,0) (which it is in this case), otherwise you could do e.g. \path (GS.center) ++(72:3cm) node[state] (G2) {family};. Haven't tested any of that code by the way. Commented Jan 15, 2022 at 15:50
  • thank you, will try it out
    – martin
    Commented Jan 15, 2022 at 15:53
3
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata,arrows,calc,positioning,arrows.meta}

\begin{document}

\begin{figure}%[H]
\centering
\begin{tikzpicture}[>=stealth', shorten >=1pt, auto,
node distance=2cm, scale=1, 
transform shape, align=center, 
state/.style={circle, draw, minimum size=2cm}],

\node[state]  (GS) {Person};  
\node[state,  right=of GS]  (G1) {work};
\node[state, above right=of GS] (G2) {family};
\node[state, above left=of GS] (G3) {friends};
\node[state, left=of GS] (G4) {partner \\wife};
\node[state, below left=of GS] (G5) {community};
\node[state, below right=of GS] (G6) {local \\agencies};

\path[-{Stealth[length=5mm]},dashed] (GS) edge node {} (G1)
          (GS) edge node {} (G2)
          (GS) edge node {} (G3)
          (GS) edge node {} (G4)
          (GS) edge node {} (G5);
          
\path[-{Stealth[length=5mm]},solid] (GS) edge node {} (G6);
\draw ([yshift=-2cm] current bounding box.south west) -- ++(2cm,0) node[xshift=1.2cm]{Relationship};
\draw[dashed] ([yshift=-1cm] current bounding box.south west) -- ++(2cm,0) node[xshift=1.8cm]{Relationship needed};
\end{tikzpicture}
\end{figure}
\end{document}

enter image description here

With new contraintes. I've never been a big fan of `positionning'

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

\begin{document}

\begin{figure}%[H]
\centering
\begin{tikzpicture}[>=stealth', shorten >=1pt, auto,  align=center, 
state/.style={circle, draw, minimum size=2cm}],

\node[state]  (GS) {Person};  
\node[state] at  (canvas polar cs:angle=90,radius=4cm) (G1) {work};
\node[state] at  (canvas polar cs:angle=18,radius=4cm) (G2) {family};
\node[state] at  (canvas polar cs:angle=162,radius=4cm) (G3) {friends};
\node[state] at  (canvas polar cs:angle=234,radius=4cm) (G5) {community};
\node[state] at  (canvas polar cs:angle=-54,radius=4cm) (G6) {local \\agencies};

\path[-{Stealth[length=5mm]},dashed] (GS) edge node {} (G1)
          (GS) edge node {} (G2)
          (GS) edge node {} (G3)
          (GS) edge node {} (G5);
          
\path[-{Stealth[length=5mm]},solid] (GS) edge node {} (G6);
\draw ([yshift=-2cm] current bounding box.south west) -- ++(2cm,0) node[right]{Relationship};
\draw[dashed] ([yshift=-1cm] current bounding box.south west) -- ++(2cm,0) node[right]{Relationship needed};
\end{tikzpicture}
\end{figure}
\end{document}

enter image description here

8
  • We can do better for the legend because there I positioned the labels by hand Commented Jan 15, 2022 at 15:28
  • thank you! If I wanted 5 nodes, could I specify degrees/radians? ie instead of current bounding box.south west and below left?
    – martin
    Commented Jan 15, 2022 at 15:43
  • 1
    What do you mean by "5 nodes"? Commented Jan 15, 2022 at 15:52
  • as opposed to the six used here. In other words, if (eg) community was removed
    – martin
    Commented Jan 15, 2022 at 15:53
  • eg as per this image
    – martin
    Commented Jan 15, 2022 at 15:57
2

Five satellite nodes, using polar coordinates:

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

\begin{document}
    \begin{figure}[ht]
    \centering
\begin{tikzpicture}[
         C/.style = {circle, draw, semithick,
                     text width=4em, align=center,
                     inner sep=2pt, outer sep=2pt},
every edge/.style = {draw, -{Stealth[angle=60:5pt 6]}, semithick} % <---
                    ]
\node[C] (GS) {Person};
\foreach \i [count=\j] in {work, family, friends, partner wife, local agencies}
{
    \node[C] (s\j) at (\j*360/5:33mm) {\i};    % five satellite nodes
}
\path   (GS) edge[dashed] (s1)
             edge[dashed] (s2)
             edge[dashed] (s3)
             edge[dashed] (s4)
             edge         (s5);
% legend
\draw           (GS) ++ (-4,-4.0) -- ++ (1,0) node[right] {Relationship};
\draw[dashed]   (GS) ++ (-4,-4.5) -- ++ (1,0) node[right] {Relationship needed};
\end{tikzpicture}
    \end{figure}
\end{document}

More about arrows style you can find in TikZ & PGFF manual for version 3.1.9a, chapter 16.5 Reference: Arrow Tips, on page 211. Used arrows style is described on page 212 and 215 (for Straight Barb).

enter image description here

Addendum In cases, when you like to rotate image for some angle, just add this angle to calculation of anchors. For example:

\node[C] (s\j) at (<angle offset> +\j*360/5:33mm) {\i}; 

This ` is in the case when you like to have node "work" at 90 degree is:

    \node[C] (s\j) at (90-360/5+\j*360/5:33mm) {\i};    % five satellite nodes with angle offset (90-360/5) =18 degree

Considering this in above MWE, it will produce the following image:

enter image description here

3
  • thank you. What would the syntax for (\j*360/5:33+360/10:33mm) be (ie, if I wanted to rotate it by 360/10)?
    – martin
    Commented Jan 15, 2022 at 17:03
  • Ah, found it: (360/20+\j*360/5:33mm)
    – martin
    Commented Jan 15, 2022 at 17:11
  • 1
    @martin, syntax in your first comment is correct. See addendum to answer.
    – Zarko
    Commented Jan 15, 2022 at 17:26

You must log in to answer this question.

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