6

I created the follow (basic) flow chart:

enter image description here

with the following code:

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,  decorations.pathreplacing,decorations.pathmorphing,shapes,  matrix,shapes.symbols}

\begin{document}
\tikzstyle{block} = [rectangle, draw, text width=10em, text centered, rounded      corners, minimum height=3em]
\begin{tikzpicture}
 [node distance=1.35cm,
 start chain=going below,]
\node (n1) at (0,0) [block]  {General framwork};
\node (n2) [block, below of=n1] {Literature study};
\node (n3) [block, below of=n2] {Data-analysis};
\node (n4) [block, below of=n3] {Model set-up (SB \& NH)};
\node (n5) [block, below of=n4] {Simulations};
\node (n6) [block, below of=n5] {Sensitivity analysis};
\node (n7) [block, below of=n6] {Model update};
\node (n8) [block, below of=n7] {Conclusions and recommendations};
% Connectors
\draw [->] (n1) -- (n2);
\draw [->] (n2) -- (n3);
\draw [->] (n3) -- (n4);
\draw [->] (n4) -- (n5);
\draw [->] (n5) -- (n6);
\draw [->] (n6) -- (n7);
\draw [->] (n6) -- (n7);
\draw [->] (n7) -- (n8);
\draw [->] (n7.east) -| ++(1,0) |- (n6.east);
\draw [->] (n7.west) -| ++(-1,0) |- (n5.west);
\end{tikzpicture}
\end{document}

I want the following:

  1. Center the flow chart. The flow chart is positioned exactly at the centre of the page (something like \centering?).
  2. A box around the flow chart (something like \fbox?).
  3. The arrow a little bit thicker such that it becomes more visible.
  4. Place a caption and label (\caption{} and \label{}).
Runar
  • 6,082
André
  • 417
  • 1
    You seem already to know how to do 1. 3. and 4., why did you not just implement these into your code? In addition to what you mentioned, it would just need \begin{figure} and end{figure} around it. – Runar Jul 02 '16 at 13:07

3 Answers3

8

An alternative ...

enter image description here

with concise (optimized) code and with frame as part of TikZ image:

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, chains, fit}

\usepackage{lipsum}
\usepackage[showframe]{geometry}

\begin{document}
\lipsum[2]
\begin{figure}[hbt]
    \centering
\begin{tikzpicture}[
node distance= 5mm,
 start chain = A going below,
block/.style = {rectangle, draw, rounded  corners,
                text width=10em, minimum height=3em, align=center,
                join = by arrow,
                on chain},
arrow/.style = {-{Latex[width=3mm, length=1.5mm]},thick}
                    ]
    % nodes
    \begin{scope}[every node/.style={block}]
\node {General framework};                  % A-1
\node {Literature study};
\node {Data-analysis};
\node {Model set-up (SB \& NH)};
\node {Simulations};
\node {Sensitivity analysis};
\node {Model update};
\node {Conclusions and recommendations};    % A-8
    \end{scope}
    % Connections
\draw [arrow] (A-7.west) -- ++ (-1,0) coordinate (a) |- (A-5.west);
\draw [arrow] (A-7.east) -- ++ ( 1,0) coordinate (b) |- (A-6.east);
    % frame
\node[draw, very thin,
      inner ysep=3mm, inner xsep=5mm, 
      fit=(A-1) (A-8) (a) (b)] {};
    \end{tikzpicture}

\caption{Some title}
    \label{fig:title}
\end{figure}
\lipsum[2]
\end{document}

Addendum: Regarding sub-questions, on sub-question 1, 2 and 3 is nothing to ad to @Runar Trollet answer, regarding frame I suggest to determine it by node in TikZ picture. With this more easy to determine border distance from images or even make it more fancy (for example with drop shadow).

So the main contribution is rewriting MWE to more concise code, which is actually off-topic (sorry, I can't resist to exploit all libraries and not used options in MWE :-) ). With this addendum I slightly further reduce the above code (node for frame is not necessary to be in background, as was in the first code version).Main gain in code conciseness is obtain by use of chains library and its option join.

Zarko
  • 296,517
  • A frame to a complete tikzpicture could be drawn with backgrounds tikzlibrary: \begin{tikzpicture}[show background rectangle]. This way you don't have to worry about nodes and fits. – Ignasi Jul 04 '16 at 07:46
  • Actually, in the first version of my answer I do so, however after than I change my mind and try to show that it is not necessary and about this wrote short explanation in the first paragraph in addendum. And yes, you have right. Your suggestion of use is new to me, so thank you very much for to pointed this. – Zarko Jul 04 '16 at 08:17
7

Placing the tikzpicture inside a figure-environment will fix problem 1 and 4. Remember that \label needs to be placed after \caption. For the arrows, you could have a look at Ignasi's answer inIs it possible to change the size of an arrowhead in TikZ/PGF? using the tikz-library arrows.meta.

You can set a style for all >-arrows in the following way:

\tikzset{>={Latex[width=2mm, length=1.2mm]}}

This was taken from Torbjørn T.´s answer in How to set default style for arrow tips in TikZ?

Output

enter image description here

Code

\documentclass[11pt]{article}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{calc,trees,positioning,arrows.meta,chains,shapes.geometric,  decorations.pathreplacing,decorations.pathmorphing,shapes,  matrix,shapes.symbols}
\tikzset{>={Latex[width=2mm, length=1.2mm]}}

\begin{document}
\lipsum[2]
\begin{figure}[hbt]
    \centering
    \tikzstyle{block} = [rectangle, draw, text width=10em, text centered, rounded      corners, minimum height=3em]
    %/pgf/arrow keys/length=2mm
    \fbox{%
        \begin{tikzpicture}
             [node distance=1.35cm,
             start chain=going below,]
            \node (n1) at (0,0) [block]  {General framwork};
            \node (n2) [block, below of=n1] {Literature study};
            \node (n3) [block, below of=n2] {Data-analysis};
            \node (n4) [block, below of=n3] {Model set-up (SB \& NH)};
            \node (n5) [block, below of=n4] {Simulations};
            \node (n6) [block, below of=n5] {Sensitivity analysis};
            \node (n7) [block, below of=n6] {Model update};
            \node (n8) [block, below of=n7] {Conclusions and recommendations};
            % Connectors
            \draw [->] (n1) -- (n2);
            \draw [->] (n2) -- (n3);
            \draw [->] (n3) -- (n4);
            \draw [->] (n4) -- (n5);
            \draw [->] (n5) -- (n6);
            \draw [->] (n6) -- (n7);
            \draw [->] (n6) -- (n7);
            \draw [->] (n7) -- (n8);
            \draw [->] (n7.east) -| ++(1,0) |- (n6.east);
            \draw [->] (n7.west) -| ++(-1,0) |- (n5.west);
        \end{tikzpicture}
    }
    \caption{Some title}
    \label{fig:title}
\end{figure}
\lipsum[1]
\end{document}
LCarvalho
  • 1,611
Runar
  • 6,082
5

A different approach using the smartdiagram package:

Code

\documentclass{article}
\usepackage{smartdiagram}
\usesmartdiagramlibrary{additions}
\usepackage{lipsum}

\begin{document}
    \lipsum[2]

    \begin{figure}[hbt]
    \centering
    \smartdiagramset{back arrow disabled=true,
                     text width=.3\textwidth,
                     uniform color list=white for all items,
                     uniform arrow color=true,
                     arrow color=black!70,
                     border color=black!70,
                     arrow line width=2pt,
                     additions={additional arrow color=black!70,
                                additional arrow line width=2pt}}
    \tikzset{every shadow/.style={fill=none,shadow scale=0},
             module/.append style={very thick}}
    {\color{lightgray}\framebox[.6\textwidth]{
    \smartdiagramadd[flow diagram]{%
        General framework,
        Literature study,
        Data-analysis,
        Model set-up\\ (SB \& NH),
        Simulations,
        Sensitivity analysis,
        Model update,
        Conclusions and recommendations}{}
    \begin{tikzpicture}[remember picture, overlay]
        \draw[additional item arrow type] (module7) -- ([xshift=25pt]module7.east) |- (module6);
        \draw[additional item arrow type] (module7) -- ([xshift=-25pt]module7.west) |- (module5);
    \end{tikzpicture}}}
    \caption{A flow diagram with \texttt{smartdiagram}.}
    \label{fig:flowdiagram}
    \end{figure}

    \lipsum[2]
\end{document}

Result

Flow diagram

osjerick
  • 6,970