节点右侧的多余空白

节点右侧的多余空白

我尝试使用 tikz 库 matrix 和 matrix.skeleton 来描绘多个矩阵。稍后我想在两个矩阵上使用 matrix.skeleton 的突出显示功能。

这是我的想法:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usetikzlibrary{matrix.skeleton}
\usetikzlibrary{calc}

\begin{document}


\begin{tikzpicture}


\matrix (X) [matrix of math nodes,
            label skeleton,
             left delimiter  = (,
             right delimiter = )] at (0,0)
{%
  \vdots & \vdots &  & \vdots  \\
  x & x & \cdots & x \\
  \vdots & \vdots &  & \vdots  \\
  x & x & \cdots & x\\
  \vdots & \vdots &  & \vdots  \\
  x & x & \cdots & x\\
  \vdots & \vdots &  & \vdots  \\
  x & x & \cdots & x\\
  \vdots & \vdots &  & \vdots  \\
  x & x & \cdots & x\\
};

\matrix (U) [matrix of math nodes,
            label skeleton,
             left delimiter  = (,
             right delimiter = )] at (4.5,0)
{
  \vdots  \\
  u\\
  \vdots \\
  u\\
  \vdots \\
  u\\
  \vdots \\
  u\\
  \vdots \\
  u\\
};

\fitandstyle{(X-cell-2-1) (X-cell-6-4)}{draw=red, fill=red!25, opacity=0.5}
\fitandstyle{(U-cell-4-1) (U-cell-8-1)}{draw=red, fill=red!25, opacity=0.5,xshift=-4.5cm}

\draw[red,dashed] (X-cell-2-4.north east) -- ($(U-cell-4-1.north west)+(-4.5cm,0)$);
\draw[red,dashed] (X-cell-6-4.south east) -- ($(U-cell-8-1.south west)+(-4.5cm,0)$);

\end{tikzpicture}
\end{document}

多能运动的结果

这会在第二个矩阵的右侧创建一个额外的空白。我注意到当我通过标签骨架使用 matrix.skeleton 库时会发生这种情况。但是,我在 CTAN 包的手册中找不到解决方案。

答案1

新答案

matrix.skeleton库的设计旨在简化库的使用fit。但它不再维护。在这里你只需要使用fit不会引起任何matrix.skeleton应该解决的问题的库。 截屏

\documentclass{standalone}
\usepackage{tikz}

\usetikzlibrary{matrix}
\usetikzlibrary{fit}

\begin{document}


\begin{tikzpicture}


\matrix (X) [matrix of math nodes,
            %label skeleton,
             left delimiter  = (,
             right delimiter = )] at (0,0)
{%
  \vdots & \vdots &  & \vdots  \\
  x & x & \cdots & x \\
  \vdots & \vdots &  & \vdots  \\
  x & x & \cdots & x\\
  \vdots & \vdots &  & \vdots  \\
  x & x & \cdots & x\\
  \vdots & \vdots &  & \vdots  \\
  x & x & \cdots & x\\
  \vdots & \vdots &  & \vdots  \\
  x & x & \cdots & x\\
};

\matrix (U) [matrix of math nodes,
            %label skeleton,
             left delimiter  = (,
             right delimiter = )] at (4.5,0)
{
  \vdots  \\
  u\\
  \vdots \\
  u\\
  \vdots \\
  u\\
  \vdots \\
  u\\
  \vdots \\
  u\\
};

%\fitandstyle{(X-cell-2-1) (X-cell-6-4)}{draw=red, fill=red!25, opacity=0.5}
%\fitandstyle{(U-cell-4-1) (U-cell-8-1)}{draw=red, fill=red!25, opacity=0.5,xshift=-4.5cm}
\node [fit=(X-2-1) (X-6-4),draw=red, fill=red!25, opacity=0.5,inner sep=0pt]{};
\node [fit=(U-4-1) (U-8-1),draw=red, fill=red!25, opacity=0.5,inner sep=0pt]{};
\draw[red,dashed] (X-2-4.north east) -- (U-4-1.north west);
\draw[red,dashed] (X-6-4.south east) -- (U-8-1.south west);

\end{tikzpicture}
\end{document}

旧答案

通过不对第二个矩阵使用 matrix.skeleton 包,一切正常运行。

截屏

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usetikzlibrary{matrix.skeleton}
\usetikzlibrary{calc}

\begin{document}


\begin{tikzpicture}
\matrix (X) [matrix of math nodes,
            label skeleton,
             left delimiter  = (,
             right delimiter = )] at (0,0)
{%
  \vdots & \vdots &  & \vdots  \\
  x & x & \cdots & x \\
  \vdots & \vdots &  & \vdots  \\
  x & x & \cdots & x\\
  \vdots & \vdots &  & \vdots  \\
  x & x & \cdots & x\\
  \vdots & \vdots &  & \vdots  \\
  x & x & \cdots & x\\
  \vdots & \vdots &  & \vdots  \\
  x & x & \cdots & x\\
};

\matrix (U) [matrix of math nodes,
            %label skeleton,
             left delimiter  = (,
             right delimiter = )] at (4,0)
{%
  \vdots  \\
  u\\
  \vdots \\
  u\\
  \vdots \\
  u\\
  \vdots \\
  u\\
  \vdots \\
  u\\
};

\end{tikzpicture}
\end{document}

答案2

与其他人一样,我认为图书馆存在一些问题matrix.skeleton

右侧的空间与 x 坐标的宽度完全相同(如果 x 坐标为负,则空间位于左侧。)y 坐标对矩阵的顶部和底部产生相同的问题。

您可以执行以下操作来解决问题:

\documentclass[
    tikz
    ]{standalone}

\usetikzlibrary{matrix}
\usetikzlibrary{matrix.skeleton}
\usetikzlibrary{calc}

\begin{document}


\begin{tikzpicture}

\matrix (X) [matrix of math nodes,
            label skeleton,
            left delimiter  = (,
            right delimiter = )]
{%
  \vdots & \vdots &  & \vdots  \\
  x & x & \cdots & x \\
  \vdots & \vdots &  & \vdots  \\
  x & x & \cdots & x\\
  \vdots & \vdots &  & \vdots  \\
  x & x & \cdots & x\\
  \vdots & \vdots &  & \vdots  \\
  x & x & \cdots & x\\
  \vdots & \vdots &  & \vdots  \\
  x & x & \cdots & x\\
};

\node () at (4, 0){
\begin{tikzpicture}
    \matrix (U) [matrix of math nodes,
                 label skeleton,
                 left delimiter  = (,
                 right delimiter = )]
    {
      \vdots  \\
      u\\
      \vdots \\
      u\\
      \vdots \\
      u\\
      \vdots \\
      u\\
      \vdots \\
      u\\
    };
\end{tikzpicture}
};


\end{tikzpicture}
\end{document}

我知道这很混乱,但是它确实有效。

答案3

matrix.skeleton tikz 库中有一个错误。维护者已收到通知。目前尚未修复。

相关内容