我想在某个东西周围放一个颜色框,基本上这次是一个电路,我还想放一根颜色更深的电线。这是我的代码:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{mathtools}
\usepackage[american]{circuitikz}
\usetikzlibrary{shapes,arrows}
\renewcommand*\contentsname{Contenido}
\begin{document}
\begin{figure}[h]
\begin{circuitikz}
%Diodo
\draw
[short, o-] to (0.3,0)
;
\ctikzset{bipoles/diode/height=0.4, bipoles/diode/width=0.4,}
\draw
(0.3,0) node[below right = 4.15mm,align=center]{+} to[diode, a = $v_\gamma$, i = $i$]
(3,0) node[below left = 4.15mm,align=center]{-}
;
\draw
(3,0) [short,-o] to (3.2,0)
;
%Circuito abierto
\draw
(5,0) [short, o-] to (6,0)
to [-o,open] (8,0)
;
\draw
(7.5,0) [short, o-] to (8.5,0)
to [-o,open] (10.5,0)
;
\draw
(5,0) node[above = 4mm, right = 1mm,align=center]{$\textcolor{red}{i}$ $\color{red}\longrightarrow$ } node[below = 10mm, right = 6mm,align=center]{$v<0\ $, $i=0$} to [open, v =$v$ ] (8.5,0)
;
%Corto circuito
\draw
(10,0) [short, o-] to (11,0)
to [-o,short] (13,0)
;
\draw
(12.5,0) [short, o-] to (13.5,0)
to [-o,short] (13.5,0)
;
\draw
(10,0) node[above = 4mm, right = 1mm,align=center]{$i$ $\longrightarrow$ } node[below = 10mm, right = 6mm,align=center]{$i>0\ $, $v=0$} to [open, v =$v$,red] (13.5,0)
;
\end{circuitikz}
\caption{Modelo Ideal}
\end{figure}
\end{document}
这或多或少就是我所认为的样子。
我很感谢你的帮助!
答案1
我加了一些钛钾Z 命令
\documentclass{article}
\usepackage{geometry}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{mathtools}
\usepackage[american]{circuitikz}
\usetikzlibrary{shapes,arrows}
\renewcommand*\contentsname{Contenido}
\begin{document}
\begin{figure}[h]
\centering
\begin{circuitikz}
%Diodo
\draw
[short, o-] to (0.3,0)
;
\ctikzset{bipoles/diode/height=0.4, bipoles/diode/width=0.4,}
\draw
(0.3,0) node[below right = 4.15mm,align=center]{+} to[diode, a = $v_\gamma$, i = $i$]
(3,0) node[below left = 4.15mm,align=center]{-}
;
\draw
(3,0) [short,-o] to (3.2,0)
;
%Circuito abierto
\fill[cyan!20] (5.8,-.2) rectangle (7.7,.2);
\draw
(5,0) [short, o-] to (6,0)
to [-o,open] (8,0)
;
\draw
(7.5,0) [short, o-] to (8.5,0)
to [-o,open] (10.5,0)
;
\draw
(5,0) node[above = 4mm, right = 1mm,align=center]{$\textcolor{red}{i}$ $\color{red}\longrightarrow$ } node[below = 10mm, right = 6mm,align=center]{$v<0\ $, $i=0$} to [open, v =$v$ ] (8.5,0)
;
%Corto circuito
\fill[cyan!20] (10.8,-.2) rectangle (12.7,.2);
\draw[ultra thick] (11,0) -- (12.5,0);
\draw
(10,0) [short, o-] to (11,0)
to [-o,short] (12.5,0)
;
\draw
(12.5,0) [short, o-] to (13.5,0)
to [-o,short] (13.5,0)
;
\draw
(10,0) node[above = 4mm, right = 1mm,align=center]{$i$ $\longrightarrow$ } node[below = 10mm, right = 6mm,align=center]{$i>0\ $, $v=0$} to [open, v =$v$,red] (13.5,0)
;
\end{circuitikz}
\caption{Modelo Ideal}
\end{figure}
\end{document}
答案2
在这里,我专注于添加背景矩形,而不是改进代码。我将许多事情保持得非常明确,以便更容易理解正在发生的事情。您的代码可以简化很多,而我的添加可以以牺牲可理解性为代价提高效率。
您可以命名一些坐标并将它们适合背景层上的矩形节点。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[american]{circuitikz}
\usetikzlibrary{arrows,fit,backgrounds}
\begin{document}
\begin{figure}[h]
\begin{circuitikz}
%Diodo
\draw
[short, o-] to (0.3,0)
;
\ctikzset{bipoles/diode/height=0.4, bipoles/diode/width=0.4,}
\draw
(0.3,0) node[below right = 4.15mm,align=center]{+} to[diode, a = $v_\gamma$, i = $i$]
(3,0) node[below left = 4.15mm,align=center]{-}
;
\draw
(3,0) [short,-o] to (3.2,0)
;
%Circuito abierto
\draw
(5,0) [short, o-] to (6,0)coordinate(L1) to [-o,open] (8,0)
;
\draw
(7.5,0) coordinate(R1)[short, o-] to (8.5,0)
to [-o,open] (10.5,0)
;
\draw
(5,0) node[above = 4mm, right = 1mm,align=center]{$\textcolor{red}{i}$
$\color{red}\longrightarrow$ } node[below = 10mm, right =
6mm,align=center]{$v<0\ $, $i=0$} to [open, v =$v$ ] (8.5,0)
;
\begin{scope}[on background layer]
\node[fit=(L1)(R1),fill=blue!10,inner xsep=1.5mm,inner ysep=2mm]{};
\end{scope}
%Corto circuito
\draw
(10,0) [short, o-] to (11,0) coordinate(L2)
to [-o,short] (13,0)
;
\draw
(12.5,0) coordinate(R2) [short, o-] to (13.5,0)
to [-o,short] (13.5,0)
;
\draw
(10,0) node[above = 4mm, right = 1mm,align=center]{$i$ $\longrightarrow$ } node[below = 10mm, right = 6mm,align=center]{$i>0\ $, $v=0$} to [open, v =$v$,red] (13.5,0)
;
\begin{scope}[on background layer]
\node[fit=(L2)(R2),fill=blue!10,inner xsep=1.5mm,inner ysep=2mm]{};
\end{scope}
\end{circuitikz}
\caption{Modelo Ideal.}
\end{figure}
\end{document}