4

I'd like to change the node distance for a specific set of nodes, e.g. the first two in "introduction". The distance for the nodes in a set should be smaller, while the distance in between the sets should be bigger to make sure the caption below it is well readable. It should apply for all sets and nodes in the picture. I'm not sure how I can change the node distance variable so that it applies only to a specific set. enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, calc, fit, positioning, chains, arrows.meta}

%%% styles for Figure: Structure of the paper %%%
\tikzstyle{structure} = [rectangle, rounded corners, minimum width=5cm, minimum height=1cm,text centered, draw=black, fill=white!30]
\tikzstyle{arrow} = [thick,->,>=stealth]


\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[node distance=2cm]

\node (introduction) [structure] {Introduction to the topic};
\node (methodology) [structure, below of=introduction] {Problem definition, objectives, research methodology};
\node (theoretical) [structure, below of=methodology] {Theoretical considerations};
\node (model) [structure, below of=theoretical] {Definition of an integrated model of trust};
\node (interviews) [structure, below of=model] {Expert interviews};
\node (results) [structure, below of=interviews, text width=5cm] {Results};
\node (discussion) [structure, below of=results] {Discussion};

%arrows
\draw [arrow] (introduction) -- (methodology);
\draw [arrow] (methodology) -- (theoretical);
\draw [arrow] (theoretical) -- (model);
\draw [arrow] (model) -- (interviews);
\draw [arrow] (interviews) -- (results);
\draw [arrow] (results) -- (discussion);

%%% RECTANGLES %%%
\node[draw, thick, dotted, rounded corners, inner xsep=1em, inner ysep=1em, fit=(introduction) (methodology)] (box) {};
\node[fill=white] at (box.south) {Introduction};
\node[draw, thick, dotted, rounded corners, inner xsep=1em, inner ysep=1em, fit=(theoretical) (model) (interviews)] (box) {};
\node[fill=white] at (box.south) {Main part};
\node[draw, thick, dotted, rounded corners, inner xsep=1em, inner ysep=1em, fit=(results) (discussion)] (box) {};
\node[fill=white] at (box.south) {Conclusion};

\end{tikzpicture}
\caption{Structure of the paper} \label{fig:structure}
\end{figure}   

\end{document}

3 Answers 3

6

You can simply do it by adding <location> = x<your unit> of <node-name> instead of doing it statically like <location> of = <node-name>. As @marmot suggested, it is part of positioning package of tikz.

For instance:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, calc, fit, positioning, chains, arrows.meta}

%%% styles for Figure: Structure of the paper %%%
\tikzstyle{structure} = [rectangle, rounded corners, minimum width=5cm, minimum height=1cm,text centered, draw=black, fill=white!30]
\tikzstyle{arrow} = [thick,->,>=stealth]


\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[node distance=2cm]

\node (introduction) [structure] {Introduction to the topic};
\node (methodology) [structure, below =0.5cm of introduction] {Problem definition, objectives, research methodology};
\node (theoretical) [structure, below =2cm of methodology] {Theoretical considerations};
\node (model) [structure, below of=theoretical] {Definition of an integrated model of trust};
\node (interviews) [structure, below of=model] {Expert interviews};
\node (results) [structure, below of=interviews, text width=5cm] {Results};
\node (discussion) [structure, below of=results] {Discussion};

%arrows
\draw [arrow] (introduction) -- (methodology);
\draw [arrow] (methodology) -- (theoretical);
\draw [arrow] (theoretical) -- (model);
\draw [arrow] (model) -- (interviews);
\draw [arrow] (interviews) -- (results);
\draw [arrow] (results) -- (discussion);

%%% RECTANGLES %%%
\node[draw, thick, dotted, rounded corners, inner xsep=1em, inner ysep=1em, fit=(introduction) (methodology)] (box) {};
\node[fill=white] at (box.south) {Introduction};
\node[draw, thick, dotted, rounded corners, inner xsep=1em, inner ysep=1em, fit=(theoretical) (model) (interviews)] (box) {};
\node[fill=white] at (box.south) {Main part};
\node[draw, thick, dotted, rounded corners, inner xsep=1em, inner ysep=1em, fit=(results) (discussion)] (box) {};
\node[fill=white] at (box.south) {Conclusion};

\end{tikzpicture}
\caption{Structure of the paper} \label{fig:structure}
\end{figure}   

\end{document}

will give you something like this (as similar to the space you requested in your question):

enter image description here

As per @marmot's suggestion: by using tikzset{...} instead of the depreciated tikzstyle{...} environment:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, calc, fit, positioning, chains, arrows.meta}

%%% styles for Figure: Structure of the paper %%%

\tikzset{
    structure/.style = {draw, rectangle,
        minimum height=1cm,
        minimum width=5cm, rounded corners,, text centered, draw=black, fill=white!30},
    arrow/.style = {thick, ->, >=stealth}
}


\begin{document}

    \begin{figure}
        \centering
        \begin{tikzpicture}[node distance=2cm]

        \node (introduction) [structure] {Introduction to the topic};
        \node (methodology) [structure, below =0.5cm of introduction] {Problem definition, objectives, research methodology};
        \node (theoretical) [structure, below =2cm of methodology] {Theoretical considerations};
        \node (model) [structure, below of=theoretical] {Definition of an integrated model of trust};
        \node (interviews) [structure, below of=model] {Expert interviews};
        \node (results) [structure, below of=interviews, text width=5cm] {Results};
        \node (discussion) [structure, below of=results] {Discussion};

        %arrows
        \draw [arrow] (introduction) -- (methodology);
        \draw [arrow] (methodology) -- (theoretical);
        \draw [arrow] (theoretical) -- (model);
        \draw [arrow] (model) -- (interviews);
        \draw [arrow] (interviews) -- (results);
        \draw [arrow] (results) -- (discussion);

        %%% RECTANGLES %%%
        \node[draw, thick, dotted, rounded corners, inner xsep=1em, inner ysep=1em, fit=(introduction) (methodology)] (box) {};
        \node[fill=white] at (box.south) {Introduction};
        \node[draw, thick, dotted, rounded corners, inner xsep=1em, inner ysep=1em, fit=(theoretical) (model) (interviews)] (box) {};
        \node[fill=white] at (box.south) {Main part};
        \node[draw, thick, dotted, rounded corners, inner xsep=1em, inner ysep=1em, fit=(results) (discussion)] (box) {};
        \node[fill=white] at (box.south) {Conclusion};

        \end{tikzpicture}
        \caption{Structure of the paper} \label{fig:structure}
    \end{figure}   

\end{document}

We will get the same as before.

2
  • 1
    your use of positioning syntax is not consistent.
    – Zarko
    Nov 26, 2018 at 23:57
  • @Zarko Thanks for your notice, I will ensure that from my next answers. Here, I just modified the nodes that OP pointed out. So, I did not even pay attention to the other nodes per se. Nov 27, 2018 at 6:55
4

You can define two styles with different node distance.

\tikzset{nearnodes/.style={node distance=0.5cm,}}
\tikzset{farnodes/.style={node distance=1cm,}

Then use these styles for the corresponding nodes.

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, calc, fit, positioning, chains, arrows.meta}

%%% styles for Figure: Structure of the paper %%%
\tikzset{structure/.style = {rectangle, rounded corners, minimum width=5cm, minimum height=1cm,text centered, draw=black, fill=white!30,}}
\tikzset{arrow/.style = {thick,->,>=stealth,}}
\tikzset{nearnodes/.style={node distance=0.5cm,}}
\tikzset{farnodes/.style={node distance=2cm}}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
\node[nearnodes] (introduction) [structure] {Introduction to the topic};
\node[nearnodes] (methodology) [structure, below =of introduction] {Problem definition, objectives, research methodology};
\node[farnodes] (theoretical) [structure, below =of methodology] {Theoretical considerations};
\node[nearnodes] (model) [structure, below =of theoretical] {Definition of an integrated model of trust};
\node[nearnodes] (interviews) [structure, below =of model] {Expert interviews};
\node[farnodes] (results) [structure, below =of interviews, text width=5cm] {Results};
\node[nearnodes] (discussion) [structure, below =of results] {Discussion};

%arrows
\draw [arrow] (introduction) -- (methodology);
\draw [arrow] (methodology) -- (theoretical);
\draw [arrow] (theoretical) -- (model);
\draw [arrow] (model) -- (interviews);
\draw [arrow] (interviews) -- (results);
\draw [arrow] (results) -- (discussion);

%%% RECTANGLES %%%
\node[draw, thick, dotted, rounded corners, inner xsep=1em, inner ysep=1em, fit=(introduction) (methodology)] (box) {};
\node[fill=white] at (box.south) {Introduction};
\node[draw, thick, dotted, rounded corners, inner xsep=1em, inner ysep=1em, fit=(theoretical) (model) (interviews)] (box) {};
\node[fill=white] at (box.south) {Main part};
\node[draw, thick, dotted, rounded corners, inner xsep=1em, inner ysep=1em, fit=(results) (discussion)] (box) {};
\node[fill=white] at (box.south) {Conclusion};

\end{tikzpicture}
\caption{Structure of the paper} \label{fig:structure}
\end{figure}   
\end{document}
0
3

i would redesign your flowchart as follows:

enter image description here

in the mwe the use of the positioning library is consistent, with use of the chains library the nodes are named by chain name and connecting lines are defined by macro ˙join`. with this the code is (far) more concise that in other answers. labels of the article parts are defined with node labels:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,
                fit,
                positioning}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[
   node distance = 4mm,
     start chain = A going below,   % <--- chain name is A
      arr/.style = {thick, -Stealth},
structure/.style = {rectangle, draw, rounded corners,
                    text width=48mm, inner sep=2mm, align=flush center,
                    on chain=A, join=by arr},
every label/.append style = {fill=white, font=\footnotesize, inner ysep=1pt}
                    ]
    \begin{scope}[every node/.append style={structure}]
\node   {Introduction to the topic};        % A-1: first name
\node   {Problem definition, objectives, research methodology};
\node [below=11mm of A-2] % <--- increased distance between 
                          % adjacent nodes
        {Theoretical considerations};
\node   {Definition of an integrated model of trust};
\node   {Expert interviews};
\node [below=11mm of A-5] % <--- increased distance between 
                          % adjacent nodes
        {Results};
\node   {Discussion};                       % A-7: last node name
    \end{scope}
%%% RECTANGLES %%%
    \begin{scope}[every node/.append style={draw, rounded corners, densely dotted,
                                            inner sep=3mm}]
\node   [label={[anchor=center]south:Introduction},
         fit=(A-1) (A-2)]        {};
\node   [label={[anchor=center]below:Main Part},
         fit=(A-3) (A-5)]        {};
\node   [label={[anchor=center]below:Conclusion},
         fit=(A-6) (A-7)]       {};
    \end{scope}
\end{tikzpicture}
    \caption{Structure of the paper} \label{fig:structure}
\end{figure}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .