如何使 tikz“路径图片”块的边框变为虚线?

如何使 tikz“路径图片”块的边框变为虚线?

我发现这个美丽的代码在线绘制了一个饱和块,可用于circuitikz等。这是一个MWE。

\documentclass[border=0pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}
\usepackage[siunitx,europeanresistors]{circuitikz}

\tikzset{%
  saturation block/.style={%
    draw,
    path picture={
      % Get the width and height of the path picture node
      \pgfpointdiff{\pgfpointanchor{path picture bounding box}{north east}}%
        {\pgfpointanchor{path picture bounding box}{south west}}
      \pgfgetlastxy\x\y
      % Scale the x and y vectors so that the range
      % -1 to 1 is slightly shorter than the size of the node
      \tikzset{x=\x*.4, y=\y*.4}
      %
      % Draw annotation
      \draw (-1,0) -- (1,0) (0,-1) -- (0,1); 
      \draw (-1,-.7) -- (-.7,-.7) -- (.7,.7) -- (1,.7);
    }
  }
}

\begin{document}
\begin{circuitikz}
    \draw (0,0) node[saturation block, minimum size=1cm] (sat1) {};
\end{circuitikz}
\end{document}

在此处输入图片描述

我怎样才能修改此代码,使得该块的边框(且只有边框)变为虚线?

答案1

如果将 用于dashed节点,则这将由内部绘图继承。您可以使用 覆盖它solid

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}
\usepackage[siunitx,europeanresistors]{circuitikz}

\tikzset{%
  saturation block/.style={%
    draw,
    path picture={
      % Get the width and height of the path picture node
      \pgfpointdiff{\pgfpointanchor{path picture bounding box}{north east}}%
        {\pgfpointanchor{path picture bounding box}{south west}}
      \pgfgetlastxy\x\y
      % Scale the x and y vectors so that the range
      % -1 to 1 is slightly shorter than the size of the node
      \tikzset{x=\x*.4, y=\y*.4}
      %
      % Draw annotation
      \draw[solid] (-1,0) -- (1,0) (0,-1) -- (0,1); 
      \draw[solid] (-1,-.7) -- (-.7,-.7) -- (.7,.7) -- (1,.7);
    }
  }
}

\begin{document}
\begin{circuitikz}
    \draw (0,0) node[saturation block, densely dashed, minimum size=1cm] (sat1) {};
\end{circuitikz}
\end{document}

在此处输入图片描述

densely dashed我认为输出效果更好)。

相关内容