节点中间的线 - 保留标签位置

节点中间的线 - 保留标签位置

从回答我之前的问题, 我有这个:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{positioning}
\begin{document}
\pagestyle{empty}

\def\layersep{2.5cm}

\begin{tikzpicture}[
      shorten >=1pt,->,draw=black!50, node distance=\layersep,
      every pin edge/.style={<-,shorten <=1pt},
      neuron/.style={circle split,fill=black!25,minimum size=17pt,inner sep=0pt},
      input neuron/.style={neuron, fill=green!50},
      output neuron/.style={neuron, fill=red!50},
      compute neuron/.style={neuron, fill=blue!50},
      annot/.style={text width=4em, text centered}
    ]

    % Draw the input layer nodes
    \foreach \name / \y in {1,...,4}
    % This is the same as writing \foreach \name / \y in {1/1,2/2,3/3,4/4}
    \node[input neuron, pin position=-90, rotate=90] (I-\name) at (0,-\y) {};

    \node[left=1pt of I-1]{$h_0$};
    % Draw the compute layer nodes
    \foreach \name / \y in {1,...,5}
        \path[yshift=0.5cm]
            node[compute neuron,rotate=90] (C-\name) at (\layersep,-\y cm) {};

    % Draw the output layer node
    \node[output neuron,pin={[pin edge={->}]right:Output}, right of=C-3,rotate=90] (O) {};

    % Connect every node in the input layer with every node in the
    % compute layer.
    \foreach \source in {1,...,4}
        \foreach \dest in {1,...,5}
            \path (I-\source) edge (C-\dest);

    % Connect every node in the compute layer with the output layer
    \foreach \source in {1,...,5}
        \path (C-\source) edge (O);

    % Annotate the layers
    \node[annot,above of=C-1, node distance=1cm] (hl) {compute layer};
    \node[annot,left of=hl] {Input layer};
    \node[annot,right of=hl] {Compute layer};
\end{tikzpicture}
% End of code
\end{document}

注意 $h_0$ 标签的问题。我希望该标签位于节点左侧。我希望其他标签位于节点上方。我该如何实现?节点旋转以适应垂直线似乎会影响标签,但我需要两者。

答案1

像这样?

在此处输入图片描述

仍然部分基于猜测,但无论如何。生成上述图像的 MWE 基于我的答案在这里

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\newcommand\ppbb{path picture bounding box}

\begin{document}
\pagestyle{empty}

\def\layersep{2.5cm}

\begin{tikzpicture}[shorten >=1pt, ->, draw=black!50, 
        node distance = \layersep,
every pin edge/.style = {<-, shorten <=1pt},
   every label/.style = {label distance=0pt, inner sep=1pt,font=\small},
        neuron/.style = {circle, minimum size=17pt, inner sep=0pt,  
                         path picture={%
                         \path[draw=black!75,semithick,-]   (\ppbb.north)  -- (\ppbb.south);},
                         },
  input neuron/.style = {neuron, fill=green!50},
 output neuron/.style = {neuron, fill=red!50},
compute neuron/.style = {neuron, fill=blue!50},
         annot/.style = {text width=4em, text centered},
                    ]
% Draw the input layer nodes
\foreach \y [count=\yi from 0] in {1,...,4}
{\ifnum\y=1
    \node[input neuron, label=left:$h_\yi$] (I-\y) at (0,-\y)  {};
 \else  
    \node[input neuron, label=$h_\yi$] (I-\y) at (0,-\y) {};
 \fi
}
% Draw the compute layer nodes
\foreach \y [count=\yi from 0] in {1,...,5}
    \node[yshift=0.5cm,compute neuron,label=$C_\yi$] (C-\y) at (\layersep,-\y cm) {};
% Draw the output layer node
\node[output neuron,pin={[pin edge={->}]right:Output}, right=of C-3.west] (O) {};
% Connect every node in the input layer with every node in the
% compute layer.
\foreach \source in {1,...,4}
    \foreach \dest in {1,...,5}
        \path (I-\source) edge (C-\dest);
% Connect every node in the compute layer with the output layer
\foreach \source in {1,...,5}
    \path (C-\source) edge (O);
% Annotate the layers
    \begin{scope}[node distance=0pt]
\node[annot,above=4mm of C-1] (hl)      {Compute layer};
\node[annot,above=of hl.south -| I-1]   {Input layer};
\node[annot,above=of hl.south -| O]     {Output layer};

    \end{scope}
\end{tikzpicture}
% End of code
\end{document}

相关内容