TikZ 和 tabular/multicol

TikZ 和 tabular/multicol

我刚刚完成了我的第一个 TikZ 流程图,我有几个想改进它的地方,但我似乎找不到解决方案。我想在两列中做到这一点,并在它们之间画一条虚线。如您所见,有一个节点,虚线应该位于该节点。是否可以以可行的方式制作表格或多列?

\documentclass{memoir}
\usepackage[latin1]{inputenc}
\usepackage[a4paper,vmargin={30mm,0mm},hmargin={0mm,0mm}]{geometry}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows, shadows, calc}
\begin{document}
\pagestyle{empty}

\begin{center}
\tikzstyle{block} = [rectangle, draw, fill=gray!20, 
text width=8em, text centered, minimum height=4em, drop shadow]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, rectangle, rounded corners,fill=white!20, node distance=2cm,
minimum height=2em, drop shadow]

\begin{tikzpicture}[node distance = 2cm]
\node [block, xshift=12em] (post) {\large Postmoderne};
\node [block, xshift=-12em] (modern) {\large Moderne};
\node [cloud, below of=modern, node distance=7em, fill=red!20] (auto) {Øget             \emph{control}};
\node [cloud, below of=auto] (active) {\emph{Active learning} og positive udviklingsspiral};
\node [cloud, below of=active] (effect) {Mere effektivitet og positive emotioner};
\node [cloud, below of=post, node distance=4em, fill=red!20] (sparring) {Sparringssamarbejde};
\node [cloud, below of=sparring, node distance=3em] (support) {Øget social support};
\node [cloud, below of=support, node distance=11em] (kom) {Bedre kommunikation og gensidig respekt};
\node [cloud, below of=modern, node distance=24em, xshift=12em, fill=green!20] (res) {Resiliens hos medarbejder og organisation};


\path [line] (sparring) -- (support);
\path [line] (auto) -- (active);
\path [line] (active) -- (effect);
\path [line] (support) -- (active);
\path [line] (active) -- (kom);
\path [line] (kom) -- (res);
\path [line] (effect) -- (res);



\end{tikzpicture}
\end{center}

\end{document}

答案1

这是第一次尝试。

  • 我把你的节点放入matrix。这就像一个 LaTeXtabular环境,使网格中节点的定位变得非常容易。

  • 不幸的是,除非我弄错了,否则在 TikZ 中很难在行或列之间画线matrix。例如,您没有像 那样的列说明符tabular,因此您无法编写{c|c}获取两个居中列并在其间有一条线。

  • 我所做的是从矩阵顶部中心点到底部中心点画一条线。只有当两列的宽度大致相同时,这才是正确的。
  • 更新。我使用shorten >=-3cm将虚线的底端缩短-3cm;也就是说,将其加长3cm。您也可以写shorten <=-1 cm为 延长顶端。

代码

\documentclass{memoir}
\usepackage[utf8x]{inputenc}
\usepackage[a4paper,vmargin={30mm,0mm},hmargin={0mm,0mm}]{geometry}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows, shadows, calc}
\usetikzlibrary{matrix}
\begin{document}
\pagestyle{empty}

\begin{center}
\tikzstyle{block} = [rectangle, draw, fill=gray!20, 
text width=8em, text centered, minimum height=4em, drop shadow]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, rectangle, rounded corners,fill=white!20, node distance=2cm,
minimum height=2em, drop shadow]

\begin{tikzpicture}

\matrix (m) [column sep=2cm,row sep=2cm] {
  \node [block] (modern) {\large Moderne}; 
& \node [block] (post) {\large Postmoderne}; 
\\
& \node [cloud, fill=red!20] (sparring) {Sparringssamarbejde}; 
\\
  \node [cloud, fill=red!20] (auto) {Øget \emph{control}};
& \node [cloud] (support) {Øget social support}; 
\\
  \node [cloud] (active) {\emph{Active learning} og positive udviklingsspiral};
\\
  \node [cloud] (effect) {Mere effektivitet og positive emotioner};
& \node [cloud] (kom) {Bedre kommunikation og gensidig respekt};
\\
};

\draw[dashed, shorten >=-3cm] (m.north) -- (m.south);

\node [cloud, below of=effect, xshift=12em, fill=green!20] (res) {Resiliens hos medarbejder og organisation};

\path [line] (sparring) -- (support);
\path [line] (auto) -- (active);
\path [line] (active) -- (effect);
\path [line] (support) -- (active);
\path [line] (active) -- (kom);
\path [line] (kom) -- (res);
\path [line] (effect) -- (res);

\end{tikzpicture}
\end{center}

\end{document}

输出

在此处输入图片描述

相关内容