2

Is it possible to produce a variable battery1 sign (battery with one up slanted arrow) in circuitikz? There are options for vR and vL (variable resistor) but not for the battery1. I need it to represent a variable power supply. MWE is appended below

\documentclass{article}
\usepackage{tikz,circuitikz}
\begin{document}
\begin{circuitikz}
 \draw   (0,-2) to[battery1] (2,-2) node [right] {Powersupply};
\end{circuitikz}
\end{document}

Generated from MWE What I want What I want

I can manually put an up arrow and position it to the middle of battery1 sign but any shortcut like vR or vL would help.

3

Just define your own component. I copy&pasted the battery1 definition and added the arrow.

\documentclass{article}
\usepackage{tikz,circuitikz}

\makeatletter

\def\pgf@circ@battery2@path#1{\pgf@circ@bipole@path{battery2}{#1}}
\compattikzset{battery2/.style = {\circuitikzbasekey, /tikz/to path=\pgf@circ@battery2@path, \circuitikzbasekey/bipole/is voltage=true, v=#1}}

\ctikzset{bipoles/battery2/height/.initial=.6}
\ctikzset{bipoles/battery2/width/.initial=.3}

\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/battery2/height}}{battery2}{\ctikzvalof{bipoles/battery2/height}}{\ctikzvalof{bipoles/battery2/width}}{
        \pgfpathmoveto{\pgfpoint{.33\pgf@circ@res@right}{0}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0}}
        \pgfpathmoveto{\pgfpoint{.33\pgf@circ@res@left}{0}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{0}}
        \pgfusepath{draw}

        \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{.33\pgf@circ@res@left}{.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.33\pgf@circ@res@left}{.5\pgf@circ@res@down}}

        \pgfpathmoveto{\pgfpoint{.33\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.33\pgf@circ@res@right}{\pgf@circ@res@down}}

        \pgfsetarrowsend{latex'}
        \pgfpathmoveto{\pgfpoint{1.5\pgf@circ@res@left}{0.9\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{1.5\pgf@circ@res@right}{0.9\pgf@circ@res@up}}

        \pgfusepath{draw}
}

\makeatother
\begin{document}
\begin{circuitikz}
 \draw   (0,-2) to[battery2] (2,-2) node [right] {Powersupply};
\end{circuitikz}
\end{document}

Output:

battery2

7
  • 1
    Thanks @Benjamin for a quick reply. This macro is giving me an error 'Undefined control sequence. l.7 \compattikzset {battery2/.style...... ' What shall I do about it? Sorry if it is a trivial question. I am not an expert in tikz and writing a macro. Jan 22 '16 at 11:17
  • Did you accidentally missed adding the \usepackage{...} line?
    – Benjamin
    Jan 22 '16 at 11:29
  • No!. I copied your whole code and pasted it. I ran this MWE independently and still... same error. Wondering if there is anything wrong with my circuitikz.sty file. Jan 23 '16 at 8:45
  • Which version of circuitikz do you have installed? Add a \listfiles at the beginning of the tex file (even before \documentclass{...}) to get a list of all the packages used with the corresponding version numbers in the log file.
    – Benjamin
    Jan 23 '16 at 10:47
  • it says circuitikz.sty 2012/12/29 The CircuiTikz circuit drawing package version 0.3.0 Jan 24 '16 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.