我是 LaTeX 和 TikZ 的初学者,正在尝试将它们用于工业文档。下面的示例代码(主要是在之前的帮助下制作的)显示了用 制作的电路circuitikz
。但是我现在需要制作这个电路的一些变体,并且想知道是否可以使用另一种方法(例如\foreach
或其他解决方案)使代码更加灵活,从而最小化硬编码坐标的数量,从而简化某些尺寸的调整。任何帮助都值得赞赏。
\documentclass{article}
\usepackage{tikz}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz}[scale =1]
% Side vertical lines
\draw [ultra thick, gray!50] (0,-5)-- (0,2);
\draw [ultra thick, gray!50] (5,-5) -- (5,2);
% Black resistors
\draw (0,1) to[R=$R_1$,*-*] (2,1);
\draw (3,0) to [R=$R_1$,*-*] (5,0);
\draw (0,-1) to[R=$R_1$,*-*] (2,-1);
\draw (3,-2) to[R=$R_1$,*-*] (5,-2);
\draw (0,-3) to[R=$R_1$,*-*] (2,-3);
\draw (3,-4) to[R=$R_1$,*-*] (5,-4);
% Blue resistors
\begin{scope}[color=blue]
\draw (2,1) to [R=$R_2$] (3,0);
\draw (2,-1) to[R=$R_2$] (3,0);
\draw (2,-1) to [R=$R_2$] (3,-2);
\draw (2,-3) to[R=$R_2$] (3,-2);
\draw (2,-3) to[R=$R_2$] (3,-4);
\end{scope}
% the side messages
\node [anchor=south,rotate=90, gray] at (current bounding box.west) {\Large\textbf {Pin side}};
\node [anchor=north,rotate=90,gray] at (current bounding box.east) {\Large\textbf{Socket side}};
\end{circuitikz}
\end{document}
答案1
很难说你到底想做什么。我对代码做了一些修改,现在看起来像这样:
\documentclass{article}
\usepackage{tikz}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz}[scale =1]
% Side vertical lines with labels
\draw [ultra thick, gray!50] (0,-5) -- (0,2) node [midway, above, rotate=90, gray] {\Large\textbf{Pin side}};
\draw [ultra thick, gray!50] (5,-5) -- (5,2) node [midway, below, rotate=90, gray] {\Large\textbf{Socket side}};
% Black resistors
\draw (0,1) to[R=$R_1$,*-*] (2,1);
\draw (3,0) to [R=$R_1$,*-*] (5,0);
\draw (0,-1) to[R=$R_1$,*-*] (2,-1);
\draw (3,-2) to[R=$R_1$,*-*] (5,-2);
\draw (0,-3) to[R=$R_1$,*-*] (2,-3);
\draw (3,-4) to[R=$R_1$,*-*] (5,-4);
% Blue resistors
\begin{scope}[color=blue]
\draw (2,1) to [R=$R_2$] (3,0)
to [R=$R_2$] (2,-1)
to [R=$R_2$] (3,-2)
to [R=$R_2$] (2,-3)
to [R=$R_2$] (3,-4);
\end{scope}
\end{circuitikz}
\end{document}
如您所见,我已将两条垂直线的标签直接移动到绘制线条的命令中。我还改变了蓝色电阻器的绘图。
使用此解决方案,坐标仍然在代码中,但重复次数少了很多。