不幸的是,线条覆盖了节点描述(tikz)

不幸的是,线条覆盖了节点描述(tikz)

我想将 Mermin 在第 17 页的 KS 类型证明可视化arXiv:1802.10119使用彩色粗线以下节点描述和不开描述。但在我的代码中,线条覆盖了描述,我不知道如何修复它。此外,如果线条不会在节点描述之前停止,那就太好了,这样五角星就可以完全看到。我不太熟悉 tikz,因此我手动定位了节点,这没问题 - 但我希望有人能帮助我解决颜色问题并使这张图片看起来更整洁。

到目前为止的代码:

\begin{tikzpicture}
\node(A)[draw=none,fill=none] at (0,0.5) {$\sigma^1_y$};
\node(B)[draw=none,fill=none] at (-0.8,-1){$\sigma_y^1\sigma_x^2\sigma_y^3$};
\node(C)[draw=none,fill=none] at (0.8,-1){$\sigma_y^1\sigma_y^2\sigma_x^3$};
\node(D)[draw=none,fill=none] at (2.4,-1){$\sigma_x^1\sigma_y^2\sigma_y^3$};
\node(E)[draw=none,fill=none] at (-2.4,-1){$\sigma_x^1\sigma_x^2\sigma_x^3$};
\node(F)[draw=none,fill=none] at (1.1,-1.9){$\sigma_y^3$};
\node(G)[draw=none,fill=none] at (-1.1,-1.9){$\sigma_x^3$};
\node(H)[draw=none,fill=none] at (0,-2.6){$\sigma_x^1$};
\node(I)[draw=none,fill=none] at (-2,-4){$\sigma_y^2$};
\node(J)[draw=none,fill=none] at (2,-4){$\sigma_x^2$};

\draw[magenta,thick](A)--(J);
\draw[magenta,thick](A)--(I);
\draw[magenta,thick](E)--(J);
\draw[magenta,thick](D)--(I);
\draw[blue,thick](D)--(E);
\end{tikzpicture}

我目前得到的结果很糟糕。

答案1

如果您想改善节点位置,您还可以使用intersections库和backgrounds库来确保线条在后台:

\documentclass[tikz]{standalone}
\usetikzlibrary{backgrounds,calc,intersections}

\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0.5);
\coordinate (J) at (2,-4);
\coordinate (E) at (-2.4,-1);
\coordinate (D)at (2.4,-1);
\coordinate (I) at (-2,-4);

\path[name path = de] (D)--(E);
\path[name path=aj] (A) -- (J);
\path[name path = ai] (A) -- (I);
\path[name path =di] (D) --(I) ;
\path[name path =ej] (E) --(J);
\path[name intersections ={of = aj and de,by=B}] ;
\path[name intersections ={of = ai and de,by=C}] ;
\path[name intersections = {of=aj and di,by=F}];
\path[name intersections = {of =ai and ej,by=G}];
\path[name intersections = {of =di and ej,by=H}];

\node at (C) {C};
\node at (B) {B};
\node at (F){F};
\node at (G){G};
\node at (H){H};

\begin{pgfonlayer}{background}
\draw[magenta,thick] (I) -- (A) node[black] {$\sigma^1_y$}--(J) node [black]{J}-- (E) node [black]{E} -- (D) node [black]{D} -- (I) node [black]{I};
\draw[blue,thick](D)--(E);
\end{pgfonlayer}
\end{tikzpicture}
\end{document}

在此处输入图片描述

(对图像进行编辑:用使用实际颜色的图像替换该图像。)

编辑:现在我可以在固定设备上正确地执行此操作,我删除了代码中的一些冗余部分,并使用极坐标来确保五角星的规则性。此外,我还更改了节点标签,使其更加数学化。

\documentclass[tikz]{standalone}
\usetikzlibrary{backgrounds,calc,intersections}

\begin{document}
    \begin{tikzpicture}
        \foreach \i/\j in {0/A, 1/B, 2/C, 3/D, 4/E}{
            \coordinate (\j) at ({90+72*\i}:2cm);
            }
        
        \path[name path = ac] (A) -- (C);
        \path[name path = ad] (A) -- (D);
        \path[name path = be] (B) -- (E);
        \path[name path = bd] (B) -- (D);
        \path[name path = ce] (E) -- (C);
        
        \node[name intersections = {of = ad and be,by=F}] at (F) {F};
        \node[name intersections = {of = ac and be,by=G}] at (G) {G};
        \node[name intersections = {of = ac and bd,by=H}] at (H) {H};
        \node[name intersections = {of = ce and bd,by=I}] at (I) {I};
        \node[name intersections = {of = ad and ce,by=J}] at (J) {J};
        
        \begin{pgfonlayer}{background}
            \begin{scope}[every node/.style={black}]
                \draw[magenta,thick] (A) node {A} -- (C) node {C} -- (E) node {E} -- (B) node {B} -- (D) node {D} -- cycle;
                \draw[blue,thick] (B)--(E);
            \end{scope}
        \end{pgfonlayer}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

我应该指出,在洋红色线的上方再次绘制蓝线当然不是很好,但不幸的是,这是获得尖锐边缘的必要条件。 仅更改此类路径的一部分的颜色有点复杂,并且已针对此问题进行了详细回答:TikZ:中途改变路径的颜色

答案2

有了这个:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[scale=4]
\foreach \x in{0,...,4} \coordinate (A\x) at ({sin(\x*72)},{cos(\x*72)});
\draw[name path=A02,thick,color=magenta] (A0)--(A2);
\draw[name path=A03,thick,color=magenta] (A0)--(A3);
\draw[thick,color=magenta] (A4)--(A2);
\draw[thick,color=magenta] (A3)--(A1);
\draw[name path=A14,thick,blue] (A4)--(A1);
\path[name intersections={of=A02 and A14,by=Ir}];
\path[name intersections={of=A03 and A14,by=Il}];
\node[above] at (A0) {$\sigma_y^1$};
\node[right] at (A1) {$\sigma_x^1\sigma_y^2\sigma_y^3$};
\node[below right] at (A2) {$\sigma_x^2$};
\node[below left] at (A3) {$\sigma_y^2$};
\node[left] at (A4) {$\sigma_x^1\sigma_x^2\sigma_x^3$};
\node[above right] at (Ir) {$\sigma_y^1\sigma_x^2\sigma_y^3$};
\node[above left] at (Il) {$\sigma_y^1\sigma_y^2\sigma_x^3$};
\end{tikzpicture}
\end{document}

我懂了:

在此处输入图片描述

答案3

现在很漂亮,至少我对结果很满意。我添加了白色填充以提高可读性。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usetikzlibrary{backgrounds,calc,intersections}

\begin{document}
\begin{tikzpicture}[scale=4]
\foreach \x in{0,...,4} \coordinate (A\x) at ({sin(\x*72)},{cos(\x*72)});
\path[name path = a1] (A0)--(A2);
\path[name path=a2] (A0) -- (A3);
\path[name path = a3] (A4) -- (A2);
\path[name path =a4] (A3) --(A1) ;
\path[name path =a5] (A4) --(A1);
\path[name intersections ={of = a2 and a3,by=B1}] ;
\path[name intersections ={of = a5 and a1,by=B2}] ;
\path[name intersections = {of=a3 and a4,by=B3}];
\path[name intersections = {of =a1 and a4,by=B4}];
\path[name intersections = {of =a5 and a2,by=B5}];


\node [black,rectangle,fill=white] at (B1) {$\sigma_x^3$};
\node [black,rectangle,fill=white] at (B2) {$\sigma_y^1\sigma_x^2\sigma_y^3$};
\node [black,rectangle,fill=white] at (B3){$\sigma_x^1$};
\node [black,rectangle,fill=white] at (B4){$\sigma_y^3$};
\node [black,rectangle,fill=white] at (B5){$\sigma_y^1\sigma_y^2\sigma_x^3$};

\begin{pgfonlayer}{background}
\draw[magenta,line width=1mm] (A0) -- (A2) node[black,rectangle,fill=white] {$\sigma_x^2$}--(A4) -- (A1)  -- (A3) node [black,rectangle,fill=white]{$\sigma_y^2$} -- (A0) node [black,rectangle,fill=white]{$\sigma_y^1$};
\draw[blue,line width=1mm](A4)node [black,rectangle,fill=white]{$\sigma_x^1\sigma_x^2\sigma_x^3$}--(A1)node [black,rectangle,fill=white]{$\sigma_x^1\sigma_y^2\sigma_y^3$};
\end{pgfonlayer}

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容