不同的方法?

不同的方法?

我正在尝试制作我的第一个 tikz 图表,它运行良好,但我遇到了一些问题,我认为我的解决方案开始变得更加灵活。这是我的代码:

\documentclass[png,border=10pt,tikz]{article}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,fit,shapes,calc}
\tikzset{
    state/.style={
           rectangle,
           rounded corners,
           draw=black, very thick,
           minimum height=2em,
           inner sep=2pt,
           text centered,
           },
}

\tikzstyle{line} = [draw, -latex]

\pgfdeclarelayer{bg}    % declare background layer
\pgfsetlayers{bg,main}

\begin{document}


\tikzset{
    block/.style={draw, fill=white, rectangle, rounded corners, 
            minimum height=2em, minimum width=10em},
    block2/.style={draw, fill=white, rectangle, rounded corners, 
            minimum height=2em, minimum width=10em},  
    block3/.style={draw, fill=white, rectangle, 
            minimum height=4em, minimum width=30em},             
}

\begin{tikzpicture}[auto, node distance=2.5cm, >=latex]

\node[block3] (kronos) {Kronos};
\node[block, above of= kronos, anchor=north east] (interbank) {Interbank};
\node[block, above of= kronos, anchor=north west] (pengepolitik) {Pengepolitiske operationer};

\node[block, below = of kronos, anchor=south] (sum) {Sum-, intraday- og Straksclearing};
\node[block, left of = sum] (scp) {SCP};
\node[block, left = of scp] (vp) {VP};

\node[block, right of = sum] (euro) {EuroCCP};
\node[block, right of = euro] (cls) {CLS}; 

\node[block, below of= vp] (valuta) {Valutahandler};
\node[block, below of= scp] (detail) {Detailhandler};
\node[block, below of= cls] (værdi) {Værdipapirhandler};

\draw[dotted,thick] ($(interbank.north west)+(-0.3,0.3)$) rectangle ($(pengepolitik.south east)+(0.3,-0.3)$);

\draw[dotted,thick] ($(vp.north west)+(-0.3,0.3)$) rectangle ($(cls.south east)+(0.3,-0.3)$);



\path[line] (pengepolitik) -- (kronos);
\path[line] (interbank) -- (kronos);
\path[line] (scp) -- (kronos);
\path[line] (euro) -- (kronos);
\path[line] (vp) -- (kronos);
\path[line] (cls) -- (kronos);

\begin{pgfonlayer}{bg}    % select the background layer
       \draw[dashed] ($(kronos.west)+(-6,0)$) -- ($(kronos.east)+(6,0)$);
    \end{pgfonlayer}


\end{tikzpicture}



\end{document}

我的一些问题非常明显:

在此处输入图片描述

但我正在尝试实现这样的目标: 在此处输入图片描述

因此,我也在寻找一种方法来画直线,而不是画到主图的中心?您有更好的解决方案可以让我尝试吗?

问候,弗雷德里克。

答案1

您或多或少已经到了那里。在一些较小的语法错误之下,您错误地使用了节点的锚点。

\documentclass[border=10pt,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,fit,shapes,calc}
\tikzset{
    state/.style={
           rectangle,
           rounded corners,
           draw=black, very thick,
           minimum height=2em,
           inner sep=2pt,
           text centered,
           },
}

\tikzstyle{line} = [draw, -latex]

\pgfdeclarelayer{bg}    % declare background layer
\pgfsetlayers{bg,main}

\begin{document}


\tikzset{
    block/.style={draw, fill=white, rectangle, rounded corners, 
            minimum height=2em, minimum width=10em},
    block2/.style={draw, fill=white, rectangle, rounded corners, 
            minimum height=2em, minimum width=10em},  
    block3/.style={draw, fill=white, rectangle, 
            minimum height=4em, minimum width=30em},             
}

\begin{tikzpicture}[auto, node distance=2.5cm, >=latex]

\node[block3] (kronos) {Kronos};
\node[block, above left = 3em of kronos, anchor=south west] (interbank) {Interbank};
\node[block, above right = 3em of kronos, anchor=south east] (pengepolitik) {Pengepolitiske operationer};

\node[block, below = 3em of kronos] (sum) {Sum-, intraday- og Straksclearing};
\node[block, left = 3em of sum] (scp) {SCP};
\node[block, left = 3em of scp] (vp) {VP};

\node[block, right = 3em of sum] (euro) {EuroCCP};
\node[block, right = 3em of euro] (cls) {CLS}; 

\node[block, below = 3em of vp] (valuta) {Valutahandler};
\node[block, below = 3em of scp] (detail) {Detailhandler};
\node[block, below = 3em of cls] (værdi) {Værdipapirhandler};

\draw[dotted,thick] ($(interbank.north west)+(-0.3,0.3)$) rectangle ($(pengepolitik.south east)+(0.3,-0.3)$);

\draw[dotted,thick] ($(vp.north west)+(-0.3,0.3)$) rectangle ($(cls.south east)+(0.3,-0.3)$);

\path[line] (pengepolitik) -- (kronos);
\path[line] (interbank) -- (kronos);
\path[line] (scp) -- (kronos);
\path[line] (euro) -- (kronos);
\path[line] (vp) -- (kronos);
\path[line] (cls) -- (kronos);

\begin{pgfonlayer}{bg}    % select the background layer
       \draw[dashed] ($(kronos.west)+(-6,0)$) -- ($(kronos.east)+(6,0)$);
    \end{pgfonlayer}

\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容