1

I have a very long diagram and I want it to be displayed in one frame

\begin{frame}

\newcommand{\rect}[4]{\node[draw,minimum height=1cm,minimum width=4cm] (#3) at (#1,#2) {\begin{minipage}{3.8cm}\centering #4\end{minipage}};} \newcommand{\prect}[3]{\node[draw,minimum height=1cm,minimum width=1.8cm] (#3) at (#1,#2) {$#3$};} \newcommand{\diam}[4]{\node[draw,diamond,aspect=3,minimum width=4cm] (#3) at (#1,#2) {\smash{\begin{minipage}[1pt]{3.8cm}\centering #4\end{minipage}}};}

\begin{tikzpicture}[x=-.350cm,y=-.350cm] % \foreach \x/\y/\k in {0/0/A, 0/5/B, 0/10/C, %0/15/D, % on retire D de la liste % 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} % } \tikzstyle{P}=[diamond, aspect=3,thick, draw,minimum width=2.5cm] \tikzstyle{R}=[diamond, aspect=2,thick, draw,minimum width=2.5cm] \tikzstyle{N}=[diamond, aspect=3,thick, draw,minimum width=2.5cm]

\nodedraw,minimum width=4cm at (0,0){a}; \nodedraw,minimum width=4cm at (0,5){a}; \nodedraw,minimum width=4cm at (0,10){a}; % on ajoute le node D avec son texte long \nodedraw,minimum width=4cm at (0,15){a}; \nodedraw,minimum width=4cm at (0,20){a}; \nodedraw,text width=4cm at (0,30){a}; \nodedraw= blue,fill=blue!30,text width=4cm at (16,25){Se}; \nodedraw,text width=4cm at (16,30){Add }; % \nodedraw,minimum width=4cm at (16,35){all nodes visited}; \nodedraw,minimum width=4cm at (16,40){Return to the depot}; \nodedraw= blue,fill=blue!10,text width=4cm at (32,25){a}; \nodedraw= blue,fill=blue!10,minimum width=4cm at (32,30){a}; \nodedraw= blue,fill=blue!10,text width=4cm at (32,40){a};

       \node[P](P) at (0,25){a};
       \node[R](R) at (0,35){Stopping criterion?};
       \node[N](N) at (16,35){a};

% \foreach \x/\y/\k in {0/25/P, 0/35/R} { % \diam{\x}{\y}{\k} % } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \nodedraw= blue,fill=blue!10,text width=4cm at (35.1,35){a}; \nodedraw= blue,fill=blue!10,text width=1cm at (27,35){a};

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%% \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); \draw[thick,>=latex,->] (L.south) -- (32,43) -- (25,43) -- (25,30) --(25,30)--(M.west); \end{tikzpicture}

\end{frame}

Sigur
  • 37,330
farah
  • 23

2 Answers2

1
  • you are missing the fragile frame option. Without it you'll get in trouble with all the # you use in your definitions

  • you could use something like scale=0.5,transform shape to scale down your image, but the result might not be readable. Consider changing the layout of your flowchart to better fit the aspect ratio of your slide

  • \tikzstyle is deprecated


\documentclass{beamer}

\usepackage{tikz} \usetikzlibrary{shapes}

\begin{document}

\begin{frame}[fragile]

\newcommand{\rect}[4]{\node[draw,minimum height=1cm,minimum width=4cm] (#3) at (#1,#2) {\begin{minipage}{3.8cm}\centering #4\end{minipage}};} \newcommand{\prect}[3]{\node[draw,minimum height=1cm,minimum width=1.8cm] (#3) at (#1,#2) {$#3$};} \newcommand{\diam}[4]{\node[draw,diamond,aspect=3,minimum width=4cm] (#3) at (#1,#2) {\smash{\begin{minipage}[1pt]{3.8cm}\centering #4\end{minipage}}};}

\begin{tikzpicture}[x=-.350cm,y=-.350cm,scale=0.5,transform shape] % \foreach \x/\y/\k in {0/0/A, 0/5/B, 0/10/C, %0/15/D, % on retire D de la liste % 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} % } \tikzset{P/.style={diamond, aspect=3,thick, draw,minimum width=2.5cm}} \tikzset{R/.style={diamond, aspect=2,thick, draw,minimum width=2.5cm}} \tikzset{N/.style={diamond, aspect=3,thick, draw,minimum width=2.5cm}}

\nodedraw,minimum width=4cm at (0,0){a}; \nodedraw,minimum width=4cm at (0,5){Create a}; \nodedraw,minimum width=4cm at (0,10){x}; % on ajoute le node D avec son texte long \nodedraw,minimum width=4cm at (0,15){s}; \nodedraw,minimum width=4cm at (0,20){s}; \nodedraw,text width=4cm at (0,30){s }; %$E(L_{k})$ of PTSPD for each and \nodedraw,text width=4cm at (16,20){s}; \nodedraw= blue,fill=blue!30,text width=4cm at (16,25){s}; \nodedraw,text width=4cm at (16,30){A}; % \nodedraw,minimum width=4cm at (16,35){as}; \nodedraw,minimum width=4cm at (16,40){Return }; \nodedraw= blue,fill=blue!10,text width=4cm at (32,25){a}; \nodedraw= blue,fill=blue!10,minimum width=4cm at (32,30){a}; \nodedraw= blue,fill=blue!10,text width=4cm at (32,40){a};

       \node[P](P) at (0,25){a};
       \node[R](R) at (0,35){Stopping criterion?};
       \node[N](N) at (16,35){aa};

% \foreach \x/\y/\k in {0/25/P, 0/35/R} { % \diam{\x}{\y}{\k} % } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \nodedraw= blue,fill=blue!10,text width=4cm at (35.1,35){a}; \nodedraw= blue,fill=blue!10,text width=1cm at (27,35){a};

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%% \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); \draw[thick,>=latex,->] (L.south) -- (32,43) -- (25,43) -- (25,30) --(25,30)--(M.west); \end{tikzpicture}

\end{frame}

\end{document}

enter image description here

farah
  • 23
  • if it wants to like a little help on the red arrow and that is next, they have entangled – farah Jan 24 '23 at 15:22
  • There isn't enough space to de-tangle them. Change the layout of your diagram to spread out the three columns of nodes. This way there will be more space for your arrows (with all your hard coded coordinates, it is a pain to move them). – samcarter_is_at_topanswers.xyz Jan 24 '23 at 15:26
  • @farah Consider going back to your earlier question and use the solution https://tex.stackexchange.com/a/666668/36296 This would make your code much easier to adapt to other page geometries. – samcarter_is_at_topanswers.xyz Jan 24 '23 at 15:29
1

For fun and joy, but someone may liked ...

  • new shapes for nodes (shape for decision node is designed by @Qrrbrbirlbel)
  • added colors to nodes,
  • use relative positioning
  • for orthogonal arrow is used ext.paths.ortho, library
  • main branch is in chain
  • no scaling
  • text area in frame is widened by use adjustwidth of changepage package
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,
                ext.paths.ortho,  % -|- and |-| path operations
                positioning,
                shapes}
\usepackage{changepage}

\begin{document} \begin{frame}[fragile] \begin{adjustwidth}{-2em}{-1em} \centering \begin{tikzpicture}[auto, node distance = 2.8mm and 4mm, start chain = going below, arr/.style = {semithick,-{Stealth[scale=0.8]}}, base/.style = {draw=#1, semithick, fill=#1!25, text width=22mm, minimum height=5mm, align=center, inner sep=3pt, font=\tiny\linespread{0.84}\selectfont, on chain }, be/.style = {% BeginEnd base=red, text width=#1, rounded corners}, be/.default = 22mm, if/.style = {% decision node: https://tex.stackexchange.com/questions/661461 base=teal, align=left, label={[D=teal]north east:}}, D/.style = {diamond, draw=#1, fill=#1!50, inner sep=1mm, anchor=center}, lbl/.style = {inner sep=2pt, font=\tiny, text=black!75}, ra/.style = {label={[lbl, anchor=south west]east:#1}}, % right above rb/.style = {label={[lbl, anchor=north west]east:#1}}, % right bbelo la/.style = {label={[lbl, anchor=north east]west:#1}}, % lrft above lb/.style = {label={[lbl, anchor=south east]west:#1}}, % left below bl/.style = {label={[lbl, anchor=north west]south:#1}}, % below lrfz br/.style = {label={[lbl, anchor=north west]south:#1}}, % below right pc/.style = {% ProCess base=#1}, pc/.default = orange, px/.style args = {#1/#2}{% ProcessExtend base=#1, text width=#2}, % off chain/.code={\def\tikz@lib@on@chain{}} % <== defined interruption of chain ] %% branche principale, les nœuds sont en chaîne \begin{scope}[nodes={join=by arr}] \node[be] (A) {Initialisation of ACO parameters}; \node[pc] (B) {Create $m$ ants}; \node[pc] (C) {Place $m$ ants on the depot node}; \node[pc] (D) {Ants start moving from depot}; \node[pc] (E) {For each ant $k$ in colony:}; % \node[if, br=Yes?] (F) {Do this for all ants}; % \node[pc] (G) {Update pheromone level}; % \node[if, br=Yes, rb=No] (H) {Stopping criterion?}; % \node[be=11mm, below=11mm of H] (End) {End}; \end{scope}

%% près de la branche gauche \node[off chain, pc, left=of E] (I) {Mark all nodes as unvisited}; \node[pc=cyan] (J) {Select next node using transition rule};

\node[pc] (K) {Add selected node to route and mmark it as visited}; \begin{scope}[nodes={join=by arr}] % \node[if, rb=No, br=Yes] (L) {all nodes visited}; % \node[pc] (M) {Return to the depot}; \end{scope} %% branche extrême gauche \begin{scope}[nodes={off chain}] \node[pc=blue, left=0mm and 13mm of J]
(N) {Generate a uniform random $P_{\mathrm{now}}\in[0,1]$, $P_{\mathrm{Levy}}\in[0,1]$}; % \node[if=blue, la=Yes, rb=No, below=of N] (O) {$P_{\mathrm{Levy}}\geq P_{\mathrm{threshold}}$}; % \node[px=blue/30mm, below left=of O.south]
(P) {$P_{\mathrm{new}}= 1-A \ast \frac{1-P_{\mathrm{levy}}}{1-P_{\mathrm{threshold}}\ast P_{\mathrm{now}}}$}; \node[px=blue/15mm, below right=of O.south]
(Q) {$P_{\mathrm{new}}=P_{now}$}; \node[pc=blue, below=of P.south -| O]
(R) {The next node be selected using $P_{\mathrm{new}}$ from candidate liste}; \end{scope}

%% flèches, non incluses dans la macro de "join" \foreach \m/\n in {I/J, J/N, N/O} \draw[arr] (\m) -- (\n);

\draw[arr] (O) -| (P); \draw[arr] (O) -| ([xshift=4mm] Q.north); \draw[arr] (P) |- (R); \draw[arr] ([xshift=4mm] Q.south) |- (R);

\draw[arr] (R.south) -- ++ (0,-0.5) -|- [distance=23mm] (K); \draw[arr] (L.east) -|- [distance=-3mm] (J); \draw[arr] (H.east) -|- [distance=-5mm] (B);

\draw[arr, red] (M.south) -- ++ (0,-0.5) node[below] {go to?}; \end{tikzpicture} \end{adjustwidth} \end{frame} \end{document}

enter image description here

Addendum:
I estimate that more clear flowchart can be obtained, if both left branches are merged in one with beginning near top of main branch. With such organized flowchart is more evident, where should interconnections arrows. However, I'm not sure, if they are really there as shown below.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                calc, chains,
                ext.paths.ortho,  % -|- and |-| path operations
                positioning,
                shapes}
\usepackage{changepage}

\begin{document} \begin{frame}[fragile] \begin{adjustwidth}{-2em}{-1em} \centering \begin{tikzpicture}[auto, node distance = 2.8mm and 24mm, start chain = going below, arr/.style = {semithick,-{Stealth[scale=0.8]}}, base/.style = {draw=#1, semithick, fill=#1!25, text width=22mm, minimum height=4mm, align=center, inner sep=3pt, font=\tiny\linespread{0.84}\selectfont, on chain }, be/.style = {% BeginEnd base=red, text width=#1, rounded corners}, be/.default = 22mm, if/.style = {% decision node: https://tex.stackexchange.com/questions/661461 base=teal, align=left, label={[D=teal]north east:}}, D/.style = {diamond, draw=#1, fill=#1!50, inner sep=1mm, anchor=center}, lbl/.style = {inner sep=2pt, font=\tiny, text=black!75}, ra/.style = {label={[lbl, anchor=south west]east:#1}}, % right above rb/.style = {label={[lbl, anchor=north west]east:#1}}, % right bbelo la/.style = {label={[lbl, anchor=north east]west:#1}}, % lrft above lb/.style = {label={[lbl, anchor=south east]west:#1}}, % left below bl/.style = {label={[lbl, anchor=north west]south:#1}}, % below lrfz br/.style = {label={[lbl, anchor=north west]south:#1}}, % below right pc/.style = {% ProCess base=#1}, pc/.default = orange, px/.style args = {#1/#2}{% ProcessExtend base=#1, text width=#2}, % off chain/.code={\def\tikz@lib@on@chain{}} % <== defined interruption of chain ] %% branche principale, les nœuds sont en chaîne \begin{scope}[nodes={join=by arr}] \node[be] (A) {Initialisation of ACO parameters}; \node[pc] (B) {Create $m$ ants}; \node[pc] (C) {Place $m$ ants on the depot node}; \node[pc] (D) {Ants start moving from depot}; \node[pc] (E) {For each ant $k$ in colony:}; % \node[if, br=Yes?, lb=No?] (F) {Do this for all ants}; % \node[pc] (G) {Update pheromone level}; % \node[if, br=Yes, rb=No] (H) {Stopping criterion?}; \node[be=11mm, below=11mm of H] (end) {End}; \end{scope}

%% près de la branche gauche \node[off chain, pc, left=of $(A.south west)!0.5!(B.south west)$]
(I) {Mark all nodes as unvisited}; \begin{scope}[nodes={join=by arr}] \node[pc=cyan] (J) {Select next node using transition rule}; \node[pc=blue] (K) {Generate a uniform random $P_{\mathrm{now}}\in[0,1]$, $P_{\mathrm{Levy}}\in[0,1]$}; % \node[if=blue, la=Yes, rb=No] (L) {$P_{\mathrm{Levy}}\geq P_{\mathrm{threshold}}$}; % \end{scope}

  \begin{scope}[off chain]

\node[px=blue/40mm, below left=3mm and 8mm of L.south]
(M) {$P_{\mathrm{new}}= 1-A \ast \frac{1-P_{\mathrm{levy}}}{1-P_{\mathrm{threshold}}\ast P_{\mathrm{now}}}$}; \node[px=blue/15mm, below right=3mm and 8mm of L.south]
(N) {$P_{\mathrm{new}}=P_{now}$}; \node[pc=blue, below=of M.south -| J]
(O) {The next node be selected using $P_{\mathrm{new}}$ from candidate liste}; \end{scope}

  \begin{scope}[nodes={join=by arr}]

\node[pc] (P) {Add selected node to route and mmark it as visited}; % \node[if, rb=No, br=Yes] (Q) {All nodes visited?}; % \node[pc] (R) {Return to the depot}; \end{scope}

%% branche extrême gauche \draw[arr] (L) -| (M); \draw[arr] (L) -| (N); \draw[arr] (M) |- (O); \draw[arr] (N) |- (O);

\draw[arr] (Q.east) -|- [distance=-17mm] (J); \draw[arr] (F.west) -|- [distance=5mm] (I); \draw[arr] (H.east) -|- [distance=-5mm] (B); \end{tikzpicture} \end{adjustwidth} \end{frame} \end{document}

enter image description here

Zarko
  • 296,517
  • Text in nodes I took from @samcarter_is_at_topanswers.xyz answer. It is not clear, which nodes are interconnected with arrows. Some connection seem pretty unlogical. So, OP should clarify this, if like to have more complete answer. – Zarko Jan 24 '23 at 22:41