# Diagram distance between two elements

I have the following diagram:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\usetikzlibrary{shapes,arrows,positioning,calc}

\tikzset {
block/.style = {draw, fill=blue!20, rounded corners,text centered, rectangle, minimum height=3em, minimum width = 9em, font=\bfseries},
}

\begin{tikzpicture}[node distance=3cm, >=latex']

\node [block] (convergencia) {convergence};

\node [below right=2em] (analitica) {analitical solution};
\node [below left=2em] (numerica) {numerical solution};
\draw [<->] (analitica) -- (numerica);

\node [block,above left of=convergencia] (consistencia) {consistency};
\draw [thick,->] (consistencia) -- (convergencia);

\node[above left of=consistencia] (discreta) {Discrete equation};
\node[above right  of=consistencia] (diferencial) {differential equation};
\draw [<->] (discreta) -- (diferencial);

\node [block, above right of=convergencia] (estabilidade) {stability};

\node[above left of=estabilidade] (exata) {exact numerical solution};
\node[above right  of=estabilidade] (numerica) {found numerical solution};
\draw [<->] (exata) -- (numerica);

\end{tikzpicture}
\end{document}


But it has two issues that I can't solve:

First, I can't make positional references as above right of=object and above left of=object and have a good distance between the object below and the two objects created above. By good I mean, a small vertical distance and a horizontal distance that to not clutter everything.

Second, my two boxes Consistencia and Estabilidade are nicely positioned, but the objects above them get over each other, how can I enforce a bigger horizontal distance (but not vertical) between them to make the objects above do not overwrite each other?

• Welcome to TeX.SE! Please always provide an MWE. What strikes me is the fact that you are loading the positioning library, but you are not using it. By using it, e.g. above left=1.5cm of estabilidade instead of above left of=estabilidade you should be able to place everything where you want.
– user121799
Jun 2, 2018 at 4:06
• Thank you for the comment. 1. I think that is my MWE, since without 3 elements I would not be able to show the issues; 2. I thought that (elem) -- (elem) and left of like statements is the poistioning library; 3. your hint is good, It has worked for the blocks, but the [attribs] now are too spread horizontaly since they are starting after the margins of the [blocks]. I wish something in between. Thanks.
– Lin
Jun 2, 2018 at 4:20
• Welcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a \documentclass command, include any necessary packages and be as small as possible to demonstrate your problem.
– user30471
Jun 2, 2018 at 4:42
• Ok. MWE must be fully functional. All right, right on the way.
– Lin
Jun 2, 2018 at 5:17

The tikzlibrary positioning allows fine-tuning the position of your nodes.

I have also put the description in multiple lines, otherwise, they are too long and the image goes out of the page borders.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,calc}
\tikzset {
block/.style = {
draw, fill=blue!20, rounded corners,text centered,  rectangle, minimum height=3em, minimum width = 9em, font=\bfseries
},
descr/.style = {
text width=5em,
text centered,
minimum height=10ex
},
}

\begin{document}
\begin{tikzpicture}[>=latex']

\node [block] (convergencia) {convergence};

\node [below right=20pt and 10pt, descr] (analitica) {analitical solution};
\node [below left=20pt and 10pt, descr] (numerica) {numerical solution};
\draw [<->] (analitica) -- (numerica);

\node [block, above left= 26pt and -10pt of convergencia] (consistencia) {consistency};
\draw [thick,->] (consistencia) -- (convergencia);

\node[above left=5pt and -30pt of consistencia, descr] (discreta) {Discrete\\ equation};
\node[above right=5pt and -30pt of consistencia, descr] (diferencial) {differential\\ equation};
\draw [<->] (discreta) -- (diferencial);

\node [block, above right=26pt and -10pt of convergencia] (estabilidade) {stability};

\node[above left= 5pt and -30pt of estabilidade, descr] (exata) {exact numerical solution};
\node[above right= 5pt and -30pt of estabilidade, descr] (numerica) {found numerical solution};
\draw [<->] (exata) -- (numerica);

\end{tikzpicture}
\end{document}


Another possible (maybe more elegant) solution is with a tikz matrix:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,arrows}
\tikzset {
block/.style = {
draw, fill=blue!20, rounded corners,text centered,  rectangle, minimum height=3em, minimum width = 9em, font=\bfseries
},
descr/.style = {
text width=5em,
text centered,
minimum height=10ex,
anchor=center
},
}

\begin{document}
\begin{tikzpicture}[>=latex']
\matrix[
matrix of nodes,
column sep=-35pt,
row sep=4pt,
row 1/.style={nodes={descr}},
row 2/.style={nodes={block}},
row 3/.style={nodes={block}},
row 4/.style={nodes={descr}},
](mymatr){
|[name=discreta]| Discrete equation
& &|[name=diferencial]| differential equation
& &|[name=exata]| exact numerical solution
& &|[name=foundnumerica]| found numerical solution\\
&|[name=consistencia]| consistency