关于图案和渐变的问题

关于图案和渐变的问题

我使用下面的代码绘制了一个图表。

在此处输入图片描述

\documentclass[tikz]{standalone}
\usetikzlibrary{
    shapes.geometric,
    positioning,
    fit,
    calc,
    patterns
}
\usepackage{tikz}
\usepackage{scalefnt}
\begin{document}

\pgfkeys{/tikz/.cd,
  gradient style init/.initial=left color,
  gradient style init/.get=\grsi,
  gradient style init/.store in=\grsi,
  gradient style end/.initial=right color,
  gradient style end/.get=\grse,
  gradient style end/.store in=\grse,
}

\tikzset{
 block/.style = {circle, draw,
    text width=1em,align=center,inner sep=0pt},
  line/.style = {draw,thick,->},
  oplus/.style={draw,circle, text width=1em,align=center,inner sep=0pt,
  postaction={path picture={%
    \draw[black]
      (path picture bounding box.south west) -- (path picture bounding box.north east)
      (path picture bounding box.north west) -- (path picture bounding box.south east);}}},
   my pattern/.style args={#1 colored by #2}{%
   path picture={
     \node[pattern=#1,pattern color=#2] at (path picture bounding box.center) {};
   }
  },
  my gradient/.style args={#1 and #2}{%
   \grsi=#1,
   \grse=#2,
 },
}
\begin{tikzpicture}
\node [block,my pattern=north east lines colored by blue!50,
  my gradient=orange!60 and yellow!40] (s13){13};
\end{tikzpicture}
\end{document} 

但是当我把图放到一个大树中时,圆圈里面只有两条蓝线。请问这是什么问题?蓝线和圆圈的大小有关吗?以下是新代码:

\documentclass[tikz]{standalone}
\usetikzlibrary{
    shapes.geometric,
    positioning,
    fit,
    calc,
    patterns
}
\usepackage{tikz}
\usepackage{scalefnt}
\begin{document}

\pgfkeys{/tikz/.cd,
  gradient style init/.initial=left color,
  gradient style init/.get=\grsi,
  gradient style init/.store in=\grsi,
  gradient style end/.initial=right color,
  gradient style end/.get=\grse,
  gradient style end/.store in=\grse,
}

\tikzset{
 block/.style = {circle, draw,
    text width=1em,align=center,inner sep=0pt},
  line/.style = {draw,thick,->},
  oplus/.style={draw,circle, text width=1em,align=center,inner sep=0pt,
  postaction={path picture={%
    \draw[black]
      (path picture bounding box.south west) -- (path picture bounding box.north east)
      (path picture bounding box.north west) -- (path picture bounding box.south east);}}},
   my pattern/.style args={#1 colored by #2}{%
   path picture={
     \node[pattern=#1,pattern color=#2] at (path picture bounding box.center) {};
   }
  },
  my gradient/.style args={#1 and #2}{%
   \grsi=#1,
   \grse=#2,
 },
}
{\scalefont{0.5}
\begin{tikzpicture}[node distance=4mm]
\node [block] (s1) {1};
\node [block,below = of s1] (s2) {2};
\node [block, below = of s2] (s5) {5};
\node [block,below = of s5,my pattern=north east lines colored by blue!50,
  my gradient=orange!60 and yellow!40] (s13){13};


\node [block, below = of s13] (s4) {4};

\end{tikzpicture}
}
\end{document} 

在此处输入图片描述

答案1

也许你可以使用

\begin{tikzpicture}[on grid,node distance=1cm]
\node [block] (s1) {1};
\node [block,below = of s1] (s2) {2};
\node [block, below = of s2] (s5) {5};

\node [block,my pattern=north east lines colored by blue!50,
  my gradient=orange!60 and yellow!40,below = of s5] (s13)  {13};
\node [block, below = of s13] (s4) {4};
\end{tikzpicture}

在此处输入图片描述

相关内容