0

I want to create a current source as seen in many Dutch book on electric circuits. The standard European conponent is not what I want. I want something like this:

\documentclass[a4paper]{article}

\usepackage{tikz}
\usepackage[european]{circuitikz}

\begin{document}

\begin{figure}[!ht]
\begin{circuitikz}
\draw (0,0) to[I, l=$I_B$] (0,2);
\draw [->] (-0.5,0.65) -- (-0.5,1.35);
\end{circuitikz}
\end{figure}

\end{document}

In the code, I draw the arrow (as part of the current source symbol) myself. But I would like to have a complete circuitikz symbol for it. Also, I want the arrow and the symbol $I_B$ next to the arrow a bit more to the left. I tried to look into the circuitikz code for current sources but I think my knowlegde is too poor.

1 Answer 1

4

I took the current source from circuitikz and added the arrow from this answer (more or less).

The label location is determined by the borders of the components and [inner sep], so the easiest way to move the label is to just add space inside the label.

\documentclass[a4paper]{article}

\usepackage{tikz}
\usepackage[european]{circuitikz}

\makeatletter
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/isource/height}}{isource}{\ctikzvalof{bipoles/isource/height}}{\ctikzvalof{bipoles/isource/width}}{
    \pgfpointorigin
    \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@down}}
  \pgfusepath{draw}
  \pgfscope
    \pgfsetarrowsend{latex'}
    \pgfpathmoveto{\pgfpoint{0.8\pgf@circ@res@left}{1.2\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.8\pgf@circ@res@right}{1.2\pgf@circ@res@up}}
    \pgfusepath{draw}   %draw arrow
  \endpgfscope
}
\makeatother

\begin{document}

\begin{figure}[!ht]
\begin{circuitikz}
%\tikzset{every node/.style={inner sep=1em}}
\draw (0,0) to[I, l={$I_B$~},name=A] (0,2);
%\draw[red] (A.sw) rectangle (A.ne);
\end{circuitikz}
\end{figure}

\end{document}

demo


For more control, replace the label with a node:

\begin{document}

\begin{circuitikz}
\draw (0,0) to[I, name=A] (0,2);
\node[left=2pt] at (A.n) {$I_A$};

\draw (0,0) to[I, name=B] (2,0);
\node[above=2pt] at (B.n) {$I_B$};
\end{circuitikz}

\end{document}
3
  • thank you so much. This is exactly what I was looking for. Apr 4, 2018 at 7:27
  • The option inner sep=1em works when the current source is placed vertically, but not when it is placed horizontally. Is there another option? Apr 4, 2018 at 8:47
  • @JesseopdenBrouw If you like John's answer and it was helpful, please consider upvoting (by clicking on the arrows next to the score) and/or marking it as the accepted answer (by clicking on the checkmark ✓). It is the TeX.SE way of saying thank you.
    – Troy
    May 11, 2018 at 19:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .