tikz 矩阵中的节点和范围的对齐?

tikz 矩阵中的节点和范围的对齐?

我试图修复下图中箭头的位置,但没有成功。我希望箭头在矩阵单元格中居中(水平和垂直),无论它们指向哪个方向。

箭头由 LARROW RARROW 和 DARROW 宏定义。

带有父节点边界框​​的箭头

梅威瑟:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart,shapes.gates.logic.IEC,shapes.arrows,positioning,decorations.markings}


\begin{document}

\begin{tikzpicture}[use IEC style logic gates, LFSR/.style={
rectangle split, rectangle split horizontal=true, rectangle split parts=#1, draw, anchor=center}, ARROW/.style={draw,thick,single arrow,single arrow head extend=3pt,transform shape}]
\def\Byte(#1,#2,#3,#4){%
\node[LFSR=3,name=#1] {\nodepart{one}#2\nodepart{two}#3\nodepart{three}#4};
}
\def\LFSR(#1,#2,#3,#4){%
\begin{scope}[decoration={
    markings,
    mark=at position 0.6 with {\arrow{latex}}}]
    \Byte(LFSR0,#1,#2,#3)
    \node[xor gate, draw, logic gate inputs=nn, logic gate input sep=0.3cm, rotate = 180, below = 1.4cm of LFSR0.one, xshift=2mm, xor gate symbol ={\scalebox{-1}{\small=1}}, logic gate symbol align = {bottom}] (Xor) {\parbox[t][0.75cm]{0.7cm}{\scalebox{-1}{\small XOR}}};
    \draw (LFSR0.two south) |- (Xor.input 2);
    \draw (LFSR0.three south) |- (Xor.input 1);
    \draw (Xor.output) -- ++(left:3mm) node[anchor=north,inner sep=0pt] (hook1) {};
    \draw[postaction={decorate}] (hook1) |- node [near start, left] {#4} (hook1|-LFSR0.west);
    \draw (hook1|-LFSR0.west) -- (LFSR0.west) {};
    \draw[-latex] (LFSR0.one north) ++(up:1mm) node[anchor=center,inner sep=0pt] (hook2) {} -- (LFSR0.three south |-hook2);
\end{scope}
}
\def\RARROW{\node[rectangle,draw] {
    \parbox[b][1cm]{0pt}{\begin{tikzpicture}
        \node[ARROW] {};
    \end{tikzpicture}}
    };
}
\def\LARROW{\node[rectangle,draw,rotate=180] {
    \parbox[t][1cm]{0pt}{\begin{tikzpicture}
        \node[ARROW] {};
    \end{tikzpicture}}
    };
}
\def\DARROW{\node[rectangle,draw,align=center] {
    \begin{tikzpicture}
        \node[ARROW,rotate=-90] {};
    \end{tikzpicture}
    };
}
\matrix[row sep=0, column sep=2.5mm]{
    \LFSR(1,1,1,0) &\RARROW& \LFSR(0,1,1,0) & \RARROW & \LFSR(0,0,1,1) & \RARROW & \LFSR(1,0,0,0)\\
    \node[anchor=east,minimum height=9mm]{$t=0$};   & &
    \node[anchor=east,minimum height=9mm]{$t=1$};   & &
    \node[anchor=east,minimum height=9mm]{$t=2$};   & &
    \node[anchor=east,minimum height=9mm]{$t=3$};   \\
    & & & & & & \DARROW\\
    \LFSR(1,1,1,0) &\LARROW& \LFSR(1,1,0,1) &\LARROW& \LFSR(1,0,1,1) &\LARROW& \LFSR(0,1,0,1)\\
    \node[anchor=east,minimum height=9mm]{$t=7$};   & &
    \node[anchor=east,minimum height=9mm]{$t=6$};   & &
    \node[anchor=east,minimum height=9mm]{$t=5$};   & &
    \node[anchor=east,minimum height=9mm]{$t=4$};   \\
};
\end{tikzpicture}

\end{document}

答案1

下面我给出了针对您的问题的解决方案(呃...稍微修改了一下=)

矩阵节点对齐

我重写了代码,希望它不会太难理解。

\documentclass [tikz] {standalone}

\usetikzlibrary{calc}
\usetikzlibrary{matrix}
\usetikzlibrary{fit}
\usetikzlibrary{shapes.arrows}
\usetikzlibrary{shapes.gates.logic.IEC}

\tikzset{
    bit/.style = {draw, thick, minimum size = 1 cm, anchor = west}
    , port/.style = {draw, thick, minimum size = 2 cm}
    , space/.style = {minimum size = 1 cm}
    , flow/.style = {->, thick}
    , label/.style = {anchor = east}
    , inside/.style = {minimum size = 1 cm}
    , next/.style = {single arrow, draw, minimum size = 8mm}
}


\newcounter{cellcounter}

\newcommand{\myarrow}[1]{
    \begin{tikzpicture}
        \node [next, rotate = #1]{};
    \end{tikzpicture}
}   

\pgfmathsetmacro{\inputonedistance}{1 / 3}
\pgfmathsetmacro{\inputtwodistance}{2 / 3}

\newcommand{\mycell}[5]{
    \begin{tikzpicture} [use IEC style logic gates]
        \node [port]  (port) {};
        \node [inside, anchor = north]  (port symbol) at (port.north){\texttt{=1}};
        \node [inside, anchor = south]  (port name) at (port.south){\LARGE \texttt{#2}};

        \coordinate (port right 1) at ($(port.north east)!\inputonedistance!(port.south east)$);
        \coordinate (port right 2) at ($(port.north east)!\inputtwodistance!(port.south east)$);

        \node [space, anchor = south east] (space 0) at (port.north east) {};

        \node [bit, anchor = south] (bit 0) at (space 0.north east) {\texttt{#3}};
        \node [bit] (bit 1) at (bit 0.east) {\texttt{#4}};
        \node [bit] (bit 2) at (bit 1.east) {\texttt{#5}};

        \node [space, anchor = south] (space 1) at (bit 0.north) {};
        \node [space, anchor = south] (space 2) at (bit 2.north) {};

        \draw [flow] (bit 1) |- (port right 1);
        \draw [flow] (bit 2) |- (port right 2);
        \draw [flow] (space 1.center) |- (space 2.center);

        \node [space, anchor = south west] (space 3) at (port.north west) {};
        \node [space, anchor = south east] (space 4) at (space 3.north west) {};
        \node [space, anchor = east] (space 5) at (port.west) {};

        \node [label] (label 1) at ($(space 4)!0.5!(space 5)$) {\texttt{#1}};

        \draw [flow] (port) -| (label 1.east) |- (bit 0);
        \draw [flow] (port) -| (label 1.east) |- (bit 0);

        \node [fit = (port) (bit 2) (label 1) (space 2)] (base) {};
        \node [anchor = north] at (base.south) {\(t = \thecellcounter\) \stepcounter {cellcounter}};
    \end{tikzpicture}
}

\begin{document}
    \begin{tikzpicture} 
        \matrix (m) [matrix of nodes, nodes in empty cells, nodes = {minimum size = 2cm}]{
            & & & & & & & & & & & & & & \\
            & & & & & & & & & & & & & & \\
            & & & & & & & & & & & & & & \\
            & & & & & & & & & & & & & & \\
            & & & & & & & & & & & & & & \\
            & & & & & & & & & & & & & & \\
            & & & & & & & & & & & & & & \\
        };

        \node at (m-4-2) {\mycell{0}{XOR}{1}{1}{1}};

        \node at (m-2-6) {\mycell{0}{XOR}{0}{1}{1}};
        \node at (m-2-10) {\mycell{1}{XOR}{0}{0}{1}};
        \node at (m-2-14) {\mycell{0}{XOR}{1}{0}{0}};

        \node at (m-6-14) {\mycell{1}{XOR}{0}{1}{0}};
        \node at (m-6-10) {\mycell{1}{XOR}{1}{0}{1}};
        \node at (m-6-6) {\mycell{1}{XOR}{1}{1}{0}};

        \node at (m-3-4)  {\myarrow{45} };
        \node at (m-2-8)  {\myarrow{0}  };
        \node at (m-2-12) {\myarrow{0}  };
        \node at (m-4-14) {\myarrow{270}};
        \node at (m-6-8)  {\myarrow{180}};
        \node at (m-6-12) {\myarrow{180}};
        \node at (m-5-4)  {\myarrow{135}};

    \end{tikzpicture}
\end{document}

相关内容