3

I want to draw a flow chat like this

enter image description here

But I have no idea how to make those arrows across the box, and make the boxes larger.

\documentclass{beamer}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{collectbox}

\makeatletter
\newcommand{\mybox}{%
    \collectbox{%
        \setlength{\fboxsep}{5pt}%
        \fbox{\BOXCONTENT}%
    }%
}
\makeatother

\usetikzlibrary{arrows,
                positioning,    % <--- added
                shapes}
\usepackage{xparse}% So that we can have two optional parameters


\begin{document}
  \begin{frame}
    \begin{tikzpicture}[
            node distance = 7mm and 6mm,     % <---
            block/.style = {rectangle, draw, rounded corners, align=center},
            cloud/.style = {draw, ellipse, inner sep=1pt, align=center}, % <---
            font = \footnotesize       % <---
            ]
            % Place nodes
            \node [block, label={[anchor=east, align=center, xshift=-1ex, % <---
            font=\scriptsize\linespread{0.9}\selectfont,% <---
                text=purple]right:
                }
                ] (init) {\textbf{\underline{\large{Machine}}}\\
            \\[5ex]
            \qquad\:\mybox{Function}\qquad\:\\[6ex]
            };
            \node [cloud, left=of init] (data)
                 {\textbf{\large{Training data}}\\
                 \textbf{\large{set}}};
            \node [cloud, above right=of init.east, anchor=west] (input)  % <---
            {\textbf{\large{Input}}};     % <---
            \node [cloud, below right=of init.east, anchor=west] (output) % <--- 
                  {\textbf{\large{Output}}};
            % Draw edges
            \draw[red,-latex']  (data) -- (init);
            \draw[red,-latex']  (init) -- (data);
            \draw[magenta,-latex']  (input) -- (init.east |- input);
            \draw[cyan,-latex']  (init.east |- output) -- (output);
        \end{tikzpicture}
   \end{frame}
\end{document}
Alsace
  • 61
  • 3
    (i) your mwe (minimal working example) doesn't work (iii) dont mix 1 and l (in 1ex) , (iii) as i see, you use my answers in your question. isn't it now a time that you accept them? – Zarko Sep 25 '18 at 14:16
  • sorry that I forgot to copy my extra code. Now should be work. – Alsace Sep 25 '18 at 14:38
  • your mwe still not work. apparently you not consider my complete comment! – Zarko Sep 25 '18 at 14:42
  • I now realize what you mean by 'accept'. Sorry for my late acceptance. And it should be work now. – Alsace Sep 25 '18 at 14:52

4 Answers4

4

It took me a while to clean up a bit.

\documentclass{beamer}
\usepackage{amsmath}
\usepackage{tikz}

\usetikzlibrary{fit,% <--- added
                positioning,    
                shapes,decorations.markings}% <--- added
% https://tex.stackexchange.com/a/39282/121799
\tikzset{->-/.style={decoration={
  markings,
  mark=at position .5 with {\arrow{>}}},postaction={decorate}}}
\tikzset{-<>-/.style={decoration={
  markings,
  mark=at position .33 with {\arrow{<}},
  mark=at position .67 with {\arrow{>}}},postaction={decorate}}
}


\begin{document}
  \begin{frame}
    \begin{tikzpicture}[
            node distance = 7mm and 6mm,    
            block/.style = {rectangle, draw, rounded corners, align=center},
            cloud/.style = {draw, ellipse, inner sep=1pt, align=center}, 
            >=latex
            ]
            % Place nodes
            \node[font=\Large\bfseries]     (init)  {\underline{Machine}};
            \node[below=3em of init,draw,rounded corners] (function) {Function};
            \path ([yshift=-3em]function) coordinate (aux);
            \node[draw,fit=(init) (function) (aux)] (fit){};
            \node [cloud, left=of fit] (data)
                 {\textbf{\large{Training data}}\\
                 \textbf{\large{set}}};
            \node [cloud, above right=of fit.east, anchor=west,font=\large\bfseries] (input)  % <---
            {Input};     % <---
            \node [cloud, below right=12mm and 6mm of fit.east, anchor=west,font=\large\bfseries] (output) % <--- 
                  {Output};
            % Draw edges
            \draw[->-]  (data) -- (fit);
            \draw[red,-<>-]  (function.-160)  -- ++(0,-2mm) -| (data);
            \path (input.west) -- (function.east) coordinate[midway] (aux2);
            \path (output.west) -- (function.east) coordinate[midway] (aux3);
            \draw[magenta,->-]  (input) -| (aux2) |- ([yshift=2pt]function);
            \draw[cyan,->-] ([yshift=-2pt]function)  -| (aux3) |- (output);
        \end{tikzpicture}
   \end{frame}
\end{document}

enter image description here

2

You cannot (in an easy way) draw to your Function box since it is drawn as an \fbox. If you instead draw it as a \node it is much easier:

\documentclass{beamer}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{collectbox}

\makeatletter
\newcommand{\mybox}{%
    \collectbox{%
        \setlength{\fboxsep}{5pt}%
        \fbox{\BOXCONTENT}%
    }%
}
\makeatother

\usetikzlibrary{arrows,
                positioning,    % <--- added
                shapes}
\usepackage{xparse}% So that we can have two optional parameters


\begin{document}
  \begin{frame}
    \begin{tikzpicture}[
            node distance = 7mm and 6mm,     % <---
            block/.style = {rectangle, draw, rounded corners, align=center},
            cloud/.style = {draw, ellipse, inner sep=1pt, align=center}, % <---
            font = \footnotesize       % <---
            ]
            % Place nodes
            % \node [block, label={[anchor=east, align=center, xshift=-1ex, % <---
            % font=\scriptsize\linespread{0.9}\selectfont,% <---
            %     text=purple]right:
            %     }
            %     ] (init) {\textbf{\underline{\large{Machine}}}\\
            % \\[1ex]
            % \\[1ex]
            % \qquad\:\mybox{Function}\qquad\:\\[1ex]
            % \\[1ex]
            % \\[1ex]
            % };
            %%% ************ New stuff
            \node[draw, rounded corners,
              minimum height=35mm,
              text depth=30mm,
              minimum width=35mm] (init) {\textbf{\underline{\large{Machine}}}};
            \node[draw,inner sep=5pt] (Function) at ($(init)+(0,0.2)$) {Function};
            %%% *************
            \node [cloud, left=of init] (data)
                 {\textbf{\large{Training data}}\\
                 \textbf{\large{set}}};
            \node [cloud, above right=of init.east, anchor=west] (input)  % <---
            {\textbf{\large{Input}}};     % <---
            \node [cloud, below right=of init.east, anchor=west] (output) % <--- 
                  {\textbf{\large{Output}}};
            % Draw edges
            \draw[red,-latex']  (data) -- (init);
            %% \draw[red,-latex']  (init) -- (data);
            \draw[red,-latex] (data.south east) -| (Function.south);%% New
            \draw[magenta,-latex']  (Function.10) -- +(1.2,0) |- (input);%% Changed
            \draw[cyan,-latex'] (Function.-10) -- +(1.2,0) |- (output);%% Changed
        \end{tikzpicture}
   \end{frame}
\end{document}

enter image description here

StefanH
  • 13,823
2

enter image description here

\documentclass{beamer}
\usepackage{tikz}

\usetikzlibrary{arrows.meta,
                decorations.markings, % <--- added
                positioning,   
                shapes}

\begin{document}
\begin{frame}[fragile]   % <--- doesn't work without option "fragile" 
\frametitle{New flowchart}
\begin{center}
    \begin{tikzpicture}[
node distance = 12mm and 9mm,
block/.style = {rectangle, draw, rounded corners,
                minimum size=24mm,
                label={[anchor=north, font=\large\bfseries]north:#1}
                },
cloud/.style = {draw, ellipse, inner sep=2pt, outer sep=0pt,
                align=center, font=\large\bfseries},
  decoration = {markings,% switch on markings
                mark=at position 0.75 with {\arrow[thick]{Latex}},
                },
 line/.style = {draw=#1, semithick, postaction={decorate}, 
                },
font = \footnotesize
]
% Place nodes
\node [block=\underline{Machine}] (init)    {};
\node [draw]  (fnct) at (init.center)       {Function};
\node [cloud, left=of init] (data)          {Training\\ data set};
\node [cloud,
       above right=of init.east, anchor=west] (input)  {Input};
\node [cloud,
       below right=of init.east, anchor=west] (output) {Output};
\node [below left,xshift=1ex,text=blue] at (output.west) {prediction};
% Draw edges
\draw[line=red]     (data.330) -| (fnct.240);
\draw[line=red]     (fnct.240) |- (data.330);
\coordinate[right=of {[yshift= 1mm] fnct.east}] (aux1);
\coordinate[right=of {[yshift=-1mm] fnct.east}] (aux2);
\draw[line=purple]      (input) -| (aux1);
\draw[thick,magenta]    (aux1) -- (aux1 -| fnct.east);
\draw[line=magenta]    (fnct.east |- aux2) -| (aux2 |- output) -- (output);
\draw[line=black]   (data) -- (init);
        \end{tikzpicture}
\end{center}
\end{frame}
\end{document}

edit: arrows from input to funct has wrong direction, :-(. now this is corrected.

Zarko
  • 296,517
  • Is there any package missing? I find a lot of errors. – Alsace Sep 25 '18 at 15:46
  • ups, by accident i delete all libraries ... now added. sorry for any inconvenience. – Zarko Sep 25 '18 at 15:55
  • When I run it in a separate file, it works. However, when I copy it into my presentation file, several errors come out and I have know idea what it is. – Alsace Sep 25 '18 at 16:50
  • without knowing errors i cant say anything :-(. check if in your presentation you have all tikz libraries as are used in my answer and if the frame with this flowchart has option [fragile]. if both is true, than there is no reason that this code will not work. – Zarko Sep 25 '18 at 17:00
  • Yes both true. But – Alsace Sep 25 '18 at 17:02
  • fi-pdflatex.tex Runaway argument?

    ! File ended while scanning use of \next.

    \par <*> fi-pdflatex.tex

    I suspect you have forgotten a }', causing me to read past where you wanted me to stop. I'll try to recover; but if the error is serious, you'd better typeE' or `X' now and fix your file.

    – Alsace Sep 25 '18 at 17:03
  • fi-pdflatex.tex Emergency stop.

    <*> fi-pdflatex.tex

    *** (job aborted, no legal \end found)

    Here is how much of TeX's memory you used: 39017 strings out of 493013 762284 string characters out of 6135683 829564 words of memory out of 5000000 41745 multiletter control sequences out of 15000+600000 163013 words of font info for 90 fonts, out of 8000000 for 9000 1141 hyphenation exceptions out of 8191 70i,16n,76p,10411b,1043s stack positions out of 5000i,500n,10000p,200000b,80000s ! ==> Fatal error occurred, no output PDF file produced!

    – Alsace Sep 25 '18 at 17:03
  • do you check presence of the tikz libraries and option fragile? your errors not indicate, that is something wrong with my code. somewhere you haven't closed an expression or environment correctly. this is not caused by my code, if you copy correctly. sorry, my crystal ball is fogy, i cant see your actual code :-) – Zarko Sep 25 '18 at 17:14
0

Just for fun an option using basic code with some text management, and tikz libraries shapes.geometric, arrows.meta and positioning to obtain a result similar to the desired...

RESULT: enter image description here

MWE:

\documentclass[tikz,border=15pt]{standalone}
\usepackage[scaled]{helvet}
\usepackage{emerald}
\usepackage[T1]{fontenc}
\usetikzlibrary{shapes.geometric,arrows.meta,positioning}
\begin{document}
    \begin{tikzpicture}[
        %Environment Config
        line width=0.75pt,
        >={Straight Barb[slant=.2,angle=60:0.25cm]}
    ]
    \draw[thick] %Drawing the nodes
        node[draw,label={[anchor=north]90:\Large\sf Machine},minimum size=2.5cm](MA){\ECFAugie}
        node[draw](F){\ECFAugie Function}
        node[ellipse, draw, left=1cm of MA,minimum height=1.5cm](TD){\ECFAugie Training data}
        node[ellipse, draw, on grid, above right=1.5cm and 4cm of MA,minimum width=2cm](IN){\ECFAugie Input}
        node[ellipse, draw, on grid, below right=0.5cm and 4cm of MA,minimum height=1.2cm](OUT){\ECFAugie Output};

    \path%Finding nodes to put the arrows
    (TD) -- (MA) node[midway](temp){}
    (TD.-25) -| (F) node[pos=0.2](temp2){} node[pos=0.35](temp3){}
    (F.5)--++(1.2,0) |- (IN) node[pos=0.25](temp4){}
    (F.-5)--++(1.2,0) |-(OUT) node[pos=0.8](temp5){};

    %Drawing the arrows.
    \draw(temp.center) edge[<-] (TD) edge (MA);
    \draw[red](TD.-25) edge (temp2.center) (temp3.center) edge [<->] (temp2.center) -| (F);
    \definecolor{Myviolet}{HTML}{9E5EFC}
    \draw[Myviolet](F.5) -| (temp4.center) (temp4 |- IN) edge[->] (temp4.center) edge (IN);
    \draw[blue](F.-5)--++(1.2,0) coordinate (t1) -- (t1 |- OUT) coordinate (t2)  (temp5.center) edge[<-] (t2) edge (OUT);
    \draw[blue](t2)++(-115:10pt) node{\ECFAugie \scriptsize prediction};
    \end{tikzpicture}
\end{document}
J Leon V.
  • 11,533
  • 16
  • 47
  • This looks really cool but at least on my machine I cannot compile it, neither with pdflatex nor xelatex nor lualatex. The error is ! I can't find filefaumw8t'.`. Could you perhaps append some information or a link how to install this font, others may have the same problem. Once that works I will certainly upvote. –  Sep 26 '18 at 00:45
  • I compile it without problems pdfTeX, Version 3.14159265-2.6-1.40.19 (MiKTeX 2.9.6745 64-bit) LaTeX2e <2018-04-01> patch level 5 only following the instructions for usage in The LaTeX Font Catalogue... some other information: Augie is not part of TeX Live. – J Leon V. Sep 26 '18 at 02:59
  • I guess you have installed the font earlier. Let's see if others see our conversation. –  Sep 26 '18 at 03:08
  • That's strange, since pdf.tex only compiles with sources for latex, unlike luatex or xelatex that use system installed fonts and using the fontspec package, it's the first time I use this calligraphic font, and it was installed during compilation =================== – J Leon V. Sep 26 '18 at 03:19
  • Sure, the above error message comes when I compile with lualatex. With pdflatex I get !pdfTeX error: pdflatex (file faumw8r): Font faumw8r at 420 not found. –  Sep 26 '18 at 03:54