tikz 節點的放置與不透明度

tikz 節點的放置與不透明度

我有以下 MWE,我想將其用作防禦演示的路線圖。它基本上一切正常並且看起來不錯,但有兩件事我不知道如何解決。第一件事是如何使節點精確地出現在彼此之上,例如,論文的起始點右側對於從那裡離開的所有​​三個路徑都是相同的。第二個問題是如何使每個節點內的圓與線條和填充具有相同的不透明度。

\documentclass{standalone}

\usepackage[dvipsnames]{xcolor}

\usepackage{tikz}
\usepackage{lmodern}

\usepackage{pgfplots}

\usetikzlibrary{ arrows
                , positioning
                , calc
                , arrows.meta
                , shapes
                , snakes}
\colorlet{Navyblue}{NavyBlue}
\tikzstyle{project} = [
            align=left
        %, fill=NavyBlue
        , opacity=0.2
        , text opacity=1]

\newcommand{\myopacity}{1}

\begin{document}

\begin{tikzpicture}[baseline=(current bounding box.center), font=\sffamily, node distance=2cm]
\draw
  node[project,anchor=east](P) {\textbf{Dissertation}}

  node[project
        ,right= 2in of P.east
        , anchor=east
        , text opacity=0.4](P23) {}

   node[project
            , above= of P23.west
            , anchor = west
            ](P1) {\textbf{Project I:}}

   node[project
        , right = 1in of P23
        , text opacity=0.4](P2) {Project II: }
   node[project
        , below= 0.5in of P2.west
        , anchor=west
        , text opacity=0.4](P3) {Project III: }
    node[project
        , below= of P23.west
        , anchor=west
        , text opacity=0.4](P4) {Project IV:};                                                              
   % Define different colors
  \draw[{Circle[length=8pt]}-{Circle[length=8pt]}
        , line width=2pt
        , Gray
        , opacity = 0.4] (P.east) -- (P23.west);
  \draw[{Circle[length=8pt]}-{Circle[length=8pt]}
        , line width=2pt
        , darkgray
        , opacity = 0.4] (P23.east) -- (P2.west);
  \draw[{Circle[length=8pt]}-{Circle[length=8pt]}
        , line width=2pt
        , darkgray
        , opacity = 0.4
        ] (P23.east) -- (P3.west);
  \draw[{Circle[length=8pt]}-{Circle[length=8pt]}
            , line width=2pt
            , Gray
            , opacity = \myopacity] (P.east) -- (P1.west);
  \draw[{Circle[length=8pt]}-{Circle[length=8pt]}
        , line width=2pt
        , RoyalBlue
        , opacity = 0.4] (P.east) -- (P4.west);
    \draw[{Circle[length=8pt]}-{Circle[length=8pt]}
            , line width=2pt
            , Gray
            , opacity = \myopacity] (P.east) -- (P1.west);

\end{tikzpicture}

\end{document}

產生的圖形的螢幕截圖 這是第一條評論中提議的更改的結果: 結果

答案1

不要將文字放置在節點中:node[project,anchor=east](P) {\textbf{Dissertation}}

我把它們當作標籤。標籤是節點,它們具有與節點相同的選項,並且可以以相同的方式進行修改:node[project,anchor=east,label={left:\textbf{Dissertation}}](P) {}

這將允許您繪製圓形節點:

\tikzset{project/.style={ align=left 
                          %, fill=NavyBlue
                          , opacity=0.2 
                          , text opacity=1 
                          ,draw %draw a circle node 
                          ,circle}
                         }

這簡化了節點之間的畫線程式碼。後者連接空節點,不需要指定P.eastP23.west位置或將其末端畫成圓圈,如下所示:{Circle[length=8pt]}-{Circle[length=8pt]}

   \draw[{Circle[length=8pt]}-{Circle[length=8pt]}
        , line width=2pt
        , Gray
        , opacity = 0.4] (P.east) -- (P23.west);

代碼變為:

 \draw[%{Circle[length=8pt]}-{Circle[length=8pt]}
        , line width=2pt
        , Gray
        , opacity = 0.4] (P) edge (P23);

我對所有變得無用的程式碼行進行了評論,但沒有刪除它們。

我建立了一個新節點(P23')

  node[project
        ,right= 2in of P
        %, anchor=east
        , text opacity=0.4](P23) {}
  node[project
        ,right= 10pt of P23
        %, anchor=east
        , text opacity=0.4](P23') {}

螢幕截圖

\documentclass{standalone}

\usepackage[dvipsnames]{xcolor}

\usepackage{tikz}
\usepackage{lmodern}

\usepackage{pgfplots}

\usetikzlibrary{ %arrows
                , positioning
                , calc
                , arrows.meta
                , shapes
                , snakes}
\colorlet{Navyblue}{NavyBlue}
\tikzset{project/.style={
            align=left
        %, fill=NavyBlue
        , opacity=0.2
        , text opacity=1
        ,draw
        ,circle}}

\newcommand{\myopacity}{1}

\begin{document}

\begin{tikzpicture}[%baseline=(current bounding box.center),
 font=\sffamily,
  node distance=2cm]
\draw
  node[project,anchor=east,label={left:\textbf{Dissertation}}](P) {}

  node[project
        ,right= 2in of P
        %, anchor=east
        , text opacity=0.4](P23) {}
  node[project
        ,right= 10pt of P23
        %, anchor=east
        , text opacity=0.4](P23') {}
   node[project
            , above= of P23
            %, anchor = west
            , label= right:\textbf{Project I:}
            ](P1) {}

   node[project
        , right = 1in of P23
        , text opacity=0.4
        ,label=right:Project II: ](P2) {}
   node[project
        , below= 0.5in of P2
       % , anchor=west
        , text opacity=0.4,label=right:Project III: ](P3) {}
    node[project
        , below= of P23
        %, anchor=west
        , text opacity=0.4
        ,label=below:Project IV:](P4) {};                                                              
   % Define different colors
  \draw[%{Circle[length=8pt]}-{Circle[length=8pt]}
        , line width=2pt
        , Gray
        , opacity = 0.4] (P) edge (P23);
  \draw[%{Circle[length=8pt]}-{Circle[length=8pt]}
        , line width=2pt
        , darkgray
        , opacity = 0.4] (P23') -- (P2);
  \draw[%{Circle[length=8pt]}-{Circle[length=8pt]}
        , line width=2pt
        , darkgray
        , opacity = 0.4
        ] (P23') -- (P3);
  \draw[%{Circle[length=8pt]}-{Circle[length=8pt]}
            , line width=2pt
            , Gray
            , opacity = \myopacity] (P) -- (P1);
  \draw[%{Circle[length=8pt]}-{Circle[length=8pt]}
        , line width=2pt
        , RoyalBlue
        , opacity = 0.4] (P) -- (P4);
    \draw[%{Circle[length=8pt]}-{Circle[length=8pt]}
            , line width=2pt
            , Gray
            , opacity = \myopacity] (P) -- (P1);

\end{tikzpicture}

\end{document}

相關內容