答案1
这是使用和锚点的选项fit
:
\documentclass[border=10pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage[siunitx, RPvoltages]{circuitikz}
\usetikzlibrary{fit}
\begin{document}
\begin{tikzpicture}[]
% suppose this is the part of circuit of interest
\draw (0,3) -- ++(2,0) (0,0) -- ++(2,0);
\draw (1,3) coordinate(up) to[generic, name=z1, *-*] (1,0) coordinate(down);
\node [font=\footnotesize] at (z1.center){$Z_1$};
% add an auto-fitting node for the dashed part
\node [draw, dashed, fit=(up) (down) (z1), inner xsep=0.5cm,
inner ysep=0.8cm](dashed box){};
% notice that `above right` is the same as `anchor=south west`
\node [draw, thick, font=\tiny\ttfamily, outer sep=1mm, above right]
at (dashed box.south west) {A1};
\end{tikzpicture}
\end{document}
答案2
像这样:
代码:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[dashed] (-3.25,-5.25) rectangle (3.25,5.25);
\draw[line width=2pt] (-4,4)--(4,4);
\draw[line width=2pt] (4,4.2)--(4,3.8);
\draw[line width=2pt] (-4,-4)--(4,-4);
\filldraw[line width=2pt] (0,-4) circle(3pt)--(0,4) circle(3pt);
\filldraw[fill=white,draw,line width=2pt] (-.5,-1) rectangle (.5,1);
\draw (0,0) node () {\Large \bfseries $Z_1$};
\draw[line width=2pt] (-3,-5) rectangle (-2,-4.25);
\draw (-2.5,-4.6) node () {\Large \bfseries $A1$};
\end{tikzpicture}
\end{document}