我有下图:
\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=object
和above 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}