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}

相关内容