I have the following LaTex code:

% !TEX TS-program = pdflatex
% !TEX encoding = UTF-8 Unicode
\documentclass[14pt, a4paper]{article} % use larger type; default would be 10pt
\usetikzlibrary{shapes.geometric, arrows}


\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=blue!50]

\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=red!50]

\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=gray!50]

\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!50]

\tikzstyle{loop} = [rectangle split, rectangle split parts=2,draw, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=gray!50]

\tikzstyle{arrow} = [thick,->,>=stealth]

    {\textbf{Задача 1.}}
    Схема алгоритма:
        \begin{tikzpicture}[node distance=2cm]
            \node (start) [startstop] {Начало};
            \node (input) [io, below of=start] {Ввод n};
            \node (ds1) [decision, below of=input, yshift=-0.4cm]{n = 0?};
            \node (y-case) [process, right of=ds1, xshift=2cm]{pow = 1};
            \node (while) [loop, below of=ds1, yshift=-0.4cm]{ 
                \nodepart{one} While n > 0 
                         n = n //10 \\
                         pow = pow +1 \\
            \node (output) [io, below of=while, ]{Вывод pow};
            \node (stop) [startstop, below of=output] {Конец программы};
            \draw[arrow] (start) -- (input);
            \draw[arrow] (input) -- (ds1);
            \draw[arrow] (ds1) -- node[anchor=south]{Yes}(y-case);
            \draw[arrow] (y-case) |- (while);
            \draw[arrow] (ds1) -- node[anchor=east]{No}(while);
            \draw[arrow] (while) -- (output);
            \draw[arrow] (output) -- (stop);


And it's built to this: Tikz program flow

How can I define the behavior of the "NO" arrow to make it go from the left corner of the diamond block (now it goes from the bottom corner)?

  • 2
    unrelated to your question but the comment in your first line is wrong article does not have a 14pt option – David Carlisle Nov 11 '20 at 19:22
  • 1
    Just place a node or coordinate to the left of the diamond. The \draw command will let the arrow start from the nearest point of the diamond and go in a straight line to the target node. – gernot Nov 11 '20 at 19:26
  • @DavidCarlisle yeah, thanks. Just misclick. – DKay Nov 11 '20 at 20:02
  • @gernot thank you I'll try it. – DKay Nov 11 '20 at 20:02

Like this?

enter image description here

\documentclass[12pt, a4paper]{article} 

                chains,       % new
                positioning,  % new
                quotes,       % new

\oddsidemargin=-15.4mm % for this settings is better to use >"geometry" package

\tikzset{FlowChart/.style={  % <--- corrected, new
     base/.style = {draw,
                    minimum width=3cm, minimum height=1cm, align=center,
                    outer sep=0pt},
startstop/.style = {base, rounded corners, fill=blue!30},
  process/.style = {base, fill=orange!30},
 decision/.style = {base, diamond, aspect=1.3, fill=green!30},
       io/.style = {base, trapezium, trapezium stretches body,
                    trapezium left angle=70, trapezium right angle=110,
                    text width =\pgfkeysvalueof{/pgf/minimum width} - 2*\pgfkeysvalueof{/pgf/inner xsep}
     loop/.style = {base, rectangle split, rectangle split parts=2,
    arrow/.style = {thick,-Triangle},
% suspend
suspend join/.code={\def\tikz@after@path{}}
        }% end of tikzset

    \textbf{Задача 1.}  \\
    Схема алгоритма:    \\
base/.append style = {on chain, join=by arrow},
    node distance = 5mm and 7mm,
      start chain = A going below
% nodes in chain
\node (start)   [startstop] {Начало};
\node (input)   [io]        {Ввод n};
\node (ds1)     [decision]  {n = 0?};
\node (while)   [loop,
                 suspend join]  {\nodepart{one} While n > 0
                                 \nodepart{two} \begin{tabular}{cc}
                                                     n = n //10     \\
                                                     pow = pow +1   \\
\node (output)  [io]        {Вывод pow};
\node (stop)    [startstop] {Конец программы};
% right branch
\node (y-case) [process,right=of ds1,
                suspend join]   {pow = 1};
\draw[arrow]    (ds1) to ["Yes"] (y-case);
\draw[arrow]    (y-case) |- (while);
\draw[arrow]    (ds1.west) to ["No" ']  ++ (-1,0) |- (while); % new

Note: In above MWE are in comparison to yours changed the following:

  • for the picture elements styles is used tikset instead of deprecated tikzstyle
  • fo positioning of nodes is used syntax defined in positioning library (observe right=of ds1 instead of right of=ds1)
  • nodes are organised in chain, which simplify code and make it shorter and more clear
  • vertical connection lines are drawn by join macro defined in the chains macro
  • join line between last node in the main branch and node right of decision node is interrupted by style code suspend join

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.