2

I'm trying to create a simple diagram like this:

enter image description here

With text in the nodes. Is it possible?

3
  • 2
    You need e.g. TikZ . Search on this site or look in the manual. Edit: I see, that you have tagged it with tikz-pgf - so you already know the answer to your question: Yes Aug 15, 2020 at 15:38
  • 2
    \documentclass{article} \usepackage{tikz} \usetikzlibrary{positioning} \begin{document} \begin{tikzpicture}[every node/.style={circle,draw=black,align=center}] \node(c){text}; \node(a)[above left =of c]{text} edge [->](c); \node(b)[below left =of c]{text} edge [->](c); \node(d)[right= of c]{text} edge [<-] (c); \end{tikzpicture} \end{document} should serve as a point to start from.
    – leandriis
    Aug 15, 2020 at 15:41
  • Thanks a lot @leandriis
    – Michael
    Aug 15, 2020 at 16:15

4 Answers 4

8

There is another approach that doesn't require you to code everything by yourself. That is to use Mathcha, an online graphics tool. (Although I like the Tikz library, it is sometimes very frustrating and time-consuming for not-so-advanced users like me. But now I use Mathcha all the time and it is great!) (This is not an ad.)

example of flowchart as required by OP

Now if you click on the drop-down menu to the right of the "Tikz" on top, you will have an option of "copy Tikz to clipboard" and then you can paste that code into your editor under "figure" environment.

\documentclass[letterpaper,12pt]{article}
\usepackage{tikz}
\begin{document}
\begin{figure}{h}
\centering


\tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt        

\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
%uncomment if require: \path (0,300); %set diagram left start at 0, and has height of 300

%Shape: Ellipse [id:dp012121102068190615] 
\draw   (114,90) .. controls (114,78.95) and (129.67,70) .. (149,70) .. controls (168.33,70) and (184,78.95) .. (184,90) .. controls (184,101.05) and (168.33,110) .. (149,110) .. controls (129.67,110) and (114,101.05) .. (114,90) -- cycle ;
%Shape: Ellipse [id:dp45524231368736] 
\draw   (109,201) .. controls (109,189.95) and (124.67,181) .. (144,181) .. controls (163.33,181) and (179,189.95) .. (179,201) .. controls (179,212.05) and (163.33,221) .. (144,221) .. controls (124.67,221) and (109,212.05) .. (109,201) -- cycle ;
%Shape: Ellipse [id:dp19409850525124472] 
\draw   (271,144) .. controls (271,132.95) and (286.67,124) .. (306,124) .. controls (325.33,124) and (341,132.95) .. (341,144) .. controls (341,155.05) and (325.33,164) .. (306,164) .. controls (286.67,164) and (271,155.05) .. (271,144) -- cycle ;
%Shape: Ellipse [id:dp9788068233347484] 
\draw   (441,145) .. controls (441,133.95) and (456.67,125) .. (476,125) .. controls (495.33,125) and (511,133.95) .. (511,145) .. controls (511,156.05) and (495.33,165) .. (476,165) .. controls (456.67,165) and (441,156.05) .. (441,145) -- cycle ;
%Straight Lines [id:da023367382048318674] 
\draw    (184,90) -- (269.3,142.95) ;
\draw [shift={(271,144)}, rotate = 211.82999999999998] [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=0.75]    (10.93,-3.29) .. controls (6.95,-1.4) and (3.31,-0.3) .. (0,0) .. controls (3.31,0.3) and (6.95,1.4) .. (10.93,3.29)   ;
%Straight Lines [id:da8723958880825298] 
\draw    (179,201) -- (269.3,145.05) ;
\draw [shift={(271,144)}, rotate = 508.22] [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=0.75]    (10.93,-3.29) .. controls (6.95,-1.4) and (3.31,-0.3) .. (0,0) .. controls (3.31,0.3) and (6.95,1.4) .. (10.93,3.29)   ;
%Straight Lines [id:da1764663418338821] 
\draw    (341,144) -- (439,144.98) ;
\draw [shift={(441,145)}, rotate = 180.57] [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=0.75]    (10.93,-3.29) .. controls (6.95,-1.4) and (3.31,-0.3) .. (0,0) .. controls (3.31,0.3) and (6.95,1.4) .. (10.93,3.29)   ;




\end{tikzpicture}

\end{figure}
\end{document}
4

Really simple with the psmatrix environment:

\documentclass[svgnames]{article}

\usepackage{pst-node}

\begin{document}

\begin{psmatrix}[rowsep=0cm, colsep=2.5cm]
\psDefBoxNodes{O1}{\psovalbox{\rule[-0.3cm]{0pt}{0.8cm}Some text}} \\
& \psDefBoxNodes{A}{\pscirclebox{Short text}} & \psDefBoxNodes{B}{\pscirclebox{ $E = mc^2$}} \\
\psDefBoxNodes{O2}{\psovalbox{\rule[-0.3cm]{0pt}{0.8cm}Silly text}}
\end{psmatrix}
\psset{arrows=->, arrowinset=0.15, linecolor=Crimson, nodesepA=4pt, nodesepB=1cm}
\ncline{O1:Cr}{A:C}
\ncline{O2:Cr}{A:C}
\ncline[nodesepB=4pt]{A:Cr}{B:Cl}

\end{document} 

enter image description here

3

Simple with the use of matrix -- each & is a column separator and each \\ is a row separator

The row and column separation can be pre-defined with the help of

[row sep=2cm,column sep=2cm]

The shape of the nodes can be defined as ellipse or circle using styles -- in the case of ellipse the minimum height and minimum width need to be different or else you end up with a circle

Each style can be given a different name for convenience -- at present used as terminal for ellipse -- in the code the style can be called by its name \node[terminal] and an ellipse will be auto created

Font is set to italics with the help of font=\itshape -- in case not required it can be deleted

enter image description here

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary {shapes,matrix}

\begin{document}
\begin{tikzpicture}[
terminal/.style={
    % The shape:
    ellipse,
    % The size:
    minimum width=2cm,
    minimum height=1cm,
    % The border:
    very thick,
    draw=blue,
    % Font
    font=\itshape,
},
]
\matrix[row sep=2cm,column sep=2cm] {%
    % First row:
    \node [terminal](p1) {Some text};   & & & \\
    %Second row
        &\node [terminal](p3) {More text};& & \node [terminal](p4) {And more text}; \\
    % Third row:
    \node [terminal](p2) {Some text}; & & &\\
};
\draw   (p1) edge [->,>=stealth,shorten <=2pt, shorten >=2pt,thick] (p3)
        (p2) edge [->,>=stealth,shorten <=2pt, shorten >=2pt, thick] (p3);
\draw   (p3) edge [->,>=stealth,shorten <=2pt, shorten >=2pt,thick] (p4);       
\end{tikzpicture}
\end{document}
3

It is possible, also, to use a combination of TikZ and tikz-cd as in the image below.

enter image description here

\documentclass[a4paper,12pt]{article}
\usepackage{tikz-cd}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzcd}[row sep=-.1cm, column sep=1cm]
\tikz \path (0,0) node(a) [ellipse,draw] {1 ellipse};
\arrow[rrd] &  &  &   \\
&  & \tikz \path (0,0) node(b) [ellipse,draw] {3 ellipse};
\arrow[r] & \tikz \path (0,0) node(c) [ellipse,draw] {4 ellipse}; & \\
\tikz \path (0,0) node(d) [ellipse,draw] {2 ellipse};
\arrow[rru] & & &  
\end{tikzcd}
\end{document}

Addendum: Above MWE can be written also without nesting tikz pictures of ellipses in tikz-cd diagram as follows:

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{shapes.geometric}
\usepackage{amsmath}

\begin{document}
\[
    \begin{tikzcd}[sep=large,
cells={nodes={ellipse, draw, thick, inner xsep=0pt}},
every arrow/.append style = {-stealth, shorten > = 2pt, shorten <=2pt},
                    ]
\text{1. ellipse} \ar[rd]  
    &   &                                           \\
    & \text{3. ellipse} \ar[r] & \text{4. ellipse}  \\
\text{2. ellipse} \ar[ru]  &   &               
    \end{tikzcd}
\]
\end{document}

The result is almost the same as before, however, the code is now much shorter (and concise) :-)

enter image description here

5
  • 1
    (i) tikz-cd is based on tikz, so it load tikz and you not need to load it again, (ii) nodes style defined in tikz you can define directly in tikz-cd, for example as cells={nodes={ellipse, draw, inner xsep=0pt}},, anyway, +1
    – Zarko
    Oct 17, 2020 at 20:12
  • @Zarko Hi, very kind...you know that I am a scarce user. :-) Thank yoy very much for your suggestion. If you prefer you are authorized to edit or add into my answer.
    – Sebastiano
    Oct 17, 2020 at 20:15
  • @Zarko Naaaaaaa it is perfect!!! :-)
    – Sebastiano
    Oct 17, 2020 at 20:22
  • 1
    \tikz is enough without the need for \begin{tikzpicture} and \end{tikzpicture} inside tikz-cd. For example, \tikz \path (0,0) node(a) [ellipse,draw] {1 ellipse}; \arrow[rrd] & & &
    – Diaa
    Oct 17, 2020 at 21:31
  • @Diaa Thank you very much for your cooperation. Now I will edit my first answer. +1
    – Sebastiano
    Oct 17, 2020 at 21:36

You must log in to answer this question.

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