7

I would like it if someone can help me to draw the enclosed diagram?

enter image description here

This is the code that I made:

\tikzstyle{block} = [draw, fill=cyan, regular polygon,
minimum height=3em, minimum width=6em]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]

\begin{figure}[ht] \centering \begin{tikzpicture}[auto, node distance=2cm,>=latex'] \node [input, name=input] {}; \node [block, right of=sum] (Ablock) {A} edge [loop above] node {$\alpha$} (A); \node [block, right of=Ablock, node distance=4cm] (Bblock) {B} edge [loop above] node {$\beta$} (A); \draw [->] (Ablock) -- node[name=b] {a} (Bblock); \begin{scope}[transform canvas={yshift=-2mm}] \draw [->] (Bblock) -- node[name=a] {$b$} (Ablock); \end{scope} \node [output, right of=Bblock] (output) {}; \node [block, below of=b] (Cblock) {C} edge [loop below] node {$\gamma$} (C); \draw [->] (sum) -- node {} (Ablock); \draw [-] (Bblock) -| (output) node [name=c] {}; \draw [-] (c) |- (Cblock); \draw [-] (Cblock) -| [near end] {} (sum); \end{tikzpicture} \end{figure}

enter image description here

euler_med
  • 518
  • 1
    Please only use tags which actually apply to your question and don't just use random popular tags – samcarter_is_at_topanswers.xyz Feb 16 '23 at 17:27
  • 1
    Welcome. // Can you please do a simple test? Create a new .tex file, copy your posted code into it, compile. If it doesn't, please add what's needed to do so. Replace your code by the latter one, and it won't hurt to show a screenshot of your current result, too. // BTW: what's missing, what's the problem? Please put this into your question, too. Thanks – MS-SPO Feb 16 '23 at 17:28
  • Please also note that \tikzstyle is deprecated. You shouldn't use it! – samcarter_is_at_topanswers.xyz Feb 16 '23 at 17:29
  • 1
    Also take a look at Q9386 and why right of mightn't be the best way to place nodes. – Qrrbrbirlbel Feb 16 '23 at 19:28
  • 1
    You have already a lot working there. 1. Increase the vertical space between C and the top nodes. 2. Place a small filled circle node above=of Cblock as well as left=of Cblock. 3. Use path operations -| and |- to connect these new ones. 4. Load the arrows.meta library and use the arrow tip Circle, i.e. Circle-> with >=Latex instead of latex'. – Qrrbrbirlbel Feb 16 '23 at 19:32
  • 1
    Can you update your post with a more representative title, rather than "How can I draw this graph"? Something that future users will find more descriptive. – Werner Feb 16 '23 at 20:34

2 Answers2

9

Libraries:

  • arrows.meta for newest arrow tips (start with a capital letter).
  • positioning for right = of … instead of right of = ….
  • ext.paths.ortho for path operation r-rl and shortcuts |- and -|.
  • cd for shift left key (has advantages and disadvantages over transform canvas).

Code

\documentclass[tikz, border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{
  arrows.meta,      % for newest arrow tips (capital letters)
  positioning,      % for better placement via left=of …
  shapes.geometric, % for regular polygon
  quotes,           % for "…" syntax
  ext.paths.ortho,  % for r-rl and |-/-| shortcuts
  cd}               % for shift left
\tikzset{
  cd/.code=\pgfqkeys{/tikz/commutative diagrams}{#1}%
}
\begin{document}
\begin{tikzpicture}[
  >=Latex,
  arr/.style={->, every edge quotes/.append style={
    execute at begin node=$, execute at end node=$},
    every loop/.append style={looseness=5}},
  dot/.style={circle, fill, draw, inner sep=+.7pt},
  block/.style={draw, fill=cyan, regular polygon, minimum size=6em},
]
\node[block] (C) {C};
\node[above=of C, dot] (c-above) {};
\node[above left =of c-above, block] (A) {A};
\node[above right=of c-above, block] (B) {B};

\coordinate[left=of A] (a-left); \node[dot] (c-left) at (C-|a-left) {};

\path[arr, ortho/install shortcuts] (c-above) edge["c"'] (C) (A) edge[|-] (c-above) (B) edge[|-] (c-above) (C) edge["d"] (c-left) (c-left) edge[|-] (A) (A) edge[loop above, "\alpha"] () % loops don't need a target (B) edge[loop above, "\beta"] () (C) edge[loop below, "\gamma" name=gamma] () % name this node (B) edge[to path={ % so we can use it here r-rl ([yshift=-5mm]gamma.south) \tikztonodes % if you need nodes along the path -|(\tikztotarget) }] (c-left) (A) edge["a"] (B) [cd={shift left=2mm}] (B) edge["b"] (A) ; \end{tikzpicture} \end{document}

Output

enter image description here

Qrrbrbirlbel
  • 119,821
6

I've edited your code a little bit, and got this result !

\documentclass[tikz, border=20mm]{standalone}
\usetikzlibrary {shapes.geometric}
\tikzstyle{block} = [draw, fill=cyan, regular polygon,
minimum height=3em, minimum width=6em]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]
\begin{document}
\begin{tikzpicture}[auto, node distance=2cm,>=stealth]
\node [input, name=input] {};
\node [block] (Ablock) {A} edge [loop above] node {$\alpha$} (A);
\node [block, right of=Ablock, node distance=4cm] (Bblock) {B} edge [loop above] node {$\beta$} (A);
\draw [->] (Ablock) -- node[name=b] {a} (Bblock);
\begin{scope}[transform canvas={yshift=-2mm}]
\draw [->] (Bblock) -- node[name=a] {$b$} (Ablock);
\end{scope}
\node [output, right of=Bblock] (output) {};
\node [block, right=2cm, below=4cm] (Cblock) {C} edge [loop below] node {$\gamma$} (C);
\draw[->] (Cblock)--++(-3.75,0)node[midway, below] {$d$} node[left=0.1cm] (ac) {};
\draw[->] (ac)|-(Ablock);
\draw[->] (Ablock.south)--++(0,-1)--++(1.75,0);
\draw[->] (Bblock.south)--++(0,-1)--++(-1.75,0) node[left=0.1cm] (c) {};
\fill[cyan] (c)circle(0.05);
\fill[cyan] (ac)circle(0.05);
\draw[->] (c)--(Cblock.north) node[left, midway] {$c$};
\draw[->] (Bblock)--++(2,0)--++(0,-8)--++(-8,0)--(ac);
\end{tikzpicture}
\end{document}

enter image description here

It appears that when this code is executed in another document class, it does not produce the expected result. To resolve this issue, you have two options. Firstly, you can adjust the coordinates appropriately since everything is proportional. Alternatively, you can recompile everything described here and include it in your file using the graphicx package (As an example : \includegraphics[scale=0.75]{diagram.pdf}). This should also work.

However, I highly recommend that you take the time to understand @Qrrbrbirlbel's answer, as it is well-organized and involves redefining everything from scratch. In my answer, I have only edited your code to obtain the desired diagram.

euler_med
  • 518