Circuitikz:标签空间控制

Circuitikz:标签空间控制

我对零件参考和组件(电阻器 R2、R3)之间的垂直间距有疑问。我希望文字更靠近电阻器。第二个问题是电压箭头的文字位置。对于电阻器 R1 和 R4,使用命令\raisebox{}\hspace但对 R1 和 R2 没有任何影响。我使用 xelatex 和更新的 Miktex。

在此处输入图片描述

梅威瑟:

\documentclass{article}
  \usepackage{fontspec,xltxtra,xunicode,unicode-math} 
  \usepackage{siunitx}
  \usepackage{tikz}
    \usetikzlibrary{intersections}
    \usetikzlibrary{calc}
    \usetikzlibrary{positioning}
    \usetikzlibrary{arrows}
    \tikzstyle{every node}=[font=\small]
    \tikzstyle{every path}=[line width=0.8pt,line cap=round,line join=round]
  \usepackage[american, europeanresistor, cuteinductors, smartlabels]{circuitikz}
    \ctikzset{bipoles/thickness=1}
    \ctikzset{bipoles/length=0.8cm}

\begin{document}
  \begin{figure}[htp]
    \centering
    \begin{circuitikz}[scale=2, every node/.style={font=\footnotesize}, european voltages]
      \node (0,0)             (B) {};
      \node [left =2cm of B]  (A) {};
      \node [right=2cm of B]  (C) {};
      \node [below=2cm of B]  (D) {};
      \node [below=2cm of A]  (E) {};
      \node [below=2cm of C]  (F) {};
      \node [above=1cm of A]  (G) {};
      \node [above=1cm of C]  (H) {};

      \ctikzset{current/distance = .5}
      \ctikzset{bipoles/resistor/voltage/distance from node/.initial = .5}
      \draw[red, line width=2pt]               (F)
        to[short, color =red, i>_= $i_x$]      (C);
      \draw (A) to[R, l=$\begin{array}{c} R_2  \\ \SI{2}{\kohm}\end{array}$,  %
            v_>= $U_1-U_2$, i>^= $i_2$, *-*]   (B) node[above] {$2$}
        to[R, l=$\begin{array}{r} R_3 \\ \SI{2}{\kohm}\end{array}$, v_>= $U_2$, i^>= $i_3$, *-*]   (C);
      \draw (B) to[R, l_=\raisebox{0cm}{$\begin{array}{r} R_4 \\ \SI{2}{\kohm}\end{array}$\hspace{-0.2cm}},    i>_= $i_4$,  -*]   (D); 
      \draw (A) to[R, l_=\raisebox{0cm}{$\begin{array}{r} R_1 \\ \SI{6}{\kohm}\end{array}$\hspace{-0.2cm}},    i>_=$i_1$]         (E) 
                to[short]                      (D) node[below, red] {$0$};
      \draw (C) to[short] (H) to[I, i^=$\SI{1}{\milli\ampere}$] (G) to[short] (A) node[left] {$1$};
      \ctikzset{voltage/distance from node=0.5}
      \draw (D.north) to [open, v^=$U_1$]      (A.north);
      \draw (F.north) to [open, v^=$U_2$]      (B.north);
      \draw[red, line width=2pt] (D) to[short, color =red, *-] (D -| C);
    \end{circuitikz}
    \caption{ }
  \end{figure}
\end{document}

答案1

除了arrays,您还可以使用\substack(并添加\displaystyle以恢复字体大小);事实上,使用\substack空的第一行还可以为某些标签获得更多间距。我还增加了0.5cm一些节点之间的距离(当然,这是可选的,但在我看来可以改善图表):

\documentclass{article}
\usepackage{fontspec,xltxtra,xunicode,unicode-math} 
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\usepackage[american, europeanresistor, cuteinductors, smartlabels]{circuitikz}

\tikzstyle{every node}=[font=\small]
\tikzstyle{every path}=[line width=0.8pt,line cap=round,line join=round]
\ctikzset{bipoles/thickness=1}
\ctikzset{bipoles/length=0.8cm}

\begin{document}
\begin{figure}[htp]
\centering
\begin{circuitikz}[scale=2, every node/.style={font=\footnotesize}, european voltages]
  \node (0,0) (B) {};
  \node [left =2.5cm of B](A) {};
  \node [right=2.5cm of B](C) {};
  \node [below=2.5cm of B](D) {};
  \node [below=2.5cm of A](E) {};
  \node [below=2.5cm of C](F) {};
  \node [above=1cm of A](G) {};
  \node [above=1cm of C](H) {};

  \ctikzset{current/distance = .5}
  \ctikzset{bipoles/resistor/voltage/distance from node/.initial = .5}
  \draw[red, line width=2pt] (F)
    to[short, color =red, i>_= $i_x$](C);
  \draw (A) 
    to[R,l=$\substack{\displaystyle\hfill R_2\\\displaystyle \SI{2}{\kohm}}$,%
      v_>= $\substack{\phantom{a}\\\displaystyle U_1-U_2}$, i>^= $i_2$, *-*] (B) node[above] {$2$}
    to[R, l=$\substack{\displaystyle\hfill R_3 \\\displaystyle \SI{2}{\kohm}}$,%
      v_>= $\substack{\phantom{a}\\\displaystyle U_2}$, i^>= $i_3$, *-*] (C);
  \draw (B) 
    to[R, l_=$\substack{\displaystyle\hfill R_4 \\ \displaystyle\SI{2}{\kohm}}$,%
      i>_= $i_4$,-*] (D); 
  \draw (A) 
    to[R, l_=$\substack{\displaystyle\hfill R_1 \\\displaystyle \SI{6}{\kohm}}$,%
      i>_=$i_1$] (E) 
    to[short](D) node[below, red] {$0$};
  \draw (C) 
    to[short] (H) 
    to[I, i^=$\SI{1}{\milli\ampere}$] (G) 
    to[short] (A) node[left] {$1$};
  \ctikzset{voltage/distance from node=0.5}
  \draw (D.north) 
    to [open, v^=$U_1$] (A.north);
  \draw (F.north) 
    to [open, v^=$U_2$](B.north);
  \draw[red, line width=2pt] (D) 
    to[short, color =red, *-] (D -| C);
\end{circuitikz}
\caption{ }
\end{figure}
\end{document}

在此处输入图片描述

相关内容