4

I use the very nice tikz-network package for simple graphs where I need to have long labels, is there a way to have a label on two lines ?

enter image description here

\begin{filecontents}{vert.csv}
id, label, x, y
A, long label, 0,  0
B, label 2,0.87,0.5
C, label 3, -0.87,  0.5
D, label 4,-0.87,  -0.5
E, label 5, 0.87,-0.5
\end{filecontents}
\begin{filecontents}{edg.csv}
u,v,label, bend
B,A,FC1,0
C,A,FC2,0
D,A,FC3,0
E,A,FC4,0
B,C,FP1,15
B,E,FP2,-40
\end{filecontents}
\documentclass[a4paper,12pt]{article}
\usepackage{tikz-network}
\begin{document}
\begin{tikzpicture}
\SetVertexStyle[MinSize=1.2cm]
\SetDistanceScale{3.0}
\Vertices{vert.csv}
\Edges{edg.csv}
\end{tikzpicture}
\end{document}

2 Answers 2

4

The manual suggests to add [style={...}] to the \Vertices macro, but from the source code it seems that the texts in the nodes are done separately. Therefore I suggest to "hack" it (which has nothing to do with the name of the package author;-) by just setting

every label/.append style={text width=1cm,align=center}

in the tikzpicture options.

\documentclass[a4paper,12pt]{article}
\usepackage{filecontents}
\begin{filecontents*}{vert.csv}
id, label, x, y
A, {long label}, 0,  0
B, label 2,0.87,0.5
C, label 3, -0.87,  0.5
D, label 4,-0.87,  -0.5
E, label 5, 0.87,-0.5
\end{filecontents*}
\begin{filecontents*}{edg.csv}
u,v,label, bend
B,A,FC1,0
C,A,FC2,0
D,A,FC3,0
E,A,FC4,0
B,C,FP1,15
B,E,FP2,-40
\end{filecontents*}
\usepackage{tikz-network}
\begin{document}
\begin{tikzpicture}[every label/.append style={text width=1cm,align=center}]
\SetVertexStyle[MinSize=1.2cm]
\SetDistanceScale{3.0}
\Vertices{vert.csv}
\Edges{edg.csv}
\end{tikzpicture}
\end{document}

enter image description here

1

Just have a look at tikz-network documentation and see that plain TikZ can help for this kind of simple figures. (why tikz-network use the default color teal!50 ?)

enter image description here

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[line width=1.5pt,
n/.style={circle,draw,fill=#1,minimum size=15mm},
j/.style={circle,midway,fill=white}]
\def\a{4} \def\b{2.5}

\path
(0,0)     node[n=orange,align=center] (F) {Four\\Seasons}
(-\a,-\b) node[n=green!50] (Sp) {Spring}
(\a,-\b)  node[n=red!50] (Su) {Summer}
(\a,\b)   node[n=yellow!50] (Au) {Autumn}
(-\a,\b)  node[n=gray!50] (Wi) {Winter};

\draw 
(F)  to node[j]{FC3} (Sp)
(F)  to node[j]{FC4} (Su)
(F)  to node[j]{FC1} (Au)
(F)  to node[j]{FC2} (Wi)
(Wi) to[bend right=20] node[j]{FP1} (Au)
(Su) to[bend left=20]  node[j]{FP2} (Au); 
\end{tikzpicture}
\end{document}

You must log in to answer this question.

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