Tikz Matrix 没有命名的形状

Tikz Matrix 没有命名的形状

我尝试使用 LaTeX 撰写我的学士论文。在这方面,我遇到了 TikZ 问题。我喜欢像这样在矩阵上加括号:

在此处输入图片描述

我有几个问题:

  • 无法在第 6 行和第 7 行之间绘制虚线
  • 节点(我希望 u_1 等是节点?)不在正确的位置
  • 六个节点之后我就无法再添加。它显示“没有名为 1-7 的形状”
  • 我喜欢每 3 列(即从 1 到 3、3-6 和 6-9)添加一个字母

如果有人能帮助我我将非常感激:)

代码如下:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning}
\begin{document}

\begin{eqnarray*}
\begin{tikzpicture}
[baseline=-\the\dimexpr\fontdimen22\textfont2\relax ]
\matrix (m)[matrix of math nodes,left delimiter={[},right delimiter={]},,nodes in empty cells]
{
    d^{(1)}_1\\
    d^{(1)}_2\\
    d^{(1)}_3\\
    d^{(1)}_4\\
    d^{(1)}_5\\
    d^{(1)}_6\\
    %
    d^{(2)}_1\\
    d^{(2)}_2\\
    d^{(2)}_3\\
    d^{(2)}_4\\
    d^{(2)}_5\\
    d^{(2)}_6\\
 };

\draw[dashed] ($0.5*(m-6-1.south west)+0.5*(m-7-1.north west)$) --
($0.5*(m-6-1.south east)+0.5*(m-7-1.north east)$);

\node[left=12pt of m-2-1] (left-1) {i};
\node[left=12pt of m-5-1] (left-2) {k};
\node[left=12pt of m-8-1] (left-3) {i};
\node[left=12pt of m-11-1](left-4) {k};

\node[rectangle,left delimiter=\{] (del-left-1) at ($0.5*(left-1.east) +0.5*(left-2.east)$) {\tikz{\path (left-1.north east) rectangle (left-2.south west);}};
\node[left=12pt] at (del-left-1.west) {$E_1$};

\node[rectangle,left delimiter=\{] (del-left-3) at ($0.5*(left-3.east) +0.5*(left-4.east)$) {\tikz{\path (left-3.north east) rectangle (left-4.south west);}};
\node[left=12pt] at (del-left-3.west) {$E_1$};
\end{tikzpicture}
=
\begin{tikzpicture}
[baseline=-\the\dimexpr\fontdimen22\textfont2\relax ]
\matrix (n)[matrix of math nodes,left delimiter={[},right delimiter={]},column sep=0.5cm,nodes in empty cells]{
1       &       &       &       &       &       &       &       &       \\
        &1      &       &       &       &       &       &       &       \\
        &       &1      &       &       &       &       &       &       \\
        &       &       &1      &       &       &       &       &       \\
        &       &       &       &1      &       &       &       &       \\
        &       &       &       &       &1      &       &       &       \\
        &       &       &1      &       &       &       &       &       \\
        &       &       &       &1      &       &       &       &       \\
        &       &       &       &       &1      &       &       &       \\
        &       &       &       &       &       &1      &       &       \\
        &       &       &       &       &       &       &1      &       \\
        &       &       &       &       &       &       &       &1      \\
};

\draw[dashed] ($0.5*(m-6-1.south west)+0.5*(m-7-1.north west)$) --($0.5*(m-6-9.south east)+0.5*(m-7-9.north east)$);

\node[above=of n-1-1] (top-1) {$u_1$};
\node[above=of n-1-2] (top-2) {$w_1$};
\node[above=of n-1-3] (top-3) {$\phi_1$};
\node[above=12pt of n-1-4] (top-4) {$u_2$};
\node[above=12pt of n-1-5] (top-5) {$w_2$};
\node[above=12pt of n-1-6] (top-6) {$\phi_2$};
\node[above=10pt of m-1-7] (top-7) {$u_3$};
\node[above=10pt of m-1-8] (top-8) {$w_3$};
\node[above=10pt of m-1-9] (top-9) {$\phi_3$};
\end{tikzpicture}
\end{eqnarray*}

\end{document}

答案1

首先,你应该避免eqnarray。对齐点周围有一些间距问题。然后,Tikz我会使用方程环境,而不是这里displaymath和用来array绘制矩阵。为了使括号正确,您可能需要更改一些字体相关的距离。这可能不是最好的解决方案,但我认为它有效。而且因为这是你的论文,所以你可以完全控制类型设置,它可能不应该与其他字体或大小一起编译。我还假设较低的 E_1 应该是 E_2(可能完全错误),并且字母应该在矩阵上方。我还添加了一些虚线垂直线,因为它看起来不错:-)

\documentclass{article}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{arydshln}%%% dashed lines
\usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning}
\begin{document}

\begin{displaymath}
  \begin{array}{c}
    E_1\left\{\rule{0pt}{57pt}\right.\\[10pt]
    E_2\left\{\rule{0pt}{57pt}\right.
  \end{array}%
  \left[
    \begin{array}{@{}c@{}}
      d^{(1)}_1\\[5pt]
      \llap{\ensuremath i\rule{8pt}{0pt}}d^{(1)}_2\\[5pt] %% Write the letters to the left of the vector
      d^{(1)}_3\\[5pt]
      d^{(1)}_4\\[5pt]
      \llap{\ensuremath k\rule{8pt}{0pt}}d^{(1)}_5\\[5pt]
      d^{(1)}_6\\[3pt]\hdashline[4pt/2pt]\\[-7pt] %% relatively centered line
      d^{(2)}_1\\[5pt]
      \llap{\ensuremath i\rule{8pt}{0pt}}d^{(2)}_2\\[5pt]
      d^{(2)}_3\\[5pt]
      d^{(2)}_4\\[5pt]
      \llap{\ensuremath k\rule{8pt}{0pt}}d^{(2)}_5\\[5pt]
      d^{(2)}_6
    \end{array}
  \right]
  =
  \begin{matrix}
    \overbrace{\rule{58pt}{0pt}}^{A}
    \overbrace{\rule{58pt}{0pt}}^{B}
    \overbrace{\rule{58pt}{0pt}}^{C}\\
    \strut\\
    \left[
      \begin{array}{@{}ccc;{4pt/2pt}ccc;{4pt/2pt}ccc@{}}
        \raisebox{15pt}[0pt][0pt]{$u_1$} &
        \raisebox{15pt}[0pt][0pt]{$w_1$} &
        \raisebox{15pt}[0pt][0pt]{$\phi_1$} &
        \raisebox{15pt}[0pt][0pt]{$u_2$} &
        \raisebox{15pt}[0pt][0pt]{$w_2$} &
        \raisebox{15pt}[0pt][0pt]{$\phi_2$} &
        \raisebox{15pt}[0pt][0pt]{$u_3$} &
        \raisebox{15pt}[0pt][0pt]{$w_3$} &
        \raisebox{15pt}[0pt][0pt]{$\phi_3$}\\[-10pt]
        1       &       &       &       &       &       &       &       &       \\
                &1      &       &       &       &       &       &       &       \\
                &       &1      &       &       &       &       &       &       \\
                &       &       &1      &       &       &       &       &       \\
                &       &       &       &1      &       &       &       &       \\
                &       &       &       &       &1      &       &       &       \\\hdashline[4pt/2pt]
                &       &       &1      &       &       &       &       &       \\
                &       &       &       &1      &       &       &       &       \\
                &       &       &       &       &1      &       &       &       \\
                &       &       &       &       &       &1      &       &       \\
                &       &       &       &       &       &       &1      &       \\
                &       &       &       &       &       &       &       &1   
      \end{array}
    \right]\\
    \rule{0pt}{26pt}%% Extra space below to compensate for braces above
  \end{matrix}
\end{displaymath}

在此处输入图片描述

编辑以解决 OP 的后续问题。

要交换等式,即让 d 向量位于右侧,我们还必须交换括号。也就是说,对前导码和大型二进制(?)矩阵进行一些剪辑,

[...clip...]
                &       &       &       &       &       &       &1      &       \\
                &       &       &       &       &       &       &       &1   
      \end{array}
    \right]\\
    \rule{0pt}{26pt}
  \end{matrix}
  =
  \left[
    \begin{array}{@{}c@{}}
      d^{(1)}_1\\[5pt]
      d^{(1)}_2\rlap{\rule{8pt}{0pt}$i$}\\[5pt]
      d^{(1)}_3\\[5pt]
      d^{(1)}_4\\[5pt]
      d^{(1)}_5\rlap{\rule{8pt}{0pt}$k$}\\[5pt]
      d^{(1)}_6\\[3pt]\hdashline[4pt/2pt]\\[-7pt]
      d^{(2)}_1\\[5pt]
      d^{(2)}_2\rlap{\rule{8pt}{0pt}$i$}\\[5pt]
      d^{(2)}_3\\[5pt]
      d^{(2)}_4\\[5pt]
      d^{(2)}_5\rlap{\rule{8pt}{0pt}$k$}\\[5pt]
      d^{(2)}_6
    \end{array}
  \right]
  \begin{array}{c}
    \left.\rule{0pt}{57pt}\right\}E_1\\
    \left.\rule{0pt}{57pt}\right\}E_2
  \end{array}
\end{displaymath}

在此处输入图片描述

答案2

这显示了使用 OP 代码的解决方案TiKZ

原始代码包含一个拼写错误,避免绘制第二条虚线。节点m-6-1被引用,但应该是n-6-1。所以我替换了

\draw[dashed] ($0.5*(m-6-1.south west)+0.5*(m-7-1.north west)$) --($0.5*(m-6-9.south east)+0.5*(m-7-9.north east)$);

\draw[dashed] (n.center-|n-1-1.west) --(n.center-|n-6-9.east);

矩阵由内部节点( ,,...)和矩阵节点TikZ组成,也可以绘制、引用...由于虚线应穿过节点和之间,因此可以应用垂直坐标系。n-1-1n-2-1nn.centern-1-1n-1-9

下一个问题是上部节点的对齐。这种错位是由于内部节点的大小不同造成的。above = of n-1-1将参考点固定在,n-1-1.north并且该点不在同一水平线上,n-1-2.north因为n-1-2是空节点。这个问题也可以用垂直参考再次解决。一旦top-1放置了节点,就可以将其用作水平参考:

\node[above=3mm of n-1-1] (top-1) {$u_1$};
\node (top-2) at (top-1-|n-1-2) {$w_1$};
...

最后,水平支撑可以用以下方式绘制decoration

\draw [decorate, decoration={brace, raise=0mm, amplitude=3mm}] (top-1.north west)--(top-3.north east) node[above=4mm, midway]{$A$};

在此处输入图片描述

完整代码如下

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning}
\begin{document}

\[
\begin{tikzpicture}
[baseline=-\the\dimexpr\fontdimen22\textfont2\relax ]
\matrix (m)[matrix of math nodes,left delimiter={[},right delimiter={]},,nodes in empty cells]
{
    d^{(1)}_1\\
    d^{(1)}_2\\
    d^{(1)}_3\\
    d^{(1)}_4\\
    d^{(1)}_5\\
    d^{(1)}_6\\
    %
    d^{(2)}_1\\
    d^{(2)}_2\\
    d^{(2)}_3\\
    d^{(2)}_4\\
    d^{(2)}_5\\
    d^{(2)}_6\\
 };

\draw[dashed] ($0.5*(m-6-1.south west)+0.5*(m-7-1.north west)$) --
($0.5*(m-6-1.south east)+0.5*(m-7-1.north east)$);

\node[left=12pt of m-2-1] (left-1) {i};
\node[left=12pt of m-5-1] (left-2) {k};
\node[left=12pt of m-8-1] (left-3) {i};
\node[left=12pt of m-11-1](left-4) {k};

\node[rectangle,left delimiter=\{] (del-left-1) at ($0.5*(left-1.east) +0.5*(left-2.east)$) {\tikz{\path (left-1.north east) rectangle (left-2.south west);}};
\node[left=12pt] at (del-left-1.west) {$E_1$};

\node[rectangle,left delimiter=\{] (del-left-3) at ($0.5*(left-3.east) +0.5*(left-4.east)$) {\tikz{\path (left-3.north east) rectangle (left-4.south west);}};
\node[left=12pt] at (del-left-3.west) {$E_1$};
\end{tikzpicture}
=
\begin{tikzpicture}
[baseline=-\the\dimexpr\fontdimen22\textfont2\relax ]
\matrix (n)[matrix of math nodes,left delimiter={[},right delimiter={]},column sep=0.5cm, nodes in empty cells]{
1       &       &       &       &       &       &       &       &       \\
        &1      &       &       &       &       &       &       &       \\
        &       &1      &       &       &       &       &       &       \\
        &       &       &1      &       &       &       &       &       \\
        &       &       &       &1      &       &       &       &       \\
        &       &       &       &       &1      &       &       &       \\
        &       &       &1      &       &       &       &       &       \\
        &       &       &       &1      &       &       &       &       \\
        &       &       &       &       &1      &       &       &       \\
        &       &       &       &       &       &1      &       &       \\
        &       &       &       &       &       &       &1      &       \\
        &       &       &       &       &       &       &       &1      \\
};

\draw[dashed] (n.center-|n-1-1.west) --(n.center-|n-6-9.east);

\node[above=3mm of n-1-1] (top-1) {$u_1$};
\node (top-2) at (top-1-|n-1-2) {$w_1$};
\node (top-3) at (top-1-|n-1-3) {$\phi_1$};
\node (top-4) at (top-1-|n-1-4) {$u_2$};
\node (top-5) at (top-1-|n-1-5) {$w_2$};
\node (top-6) at (top-1-|n-1-6) {$\phi_2$};
\node (top-7) at (top-1-|n-1-7) {$u_3$};
\node (top-8) at (top-1-|n-1-8) {$w_3$};
\node (top-9) at (top-1-|n-1-9) {$\phi_4$};

\draw [decorate, decoration={brace, raise=0mm, amplitude=3mm}] (top-1.north west)--(top-3.north east) node[above=4mm, midway]{$A$};
\draw [decorate, decoration={brace, raise=0mm, amplitude=3mm}] (top-4.north west)--(top-6.north east) node[above=4mm, midway]{$B$};
\draw [decorate, decoration={brace, raise=0mm, amplitude=3mm}] (top-7.north west)--(top-9.north east) node[above=4mm, midway]{$C$};
\end{tikzpicture}
\]

\end{document}

相关内容