2

I want to draw following figure, I was not able to manage drawing its arrow format where like a tree-like format:

enter image description here

Reference: The Linux Programming Interface, Figure 41-1


My beginner approach:

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}
    [ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        arrow/.style={->, >=stealth, semithick},
    ] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    \draw[help lines] (0,0) grid (8,4);
    [
    >=latex,shorten >=2pt,shorten <=2pt,shape aspect=1,
    % arrow/.style={->, >=stealth, very thick},
    % arrow/.style={<->, >=stealth, semithick},
    block/.style={}
    every node/.style = {font=\footnotesize}
    ]
    \node[
        rectangle,
        double=black,
        double distance =0.5pt,
        shape border rotate=90,
        draw,
        fill=white,
        shape aspect=0.2,
        font={\scriptsize\baselineskip=8pt},
        inner xsep=3pt,
        align=left,
    ]  (A) at (1,4) {\scriptsize \$ gcc -g -c \\ \,\, -fPIC - Wall \\ \,\, mod1.c mod2.c mod3.c};

    \node[circle,
        shape border rotate=90,
        inner xsep=0pt,
        draw] (B) at (-0.9,4.3) {\tiny 1};

    \node[
        rectangle,
        double=black,
        double distance =0.5pt,
        shape border rotate=90,
        draw,
        fill=white,
        font={\scriptsize\baselineskip=8pt},
        inner xsep=3pt,
        align=left,
    ]  (B) at (2,2) {mod1.o code};

    \node[
        rectangle,
        double=black,
        double distance =0.5pt,
        shape border rotate=90,
        draw,
        fill=white,
        font={\scriptsize\baselineskip=8pt},
        inner xsep=3pt,
        align=left,
    ]  (C) at (2,1) {mod2.o code};


    \node[
        rectangle,
        double=black,
        double distance =0.5pt,
        shape border rotate=90,
        draw,
        fill=white,
        font={\scriptsize\baselineskip=8pt},
        inner xsep=3pt,
        align=left,
    ]  (D) at (2,0) {mod3.o code};

    \draw [arrow] (A.south) -- (B.west);
    \draw [arrow] (A.south) -- (C.west);
    \draw [arrow] (A.south) -- (D.west);

\end{tikzpicture}
\end{document}

enter image description here

Here I was unable to manage to draw tree-format arrows as:

[*]
 │   
 ├──> [...]
 ├──> [...]
 └──> [...]
5
  • 2
    Tikz provides several ways to do it. Search e.g. for |– or graphs in the pgfmanual.
    – MS-SPO
    Jul 16 at 18:00
  • 1
    Ah I was working on pgfmanul version 1.18, that's why I was not able to find a way to do it.
    – alper
    Jul 16 at 18:04
  • Fine. Looks like you can move many common options to a small number of format statements. Best examples, when the manual explains statement \tikz[]{}
    – MS-SPO
    Jul 16 at 18:08
  • sorry I did not get the` common options to a small number of format statements.` => you mean the node format definitions right?
    – alper
    Jul 16 at 19:39
  • Yes. Sorry for having been too brief. Ah, see the answer from Zarko.
    – MS-SPO
    Jul 16 at 19:48

1 Answer 1

5

Like this:

enter image description here

In MWE below nodes are positioned relatively to each other. Also are defined styles for nodes and by this made picture code significantly shorter. For arrow are used orthogonal coordinates |- (for details of its use see TikZ & PGF manual, section 13.3.1 Intersections of Perpendicular Lines) as suggested in @ MS-SPO comment:

\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                 positioning}

\begin{document}
    \begin{tikzpicture}[
node distance = 4mm and 8mm,
   arr/.style = {-Stealth, semithick},
     C/.style = {circle, draw, font=\footnotesize},
     N/.style = {draw, very thick,
                 font=\small, align=left,
                 inner sep=5pt}
                        ]
\draw[help lines] (0,0) grid (8,5);
%
\node (n1) [N] at (3,4) {\$ gcc -g -c \\ 
                         \hphantom{\$ } -fPIC - Wall \\
                         \hphantom{\$ } mod1.c mod2.c mod3.c};
    \node[C, below left = 0 and 2mm of n1.north west] {1};
\node (n2) [N, below right=of n1.south]     {mod1.o code};
\node (n3) [N, below=of n2]     {mod2.o code};
\node (n4) [N, below=of n3]     {mod3.o code};
%
\draw[arr] (n1) |- (n2);
\draw[arr] (n1 |- n2) |- (n3);
\draw[arr] (n1 |- n3) |- (n4);
    \end{tikzpicture}
\end{document}

Addendum: Regarding your comment, you only need to change style of C nodes (to some extend only). For example:

...
    \begin{tikzpicture}[
node distance = 4mm and 8mm,
   arr/.style = {-Stealth, semithick},
     C/.style = {circle, draw, inner sep=1pt}, % <--- text in node will be \normalsize
     N/.style = {draw, very thick,
                 font=\small, align=left,
                 inner sep=5pt}
                        ]
...

gives

enter image description here

At bigger font in circle will enlarge circle too.

9
  • Thanks its golden. Is it possible to keep 1 larger font while keeping the circle size same? I play around but when I try to increase the font size circle also becomes larger
    – alper
    Jul 16 at 19:52
  • 1
    @alper, yes, it is possible to some extend. You only need to change C/.style accordingly. For example to C/.style = {circle, draw, inner sep=1pt},. See ddendum to answer.
    – Zarko
    Jul 16 at 20:05
  • Sorry for the late comment, in double column is it possible to start grid from most left side of the column? looks like it starts 4 space inside by default
    – alper
    Jul 17 at 0:36
  • @alper, yes this is possible too. Change node distance to node distance = 4mm and 10mm,. However, I would not use help lines. To my opinion they distract image. If you like to have image elements on grid, nodes size will not to be consistent anymore. But this is up to you,
    – Zarko
    Jul 17 at 3:36
  • 1
    @alper, ok. Apparently you move nodes positions according to help' lines. But, what you will do when nodes sizes are not aligned with help lines steps? Distance between nodes are determined by node distance=<vertical> and <horizontal> so you only need to determine size of gaps between nodes as is done in answer. Only "problem" (not really) is determine where star second node) offset form south anchor of the first node. A little experiences here is more helpful than help lines. BTW, on the end you can simple removes help lines by comment it by % at beginning of its code line.
    – Zarko
    Jul 17 at 10:27

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.