1

Which library works better (convenient) for drawing/coloring (nodes) in Latex the following: enter image description hereenter image description here

closed as primarily opinion-based by cfr, Zarko, Phelype Oleinik, gusbrs, Mensch Feb 28 '18 at 1:41

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    TikZ or pstricks or .... Which is most convenient depends, most of all on which you find most convenient. That is, this is asking for opinions, essentially, as there is no one answer. TikZ has automated graph-drawing algorithms, but you must use LuaTeX which isn't always an option for everyone. Otherwise, you can lay it out manually or as a matrix or as a commutative diagram or as chains or .... (And those are just TikZ options, really. pstricks offers more options besides.) – cfr Feb 27 '18 at 23:42
6

Here is a short code with pstricks:

\documentclass[border=5pt, svgnames]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pst-node}
\usepackage{ auto-pst-pdf } %% to compile with pdflatex --enable-write18 (MiKTeX) or pdflatex --shell-escape (TeX Live, MacTeX))
\usepackage{makebox} 

\begin{document}

$ \begin{psmatrix}[rowsep=1.1cm, colsep=1.2cm, mnode = circle]%
%%%% Nodes
[name = I1] \infty &[fillcolor = Gainsboro!60!Lavender, fillstyle= solid, name = Z]
      \makebox*{$\infty$}{$ 0 $} & [name = I3] \infty & [name = I4] \infty \\
  [name = J1] \infty & [name = J2]\infty & [name = J3]\infty & [name = J4]\infty
%%%%% Connecting nodes
\foreach \S/\T in {J1/I1,I1/Z, Z/J2, J2/I3, J2/J3, J3/I3, J3/I4, J3/J4, I3/I4,I4/J4}{\ncline{\S}{\T}}
%%%%% Labelling nodes
\psset{labelsep = 3pt}
\foreach \N/\label in {I1/r, Z/s, I3/t, I4/u}{\nput{90}{\N}{\label}}
\foreach \N/\label in {J1/v, J2/w, J3/x, J4/y}{\nput{-90}{\N}{\label}}
\end{psmatrix} $

\end{document} 

enter image description here

To obtain a diagram with shaded connection, one must the border=length and bordercolor= keys, but due to the shading, the strategy is a little different: we build a matrix of empty nodes, connect these nodes and next add \pscircleboxes to these nodes:

\documentclass[border=5pt, svgnames]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pst-node}
\usepackage{ auto-pst-pdf } %% to compile with pdflatex --enable-write18 (MiKTeX) or pdflatex --shell-escape (TeX Live, MacTeX))

\begin{document}

$ \begin{psmatrix}[rowsep=1.1cm, emnode = p]%
%%%% Nodes
[name = Oa] &[name = Z] & [name = I3] & [name = I4] \\
  [name = J1] & [name =Ob] & [name = J3] & [name = J4] %
%%%%% Connections
\foreach \S/\T in { J3/I3, J3/I4, J3/J4, I3/I4,I4/J4}{\ncline{\S}{\T}}
\foreach \S/\T in {J1/Oa, Oa/Z, ,Z/Ob, Ob/I3,Ob/J3}{\ncline[border = 3.5pt, bordercolor = LightSlateGray, nodesep = -1pt]{\S}{\T}}
%%%%% Labels
\foreach \N/\label in {Oa/r, Z/s, I3/t, I4/u}{\nput[labelsep = 15pt]{90}{\N}{\label}}
\foreach \N/\label in {J1/v, Ob/w, J3/x, J4/y}{\nput[labelsep = 9pt]{-90}{\N}{\label}}
%%%% Coloured and non-coloured nodes
\psset{fillstyle = solid}
\foreach \node in {I3,I4, J1, J3, J4}{\rput(\node){\pscirclebox{\infty}}}
\psset{framesep = 4.4pt, fillcolor = DarkSlateGrey }
\rput(Oa){\pscirclebox[fillcolor = Gainsboro!60!Lavender]{1}}
\rput(Z){\pscirclebox{\color{white}0}}
\rput(Ob){\pscirclebox{\color{white}1}}
\end{psmatrix} $

\end{document} 

enter image description here

  • It's a very useful example. How can I add some shading to a given edge, say from x to y, and change the color of the text in the node? (sth similar to the second image above) – Drimades Boy Feb 28 '18 at 4:01
  • @DrimadesBoy: I've added a code for the shading, which is slightly different from, but as short as the previous code. – Bernard Feb 28 '18 at 14:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.