Tikz矩阵:将节点与多行的中心对齐

Tikz矩阵:将节点与多行的中心对齐

我在使用 TIKZ 或矩阵时遇到了问题...我不知道是哪一个 :)

我只想将我的黑盒移动/对齐到这一行(多行)的中心,同时让箭头均匀分布在两侧(见下文)。不知何故,它不起作用。我尝试使用表格和数组,但仍然没有成功。

有什么想法吗?谢谢!

(我不是乳胶英雄,请仁慈一点!)

\documentclass[10pt]{article} %
\usepackage{tikz} %
\usepackage{multirow} %
\usetikzlibrary{automata,arrows} %
\usepackage[active,tightpage]{preview}%
\PreviewEnvironment{tikzpicture}%
\setlength\PreviewBorder{1em}%
\begin{document}

    \begin{tikzpicture}
    [auto,
    block/.style ={rectangle, draw=black, thick, fill=black!85, text width=8em, text centered, text=white, rounded corners, minimum height=10em},
    line/.style ={draw, thick, -latex}]

    \matrix [column sep=15mm,row sep=6mm]
    {
    \node[] (in1) {Eingang 1} ; & \multirow{6}{*}{\node[block] (bb) {Blackbox};} & \node[] (out1) {Ausgang 1} ; \\
    \node[] (in2) {Eingang 2} ; & & \node[] (out2) {Ausgang 2} ; \\
    \node[] (in3) {Eingang 3} ; & & \node[] (out3) {Ausgang 3} ; \\
    \node[] (in4) {Eingang 4} ; & & \node[] (out4) {Ausgang 4} ; \\
    \node[] (in5) {Eingang 5} ; & & \node[] (out5) {Ausgang 5} ; \\
    \node[] (in6) {Eingang 6} ; & & \node[] (out6) {Ausgang 6} ; \\
    };

    \begin{scope}[every path/.style=line]
    \path (in1.east) -- ([yshift=3em]bb.west);
    \path (in2.east) -- ([yshift=2em]bb.west);
    \path (in3.east) -- ([yshift=1em]bb.west);
    \path (in4.east) -- ([yshift=-1em]bb.west);
    \path (in5.east) -- ([yshift=-2em]bb.west);
    \path (in6.east) -- ([yshift=-3em]bb.west);

    \path ([yshift=3em]bb.east) -- (out1.west);
    \path ([yshift=2em]bb.east) -- (out2.west);
    \path ([yshift=1em]bb.east) -- (out3.west);
    \path ([yshift=-1em]bb.east) -- (out4.west);
    \path ([yshift=-2em]bb.east) -- (out5.west);
    \path ([yshift=-3em]bb.east) -- (out6.west);
    \end{scope}

    \end{tikzpicture}

\end{document}

对齐黑框

答案1

这是你想要的吗?

下面的方法首先将两组节点放在两侧,从而创建一个边界框。然后,它将黑框放在边界框的中心。您需要加载库positioning。而且似乎automata不需要该库。

代码

\documentclass[10pt]{article} %
\usepackage{tikz} %
\usepackage{multirow} %
\usetikzlibrary{arrows,positioning} %
\usepackage[active,tightpage]{preview}%
\PreviewEnvironment{tikzpicture}%
\setlength\PreviewBorder{1em}%
\begin{document}

    \begin{tikzpicture}
    [auto,
    block/.style ={rectangle, draw=black, thick, fill=black!85, text width=8em, text centered, text=white, rounded corners, minimum height=10em},
    line/.style ={draw, thick, -latex}]

    \node(in1){Eingang 1};
    \foreach\innum[count=\inlag] in {2,...,6}
        \node(in\innum)[below=of in\inlag]{Eingang \innum};

    \node(out1)[right=50mm of in1]{Ausgang 1};
    \foreach\outnum[count=\outlag] in {2,...,6}
        \node(out\outnum)[below=of out\outlag]{Ausgang \outnum};

    \node[block] (bb) at(current bounding box.center) {Blackbox};

    \begin{scope}[every path/.style=line]
    \path (in1.east) -- ([yshift=3em]bb.west);
    \path (in2.east) -- ([yshift=2em]bb.west);
    \path (in3.east) -- ([yshift=1em]bb.west);
    \path (in4.east) -- ([yshift=-1em]bb.west);
    \path (in5.east) -- ([yshift=-2em]bb.west);
    \path (in6.east) -- ([yshift=-3em]bb.west);

    \path ([yshift=3em]bb.east) -- (out1.west);
    \path ([yshift=2em]bb.east) -- (out2.west);
    \path ([yshift=1em]bb.east) -- (out3.west);
    \path ([yshift=-1em]bb.east) -- (out4.west);
    \path ([yshift=-2em]bb.east) -- (out5.west);
    \path ([yshift=-3em]bb.east) -- (out6.west);
    \end{scope}

    \end{tikzpicture}

\end{document}

输出

在此处输入图片描述

答案2

您拥有的是一个matrix节点,其中\multirow不起作用。您必须在中心为黑框添加一个新行。要更改多余的垂直空间,您可以\\[<dimen>]使用

\node[] (in3) {Eingang 3} ; & & \node[] (out3) {Ausgang 3} ; \\[-2.3cm]
                  &    \node[block] (bb) {Blackbox};   &          \\[-2.3cm]

完整代码

\documentclass[10pt]{article} %
\usepackage{tikz} %
\usepackage{multirow} %
\usetikzlibrary{automata,arrows} %
\usepackage[active,tightpage]{preview}%
\PreviewEnvironment{tikzpicture}%
\setlength\PreviewBorder{1em}%
\begin{document}

    \begin{tikzpicture}
    [auto,
    block/.style ={rectangle, draw=black, thick, fill=black!85, text width=8em, text centered, text=white, rounded corners, minimum height=10em},
    line/.style ={draw, thick, -latex}]

    \matrix [column sep=15mm,row sep=6mm]
    {
    \node[] (in1) {Eingang 1} ; &  & \node[] (out1) {Ausgang 1} ; \\
    \node[] (in2) {Eingang 2} ; & & \node[] (out2) {Ausgang 2} ; \\
    \node[] (in3) {Eingang 3} ; & & \node[] (out3) {Ausgang 3} ; \\[-2.3cm]
                  &    \node[block] (bb) {Blackbox};   &          \\[-2.3cm]
    \node[] (in4) {Eingang 4} ; & & \node[] (out4) {Ausgang 4} ; \\
    \node[] (in5) {Eingang 5} ; & & \node[] (out5) {Ausgang 5} ; \\
    \node[] (in6) {Eingang 6} ; & & \node[] (out6) {Ausgang 6} ; \\
    };

    \begin{scope}[every path/.style=line]
    \path (in1.east) -- ([yshift=3em]bb.west);
    \path (in2.east) -- ([yshift=2em]bb.west);
    \path (in3.east) -- ([yshift=1em]bb.west);
    \path (in4.east) -- ([yshift=-1em]bb.west);
    \path (in5.east) -- ([yshift=-2em]bb.west);
    \path (in6.east) -- ([yshift=-3em]bb.west);

    \path ([yshift=3em]bb.east) -- (out1.west);
    \path ([yshift=2em]bb.east) -- (out2.west);
    \path ([yshift=1em]bb.east) -- (out3.west);
    \path ([yshift=-1em]bb.east) -- (out4.west);
    \path ([yshift=-2em]bb.east) -- (out5.west);
    \path ([yshift=-3em]bb.east) -- (out6.west);
    \end{scope}

    \end{tikzpicture}

\end{document}

在此处输入图片描述

答案3

这就是我现在所做的,感谢所有回答的人!

\documentclass[10pt]{article} %
\usepackage{tikz} %
\usepackage{multirow} %
\usetikzlibrary{arrows,positioning} %
\usepackage[active,tightpage]{preview}%
\PreviewEnvironment{tikzpicture}%
\setlength\PreviewBorder{1em}%
\begin{document}

    \begin{tikzpicture}
    [auto,
    block/.style ={rectangle, draw=black, thick, fill=black!85, text width=8em, text centered, text=white, rounded corners, minimum height=10em},
    line/.style ={draw, thick, -latex},
    nodel/.style={text width=9em, align=right, anchor=east}, % change width for long text
    noder/.style={text width=9em, align=left, anchor=west}    
    ]

    \node(in1){}; %Eingang 1
    \foreach\innum[count=\inlag] in {2,...,6}
        \node(in\innum)[below=of in\inlag]{}; %Eingang \innum

    \node(out1)[right=60mm of in1]{}; %Ausgang 1
    \foreach\outnum[count=\outlag] in {2,...,6}
        \node(out\outnum)[below=of out\outlag]{}; %Ausgang \outnum

    \node[block] (bb) at(current bounding box.center) {Blackbox};

    \begin{scope}[every node/.style=nodel]
        \node[] at (in1) {This is really long text for only one node};
        \node[] at (in2) {Very short!};
        \node[] at (in3) {Here's some more text that needs to fit my node};
        \node[] at (in4) {Here's some more text};
        \node[] at (in5) {Nothing new here};
        \node[] at (in6) {Nothing new here};
    \end{scope}

    \begin{scope}[every node/.style=noder]
        \node[] at (out1) {Not as much};
        \node[] at (out2) {Long text, see above};
        \node[] at (out3) {Short! Or maybe not as short as I thought. Maybe too much};
        \node[] at (out4) {Short};
        \node[] at (out5) {Something else over here};
        \node[] at (out6) {Something else over here};
    \end{scope}

    \begin{scope}[every path/.style=line]
        \path (in1.east) -- ([yshift=3em]bb.west);
        \path (in2.east) -- ([yshift=2em]bb.west);
        \path (in3.east) -- ([yshift=1em]bb.west);
        \path (in4.east) -- ([yshift=-1em]bb.west);
        \path (in5.east) -- ([yshift=-2em]bb.west);
        \path (in6.east) -- ([yshift=-3em]bb.west);

        \path ([yshift=3em]bb.east) -- (out1.west);
        \path ([yshift=2em]bb.east) -- (out2.west);
        \path ([yshift=1em]bb.east) -- (out3.west);
        \path ([yshift=-1em]bb.east) -- (out4.west);
        \path ([yshift=-2em]bb.east) -- (out5.west);
        \path ([yshift=-3em]bb.east) -- (out6.west);
    \end{scope}

    \end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容