tikz-覆盖多列的节点

tikz-覆盖多列的节点

有没有一种简单的方法可以将 TikZ 中矩阵环境中的节点拉伸到多列上?在下面的示例中,我想将第二行中的三个节点合并为一个宽节点。

任何想法?

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{arrows}

\begin{document}

\begin{tikzpicture}
[auto,
mytext/.style={thick, text width=4.5em,inner sep=1pt},
line/.style ={draw, thick, -latex',shorten >=2pt},
block/.style ={rectangle,text width=6em,draw,minimum height=4em, outer sep=0pt}]
\matrix [column sep=1cm,row sep=7mm]
{
 % 1. row
 \node [mytext] (st0) {Step 1}; &
 \node [block] (cl0) [label=above:\textbf{Climate}] {rainfall and temperature}; &
  \node [block] (veg0) [label=above:\textbf{Vegetation}] {forest}; &
  \node [block] (sol0) [label=above:\textbf{Soil and terrain}]
  {soil}; \\
 % 2. row
 \node  (st2) {some text}; &
 \node [block] (cl1) {this blocks}; &
 \node [block] (veg1) {should be}; &
 \node [block] (sol1) {merged together}; \
\\ };
\tikzstyle{every path}=[line]
\path (cl0) -- (cl1);
\path (veg0) -- (veg1);
\path (sol0) -- (sol1);

\end{tikzpicture}

\end{document} 

在此处输入图片描述

答案1

这当然不是最干净的方法,但可能是最简单的

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{arrows,fit}

\begin{document}

\begin{tikzpicture}
[auto,
mytext/.style={thick, text width=4.5em,inner sep=1pt},
line/.style ={draw, thick, -latex',shorten >=2pt},
block/.style ={rectangle,text width=6em,draw,minimum height=4em, outer sep=0pt},
blocka/.style ={rectangle,text width=6em,minimum height=4em, outer sep=0pt}]
\matrix [column sep=1cm,row sep=7mm]
{
 % 1. row
 \node [mytext] (st0) {Step 1}; &
 \node [block] (cl0) [label=above:\textbf{Climate}] {rainfall and temperature}; &
  \node [block] (veg0) [label=above:\textbf{Vegetation}] {forest}; &
  \node [block] (sol0) [label=above:\textbf{Soil and terrain}]
  {soil}; \\
 % 2. row
 \node  (st2) {some text}; &
 \node [blocka] (cl1) {}; &
 \node [blocka] (veg1) {}; &
 \node [blocka] (sol1) {}; \\

\\ };
\tikzstyle{every path}=[line]
\path (cl0) -- (cl1);
\path (veg0) -- (veg1);
\path (sol0) -- (sol1);

\node[block] (outer) [fit=(cl1) (veg1) (sol1)] {this blocks should be merged together};

\end{tikzpicture}

\end{document} 

在此处输入图片描述

否则:TikZ 矩阵中有多行/多列单元格?

相关内容