TikZ 矩阵图、隐藏节点和格式问题

TikZ 矩阵图、隐藏节点和格式问题

我试图展示当某些节点被移除时立方体结构的演变。这是我的初始图表:

\documentclass[12pt,tikz]{standalone}

% AMS Math Packages

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}

% Font Settings

\usepackage[T1]{fontenc}
\usepackage{stix}
\usepackage[english]{babel}
\usepackage[kerning,spacing,babel,final]{microtype}

\usepackage{tikz}
\usetikzlibrary{arrows,positioning,matrix}
\tikzset{
    >=stealth,
    auto,
    font=\scriptsize,
    point/.style={circle,draw,very thick,align=center,
                  anchor=center},
    Point/.style={double,circle,draw,very thick,align=center,
                  anchor=center},
    transform shape,
}

\begin{document}

\begin{tikzpicture}
    \centering
    \matrix (m) [matrix of nodes, row sep=0.5cm,column sep=1.25cm] {
        &
        \node (1) [point] {$110$};
        & &
        \node (2) [point] {$010$}; \\
        \node (3) [Point] {$111$};
        & &
        \node (4) [point] {$011$};
        & \\ &
        \node (5) [point] {$100$};
        & &
        \node (6) [point] {$000$}; \\
        \node (7) [point] {$101$};
        & &
        \node (8) [point] {$001$};
        & \\
    };
    \path[solid]
        (1) edge [loop above,very thick] (1)
        (2) edge [loop above,very thick] (2)
        (3) edge [loop above,very thick] (3)
        (4) edge [loop above,very thick] (4)
        (5) edge [loop below,very thick] (5)
        (6) edge [loop below,very thick] (6)
        (7) edge [loop below,very thick] (7)
        (8) edge [loop below,very thick] (8)
        (1) [<->,very thick] edge node[above right, pos=0.75,
            minimum size=0pt] {$A$} (2)
        (1) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (3)
        (2) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (4)
        (2) [<->,very thick] edge node[above left, pos=0.4,
            minimum size=0pt] {$B$} (6)
        (3) [<->,very thick] edge node[above right, pos=0.75,
            minimum size=0pt] {$A$} (4)
        (3) [<->,very thick] edge node[above left, pos=0.4,
            minimum size=0pt] {$B$} (7)
        (4) [<->,very thick] edge node[above left, pos=0.4,
            minimum size=0pt] {$B$} (8)
        (6) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (8)
        (7) [<->,very thick] edge node[above right, pos=0.75,
            minimum size=0pt] {$A$} (8)
        ;
    \path[dotted]
        (1) [<->,very thick] edge node[above left, pos=0.4,
            minimum size=0pt] {$B$} (5)
        (5) [<->,very thick] edge node[above right, pos=0.75,
            minimum size=0pt] {$A$} (6)
        (5) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (7)
        ;
\end{tikzpicture}

\end{document}

这给了我以下图像:

初始状态

现在,我使用它作为模板,并从本质上删除了节点:2、5、6 和 8(以及它们各自的边):

\documentclass[12pt,tikz]{standalone}

% AMS Math Packages

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}

% Font Settings

\usepackage[T1]{fontenc}
\usepackage{stix}
\usepackage[english]{babel}
\usepackage[kerning,spacing,babel,final]{microtype}

\usepackage{tikz}
\usetikzlibrary{arrows,positioning,matrix}
\tikzset{
    >=stealth,
    auto,
    font=\scriptsize,
    point/.style={circle,draw,very thick,align=center,
                  anchor=center},
    Point/.style={double,circle,draw,very thick,align=center,
                  anchor=center},
    transform shape,
}

\begin{document}

\begin{tikzpicture}
    \centering
    \matrix (m) [matrix of nodes, row sep=0.5cm,column sep=1.25cm] {
        &
        \node (1) [point] {$110$};
        & & & \\
        %\node (2) [point] {$010$}; \\
        \node (3) [Point] {$111$};
        & &
        \node (4) [point] {$011$};
        & \\ &
        % \node (5) [point] {$100$};
        & & & & \\
        %\node (6) [point] {$000$}; \\
        \node (7) [point] {$101$};
        & &
        %\node (8) [point] {$001$};
        & & \\
    };
    \path[solid]
        (1) edge [loop above,very thick] (1)
        %(2) edge [loop above,very thick] (2)
        (3) edge [loop above,very thick] (3)
        (4) edge [loop above,very thick] (4)
        %(5) edge [loop below,very thick] (5)
        %(6) edge [loop below,very thick] (6)
        (7) edge [loop below,very thick] (7)
        %(8) edge [loop below,very thick] (8)
        %(1) [<->,very thick] edge node[above right, pos=0.75,
        %    minimum size=0pt] {$A$} (2)
        (1) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (3)
        %(2) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (4)
        %(2) [<->,very thick] edge node[above left, pos=0.4,
        %    minimum size=0pt] {$B$} (6)
        (3) [<->,very thick] edge node[above right, pos=0.75,
            minimum size=0pt] {$A$} (4)
        (3) [<->,very thick] edge node[above left, pos=0.4,
            minimum size=0pt] {$B$} (7)
        %(4) [<->,very thick] edge node[above left, pos=0.4,
        %    minimum size=0pt] {$B$} (8)
        %(6) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (8)
        %(7) [<->,very thick] edge node[above right, pos=0.75,
        %    minimum size=0pt] {$A$} (8)
        ;
    \path[dotted]
        %(1) [<->,very thick] edge node[above left, pos=0.4,
        %    minimum size=0pt] {$B$} (5)
        %(5) [<->,very thick] edge node[above right, pos=0.75,
        %    minimum size=0pt] {$A$} (6)
        %(5) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (7)
        ;
\end{tikzpicture}

\end{document}

这给出了以下结果:

继承国

奇怪的是,节点和格式之间的距离似乎不对,而且图的右侧有一大片额外的空白。

我希望基本保持第一幅图的尺寸和所有内容不变,但隐藏节点和边,其他所有内容保持不变。标记为 111 和 101 的节点之间的尺寸应保持不变,所有剩余标签也应保持原样。我还想摆脱那一团乱麻,这样我就可以轻松地将它们包含在演示文稿和文档中,而不必考虑右侧的所有额外空间。

答案1

问题在于它们的nodes尺寸不为零,并且这些尺寸进一步拉大了图表的间距。您可以通过保留节点100但使其不可见来解决这个问题。

\documentclass[12pt]{article}

% AMS Math Packages

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}

% Font Settings

\usepackage[T1]{fontenc}
\usepackage{stix}
\usepackage[english]{babel}
\usepackage[kerning,spacing,babel,final]{microtype}

\usepackage{tikz}
\usetikzlibrary{arrows,positioning,matrix}
\tikzset{
    >=stealth,
    auto,
    font=\scriptsize,
    point/.style={circle,draw,very thick,align=center,
                  anchor=center},
    Point/.style={double,circle,draw,very thick,align=center,
                  anchor=center},
    transform shape,
}

\begin{document}
\begin{tikzpicture}
    \centering
    \matrix (m) [matrix of nodes, row sep=0.5cm,column sep=1.25cm] {
        &
        \node (1) [point] {$110$};
        & &
%       \node (2) [point] {$010$}; 
        \\
        \node (3) [Point] {$111$};
        & &
        \node (4) [point] {$011$};
        & \\ &
        \node (5) [point,opacity=0] {\phantom{$000$}};
        & &
%        \node (6) [point] {\phantom{$000$}};
        \\
        \node (7) [point] {$101$};
        & &
        %\node (8) [point] {$001$};
        & \\
    };
    \path[solid]
        (1) edge [loop above,very thick] (1)
        %(2) edge [loop above,very thick] (2)
        (3) edge [loop above,very thick] (3)
        (4) edge [loop above,very thick] (4)
        %(5) edge [loop below,very thick] (5)
        %(6) edge [loop below,very thick] (6)
        (7) edge [loop below,very thick] (7)
        %(8) edge [loop below,very thick] (8)
        %(1) [<->,very thick] edge node[above right, pos=0.75,
        %    minimum size=0pt] {$A$} (2)
        (1) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (3)
        %(2) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (4)
        %(2) [<->,very thick] edge node[above left, pos=0.4,
        %    minimum size=0pt] {$B$} (6)
        (3) [<->,very thick] edge node[above right, pos=0.75,
            minimum size=0pt] {$A$} (4)
        (3) [<->,very thick] edge node[above left, pos=0.4,
            minimum size=0pt] {$B$} (7)
        %(4) [<->,very thick] edge node[above left, pos=0.4,
        %    minimum size=0pt] {$B$} (8)
        %(6) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (8)
        %(7) [<->,very thick] edge node[above right, pos=0.75,
        %    minimum size=0pt] {$A$} (8)
        ;
    \path[dotted]
        %(1) [<->,very thick] edge node[above left, pos=0.4,
        %    minimum size=0pt] {$B$} (5)
        %(5) [<->,very thick] edge node[above right, pos=0.75,
        %    minimum size=0pt] {$A$} (6)
        %(5) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (7)
        ;
\end{tikzpicture}
\begin{tikzpicture}
    \centering
    \matrix (m) [matrix of nodes, row sep=0.5cm,column sep=1.25cm] {
        &
        \node (1) [point] {$110$};
        & &
        \node (2) [point] {$010$}; \\
        \node (3) [Point] {$111$};
        & &
        \node (4) [point] {$011$};
        & \\ &
        \node (5) [point] {$100$};
        & &
        \node (6) [point] {$000$}; \\
        \node (7) [point] {$101$};
        & &
        \node (8) [point] {$001$};
        & \\
    };
    \path[solid]
        (1) edge [loop above,very thick] (1)
        (2) edge [loop above,very thick] (2)
        (3) edge [loop above,very thick] (3)
        (4) edge [loop above,very thick] (4)
        (5) edge [loop below,very thick] (5)
        (6) edge [loop below,very thick] (6)
        (7) edge [loop below,very thick] (7)
        (8) edge [loop below,very thick] (8)
        (1) [<->,very thick] edge node[above right, pos=0.75,
            minimum size=0pt] {$A$} (2)
        (1) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (3)
        (2) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (4)
        (2) [<->,very thick] edge node[above left, pos=0.4,
            minimum size=0pt] {$B$} (6)
        (3) [<->,very thick] edge node[above right, pos=0.75,
            minimum size=0pt] {$A$} (4)
        (3) [<->,very thick] edge node[above left, pos=0.4,
            minimum size=0pt] {$B$} (7)
        (4) [<->,very thick] edge node[above left, pos=0.4,
            minimum size=0pt] {$B$} (8)
        (6) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (8)
        (7) [<->,very thick] edge node[above right, pos=0.75,
            minimum size=0pt] {$A$} (8)
        ;
    \path[dotted]
        (1) [<->,very thick] edge node[above left, pos=0.4,
            minimum size=0pt] {$B$} (5)
        (5) [<->,very thick] edge node[above right, pos=0.75,
            minimum size=0pt] {$A$} (6)
        (5) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (7)
        ;
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容