两个元素之间的图表距离

两个元素之间的图表距离

我有下图:

\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};
\draw [thick,->] (estabilidade) -- (convergencia);

\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}

但它有两个问题我无法解决:

首先,我无法创建位置参考,因为above right of=objectabove left of=object下方的对象与上方创建的两个对象之间有适当的距离。所谓“适当”,是指较小的垂直距离和水平距离,以免一切杂乱。

第二,我的两个盒子一致性建立位置很好,但是它们上方的物体互相重叠,我怎样才能强制它们之间有更大的水平距离(但不是垂直距离),以使上方的物体不会互相覆盖?

在此处输入图片描述

答案1

tikzlibrary positioning允许微调节点的位置。

看:PGF/TikZ 中“right of=”和“right=of”之间的区别

我还将描述分成多行,否则它们太长并且图像会超出页面边框。

\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};
    \draw [thick,->] (estabilidade) -- (convergencia);

    \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}

在此处输入图片描述

答案2

另一个可能的(也许更优雅的)解决方案是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 
            & & & &|[name=estabilidade]| stability\\[20pt]
        & & &|[name=convergencia]| convergence\\
        & &|[name=analitica]| analitical solution
            & & |[name=numerica]| numerical solution\\
    };
    \draw [<->] (analitica) -- (numerica);
    \draw [thick,->] (consistencia) -- (convergencia);
    \draw [<->] (discreta) -- (diferencial);
    \draw [thick,->] (estabilidade) -- (convergencia);
    \draw [<->] (exata) -- (foundnumerica);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容