-3

my question is when I replace the alphabet with a phrase gives me the error out of a compilation

\documentclass{article}

\usepackage{tikz} \usetikzlibrary{shapes.geometric} \usepackage[a4paper,margin=1.5cm]{geometry} \usepackage{amsmath,amsfonts} \begin{document}

%\newcommand{\boite}[3]{\draw (#1,#2) rectangle (#1+12,#2+3); %\node at (#1+6,#2+1.5) {#3};}

\newcommand{\rect}[3]{\node[draw,minimum height=1cm,minimum width=4cm] (#3) at (#1,#2) {$#3$};} \newcommand{\prect}[3]{\node[draw,minimum height=1cm,minimum width=1.8cm] (#3) at (#1,#2) {$#3$};} \newcommand{\diam}[3]{\node[draw,diamond,minimum height=1.5cm,minimum width=4cm] (#3) at (#1,#2) {$#3$};}

\begin{tikzpicture}[x=-.375cm,y=-.375cm] \foreach \x/\y/\k in {0/0/A, 0/5/B, 0/10/C, 0/15/D, 0/20/E, 0/30/Q, 16/20/F, 16/25/G, 16/30/M, 16/35/N, 16/40/O, 32/25/H, 32/30/I, 32/40/L } { \rect{\x}{\y}{\k} } \foreach \x/\y/\k in {0/25/P, 0/35/R} { \diam{\x}{\y}{\k} } \foreach \x/\y/\k in {35.1/35/J, 28.9/35/K} { \prect{\x}{\y}{\k} } \node[draw,minimum height=1cm,minimum width=4cm] (End) at (0,45) {End}; \foreach \m/\n in {A/B, B/C, C/D, D/E, E/P, E/F, P/Q, Q/R, F/G, G/H, H/I, J/L, K/L, M/N} { \draw[thick,>=latex,->] (\m)--(\n); } \foreach \m/\n in {I/J, R/End, N/O} { \draw[thick,>=latex,->] (\m) -- (\n) node[midway,above,sloped]{Yes}; } \foreach \m/\n in {I/K} { \draw[thick,>=latex,->] (\m) -- (\n) node[midway,above,sloped]{No}; } \draw[red,thick,>=latex,->] (R.west) --++ (2,0) node[midway,above]{No} --++ (0,-30) -- (B); \draw[thick,>=latex,->] (N.east) --++ (-2,0) node[midway,above]{No} --++ (0,-10) -- (G.east); \draw[thick,>=latex,->] (O.south) -- (16,43) -- (8,43) -- (8,25) --(8,25)--(P.west); \end{tikzpicture}

\end{document}

farah
  • 23
  • 3
    Welcome to TeX SE. What have you tried so far? This is not a "do it for me" website. – Alain Remillard Nov 25 '22 at 16:04
  • Maybe helpful. https://www.overleaf.com/learn/latex/LaTeX_Graphics_using_TikZ%3A_A_Tutorial_for_Beginners_(Part_3)%E2%80%94Creating_Flowcharts – Dr. Manuel Kuehner Nov 25 '22 at 16:44
  • For the record: I did not downvote the question. In addition, I was under the impression that "-1" is enough symbolism for a new contributor. – Dr. Manuel Kuehner Nov 25 '22 at 20:27
  • ok thanks a lot for your answer – farah Nov 27 '22 at 15:31
  • 1
    Hi, would you mind translating the French text to English? – Torbjørn T. Nov 27 '22 at 15:48
  • sorry my question is when I replace the alphabet with a phrase gives me the error out of a compilation – farah Nov 27 '22 at 16:28
  • To fix the error in the current code, in the first \foreach loop replace 32/40/L } with 32/40/L}, i.e. remove the space before the }. But I take it you've replaced the letters with text. I don't think I can guess exactly what causes the error in that case, I wonder if it might depend on what kind of text you've used. Can you add one example? I.e. replace one of the letters with text that causes an error. – Torbjørn T. Nov 27 '22 at 17:37
  • if you replace alphabet with some text, you should do this at all occurence where this alphabet is used as node name. BTW, structure of your flowchart is no logica or it contain errors. For example, it can be concluded that nodes I and N are decision nodes (diam), strange is decision node P with two inputs and one output ... etc. – Zarko Nov 27 '22 at 18:11

1 Answers1

1

To my opinion your approach to draw flowchart doesn't lead to clear flowchart structure. With use of chains package and its macro join, define nodes style instead of define new commands gives (to my opinion) better result, which cannot has problems with nodes names and thair contents.

As starting point can serve the following (incomplete MWE, I can't complete it since I do not figured out what flow chart present):

\documentclass{article}
\usepackage[a4paper,margin=1.5cm]{geometry}
\usepackage{amsmath,amsfonts}

\usepackage{tikz} \usetikzlibrary{arrows.meta, chains, quotes, shapes.geometric}

\begin{document} \begin{tikzpicture}[%x=-.375cm,y=-.375cm, auto, node distance = 10mm and 20mm, start chain = A going below, arr/.style = {-{Stealth[scale=2]}}, D/.style = {draw,diamond,aspect=2, minimum width=4cm}, N/.style = {draw,minimum height=1cm,minimum width=4cm} ] \foreach \i/\j/\k in {N/A/text A, N/B/text B, N/C/text C, N/D/text D, N/E/text E, D/P/text P, N/Q/text Q, D/R/text R} \node (\j) [\i, on chain, join=by arr] {\k};

\node (end)[N, below=22mm of R] {End}; % \draw[arr] (R.west) to["No" '] ++ (-0.7,0) |- (B); \draw[arr] (R) to["Yes" ] (end); %% middle branch \node (F) [N, left=of E] {text F}; \node (G) [N, below=of F] {text G}; \node (M) [N, below=of G] {text M}; \chainin (M); % \draw[arr] (E) -- (F); \draw[arr] (F) -- (G); \foreach \i/\j/\k in {D/N/text N, N/O/text O} \node (\j) [\i, on chain, join=by arr] {\k}; % \draw[arr] (N.east) to["No" '] ++ (0.7,0) |- (G); \path (N) to ["Yes"] (O); %% left branch )(left to you) \node (H) [N, left=of G] {text H}; \draw[arr] (G) -- (H); % etc \end{tikzpicture} \end{document}

As you can observe, proposed flowchart code is also much shorter in comparison to the part of your code which reproduce the following image:

enter image description here

Zarko
  • 296,517
  • It worked very well, but for very long sentences, the rectangle enters the edges of the other rectangles – farah Nov 27 '22 at 21:04
  • @farah, defined nodes styles reproduce your commands. Due to lack of information what are really nodes contes are, I was not able appropriate define nodes style. For start replace option minimum width=... with option text width=..., align=center,. Some ideas, how you can draw a complex flowcharts you can see in https://tex.stackexchange.com/questions/661461/flowchart-with-overlapping-of-the-rows ... – Zarko Nov 27 '22 at 22:02