1

I would like to extend this "nodes" example by adding 6 more nodes but I could not see the logic behind this sample code. I could not get the relations of (a), (b) and (c) and how they are actually used. Can someone explain this to me? Here is the output link: https://texample.net/tikz/examples/nav1d/

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\pagestyle{empty}
%
\tikzstyle{int}=[draw, fill=blue!20, minimum size=2em]
\tikzstyle{init} = [pin edge={to-,thin,black}]

\begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
    \node [int, pin={[init]above:$v_0$}] (a) {$\frac{1}{s}$};
    \node (b) [left of=a,node distance=2cm, coordinate] {a};
    \node [int, pin={[init]above:$p_0$}] (c) [right of=a] {$\frac{1}{s}$};
    \node [coordinate] (end) [right of=c, node distance=2cm]{};
    \path[->] (b) edge node {$a$} (a);
    \path[->] (a) edge node {$v$} (c);
    \draw[->] (c) edge node {$p$} (end) ;
\end{tikzpicture}

\end{document}

picture genereted by the code

4
  • 2
    it would be helpful if you give a sketch of the desired output -- there are other ways such as chains and matrix to achieve the same result -- have a look at page 70 of the book -- ctan.imsc.res.in/graphics/pgf/base/doc/pgfmanual.pdf
    – js bibra
    Sep 26 '20 at 16:22
  • @if you click on the link above I would like an extended version of it I mean it have only 2 nodes but I want it to be 10 nodes and I would like the same labeling style as it has. I want to label the lines and I want to put arrows and label the nodes as well as in that example. Also It may grow branches like a horizontal tree and every branch will look like the way I described.
    – esra
    Sep 26 '20 at 16:26
  • 2
    Not sure if this answes your question, but the \node statements create the square boxes. In the \node statements, the first (x) labels the node so it can later be refrred to as (x). In the square brackets are the options for the \node. Then, to join them use the \draw statements where you can use the names of the \node to refer to them. Hope that helps. Sep 26 '20 at 17:40
  • @PeterGrill it actually helped I think I've figured it out. Thanks:)
    – esra
    Sep 27 '20 at 9:28
2
  • your question is not entirely clear ...
  • used example is rather old, consequently it use now deprecated syntax (tikzstyle instead of tikzset, etc)
  • assuming, that all nodes are in chain, have the same size and content, than you can draw them using chains library, for labels of edge use quotes library and defining style for every edge and pin:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                chains,
                positioning,
                quotes}

\begin{document}
    \begin{tikzpicture}[
node distance = 12mm,
  start chain = going right, 
   int/.style = {draw, fill=blue!20, minimum size=2em, font=\large, 
                 on chain},
 every edge/.style = {draw, -Latex},
every edge quotes/.style = {auto, font=\footnotesize, text depth=0.25ex},
  every pin/.style = {pin edge={Latex-,thin,black}, font=\footnotesize}
                        ]
% nodes vith pin above
\coordinate[on chain] (in);
\node (a) [int, pin=$v_0$] {$\frac{1}{s}$};
\node (b) [int, pin=$p_0$] {$\frac{1}{s}$};
\node (c) [int, pin=$p_1$] {$\frac{1}{s}$};
\node (d) [int, pin=$p_2$] {$\frac{1}{s}$};
\node (e) [int, pin=$p_3$] {$\frac{1}{s}$};
\coordinate[on chain] (out);
% connection between nodes
\draw   (in)    edge ["$a$"] (a) 
        (a)     edge ["$v$"] (b) 
        (b)     edge ["$p$"] (c)
        (c)     edge ["$p_1$"] (d)
        (d)     edge ["$p_2$"] (e)
        (e)     edge ["$p_3$"] (out) ;
    \end{tikzpicture}
\end{document}

enter image description here

If you like to have more nodes in chain, just add them to already existing. If you not need start condition, simply drop pin in them.

Edit: The example which you provide, has two parts:

  • Definitions of styles (where is used deprecated syntax, today it should be written as:
\tikzset{
  int/.style = {draw, fill=blue!20, minimum size=2em},
 init/.style = {pin edge={to-,thin,black}}
         }

or as options of tikzpicture:

\begin{tikzpicture}[node distance=2.5cm,auto,>=latex',
 int/.style = {draw, fill=blue!20, minimum size=2em},
init/.style = {pin edge={to-,thin,black}}
               ]
  • Image body, where you draw what you like to have on image. This can you do on many different way. For example,
    • using absolute positioning od nodes:
\node (<name>) [<style>] at (<x coordinate>,<y coordinate>) {<node content>};
  • using relative positioning od nodes:
\node (<name 1>) [<style 1>] at (<x coordinate>,<y coordinate>) {<node content>};
\node (<name 2>) [<style 2>, above right=of <name 1>]  {<node content>};

where <node 2> will be positioned above and left from node <node 2> for declared node distance in tikzset or as option as done in above showed example.

  • lines you can draw as
\draw[<option>] (<coordinate 1>) -- (<coordinate 2>);

where for <option> you can use for example init as is done in showed MWE (Minimal Working Example) in your question and for coordinates use nodes' names.

or use more advanced approach as is used in my answer.

  • for other options you need to make yourself more familiar with TikZ package and their libraries. Manual is part of your LaTeX installation or you can find it on CTAN (use google for tikz.sty).
  • Manula is huge, so for start read part I Tutorials and Guidelines and than part III: TikZ ist kein Zeichenprogramm.
  • If you will stuck in drawing of some your image, ask here for concrete help. At this please provide MWE, which reproduce your problem, that people can easier help you (Preparing of an MWE, an example is in my answer, many times help you to found a solution or discover error in code by yourself)
  • Site is not intended to giving general guidelines how to use tikz package.
4
  • Thanks this helped a lot, Can you give me a piece of advice of how can I make this chain have branches like an rightward growing tree? Can I add more nodes &paths that grow with some kind of slope of 90 degrees or 60 degrees?
    – esra
    Sep 27 '20 at 9:37
  • @esra, than draw it as tree, not as chain. Or position nodes absolutely, for example as \node[<options>] at (<coordinate>) {<node content>}. I haven't any idea, what you like to draw. See Tikz and PGF Manual, part III: TikZ ist kein Zeichenprogramm for all possibilities and details.
    – Zarko
    Sep 27 '20 at 9:53
  • @esra, see edit in my answer.
    – Zarko
    Sep 27 '20 at 10:52
  • Thanks I have figured it out now.
    – esra
    Sep 27 '20 at 13:48
2

A full explanation is below--

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary {arrows.meta,graphs,shapes.misc}
\usetikzlibrary{arrows}
\begin{document}
    \pagestyle{empty}
    %no headers and footers just a blank page
    \tikzstyle{int}=[draw, fill=blue!20, minimum size=2em]
    %macro for (draw)ing square, (fill) inside color blue, default size 2em
    \tikzstyle{init} = [pin edge={to-,thin,black}]
    %macro for arrows/ edges
    
    \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
        %separation between nodes 2.5cm, type of arrows defined with >=latex
        \node [int, pin={[init]above:$v_0$}] (a) {$\frac{1}{s}$};
        %call the int macro for square named (a), and the init macro for the arrow 
        pointing (to-a), label above the arrow is v_0, and text inside the named node 
        is  {$\frac{1}{s}$}
        \node (b) [left of=a,node distance=2cm, coordinate] {a};
        %node named (b) placed left of node named (a), tec=xt inside the node is {a}
        \node [int, pin={[init]above:$p_0$}] (c) [right of=a] {$\frac{1}{s}$};
        %same as first node named (a)
        \node [coordinate] (end) [right of=c, node distance=2cm]{};
        %same as node named (end) after node named (c)
        \path[->] (b) edge node {$a$} (a);
        %draw an arrow from node b to node a, label above the arrow  {$a$}
        \path[->] (a) edge node {$v$} (c);
        %same as arrow above
        \draw[->] (c) edge node {$p$} (end) ;
        %same as arrow above
    \end{tikzpicture}
\end{document}
2
  • Thanks. Do you know how can I grow the nodes&paths with some sort of slope. Like a tree that grows rightward branches ?
    – esra
    Sep 27 '20 at 9:39
  • Thanks for the explanation I think I have figured it out.
    – esra
    Sep 27 '20 at 13:49

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.