6

I am trying to define the arrow position of a variable capacitor component, but frankly have no clue how to do so.

As far as I know, the arrow always goes from the bottom left anchor to the top right anchor - depending on the drawing direction. I would like to flip the capacitor component at the component y-axis, so that the arrow starts at the bottom right anchor pointing to the top left anchor. yscale didn't help me out, because it flipped the component at the y-axis of the overall circuit figure. EDIT: Without changing the direction of the arrow.

Is there any solution for my question?

Thanks!

EDIT:

\documentclass{article}
\usepackage{tikz}
\usepackage{circuitikz}
\begin{document}
\begin{figure}[h!]
  \begin{center} % Center figure
    \begin{circuitikz} % Begin add-on environment
      \draw (0,0)
      to[V,v=$U(t)$] (0,2);
      \draw (2,2)
      to[vC=$C_1$, o-] (0,2);
      \draw (2,2)
      to[open] (2,0)
      to[short, o-] (0,0);
    \end{circuitikz}
  \end{center}
\end{figure}
\end{document}

enter image description here

4
  • 1
    Welcome to TeX.SE! Can you show us what you have so far, so we can reproduce the problem? It'll be easier that way.
    – Troy
    Apr 6, 2017 at 9:16
  • Hi, sure! I posted the relevant part.
    – VarCapflip
    Apr 6, 2017 at 9:30
  • 1
    Sorry I wasn't clear before, but please post a compilable code, starting from \documentclass and ending with \end{document}, including relevant packages only. See meta.tex.stackexchange.com/questions/228/…
    – Troy
    Apr 6, 2017 at 9:33
  • Sorry, I updated the code.
    – VarCapflip
    Apr 6, 2017 at 10:26

2 Answers 2

3

If you're always going to want the given shape with arrows from left to right, you could simply redefine the shape associated with the variable capacitor using

\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/vcapacitor/height}}{vcapacitor}{\ctikzvalof{bipoles/vcapacitor/height}}{\ctikzvalof{bipoles/vcapacitor/width}}{
        %\pgf@circ@res@step = \ctikzvalof{bipoles/vcapacitor/width}\pgf@circ@Rlen
        \pgf@circ@res@step = \ctikzvalof{bipoles/vcapacitor/capacitor width} \pgf@circ@res@right

        \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@step}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{-\pgf@circ@res@step}{\pgf@circ@res@down}}

        \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{\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfusepath{draw}
        \endpgfscope

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{-\pgf@circ@res@step}{0pt}}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{0pt}}
        \pgfsetlinewidth{\pgfstartlinewidth}
        \pgfusepath{draw}
}

which is simply the definition from the circuitikz v0.8.1 with the lines

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

used instead of

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

to say draw from bottom left to top right instead of bottom right to top left.

Or you could define a new key Cv as (I've just followed the chain of commands that seem to be called by vC here and copied them to make a Cv variant which ends up calling the same definition with the same left/right swap as above) to use both Cv and vC

\compattikzset{Cv/.style = {\comnpatname capacitor variable = #1}}
\compattikzset{capacitor variable/.style = {\circuitikzbasekey, /tikz/to path=\pgf@circ@capacitorv@path, l=#1}}
\def\pgf@circ@capacitorv@path#1{\pgf@circ@bipole@path{capacitorv}{#1}}
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/vcapacitor/height}}{capacitorv}{\ctikzvalof{bipoles/vcapacitor/height}}{\ctikzvalof{bipoles/vcapacitor/width}}{
        %\pgf@circ@res@step = \ctikzvalof{bipoles/vcapacitor/width}\pgf@circ@Rlen
        \pgf@circ@res@step = \ctikzvalof{bipoles/vcapacitor/capacitor width} \pgf@circ@res@right

        \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@step}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{-\pgf@circ@res@step}{\pgf@circ@res@down}}

        \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{\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfusepath{draw}
        \endpgfscope

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{-\pgf@circ@res@step}{0pt}}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{0pt}}
        \pgfsetlinewidth{\pgfstartlinewidth}
        \pgfusepath{draw}
}

Collecting this together in a single example

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

\makeatletter%Create new circuitikz key Cv for variable capacitor with arrow in other direction
\compattikzset{Cv/.style = {\comnpatname capacitor variable = #1}}
\compattikzset{capacitor variable/.style = {\circuitikzbasekey, /tikz/to path=\pgf@circ@capacitorv@path, l=#1}}
\def\pgf@circ@capacitorv@path#1{\pgf@circ@bipole@path{capacitorv}{#1}}
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/vcapacitor/height}}{capacitorv}{\ctikzvalof{bipoles/vcapacitor/height}}{\ctikzvalof{bipoles/vcapacitor/width}}{
        %\pgf@circ@res@step = \ctikzvalof{bipoles/vcapacitor/width}\pgf@circ@Rlen
        \pgf@circ@res@step = \ctikzvalof{bipoles/vcapacitor/capacitor width} \pgf@circ@res@right

        \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@step}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{-\pgf@circ@res@step}{\pgf@circ@res@down}}

        \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{\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfusepath{draw}
        \endpgfscope

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{-\pgf@circ@res@step}{0pt}}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{0pt}}
        \pgfsetlinewidth{\pgfstartlinewidth}
        \pgfusepath{draw}
}
\makeatother

\begin{document}
\begin{center}
\texttt{vC} with default definition

\begin{circuitikz}
    \draw (2,0) to[vC=$C_1$, o-] (0,0);
\end{circuitikz}

New \texttt{Cv} key

\begin{circuitikz}
    \draw (2,0) to[Cv=$C_1$, o-] (0,0);
\end{circuitikz}

\makeatletter%Redefine arrow direction used by vC
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/vcapacitor/height}}{vcapacitor}{\ctikzvalof{bipoles/vcapacitor/height}}{\ctikzvalof{bipoles/vcapacitor/width}}{
        %\pgf@circ@res@step = \ctikzvalof{bipoles/vcapacitor/width}\pgf@circ@Rlen
        \pgf@circ@res@step = \ctikzvalof{bipoles/vcapacitor/capacitor width} \pgf@circ@res@right

        \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@step}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{-\pgf@circ@res@step}{\pgf@circ@res@down}}

        \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{\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfusepath{draw}
        \endpgfscope

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{-\pgf@circ@res@step}{0pt}}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{0pt}}
        \pgfsetlinewidth{\pgfstartlinewidth}
        \pgfusepath{draw}
}
\makeatother

\texttt{vC} with arrow direction redefined

\begin{circuitikz}
    \draw (2,0) to[vC=$C_1$, o-] (0,0);
\end{circuitikz}
\end{center}
\end{document}

enter image description here

1
  • @VarCapflip please do accept sistlind's answer instead of mine, unfortunately for me it is much more sensible to use keys already defined by the package for the job than worry about any of these redefinitions!
    – Dai Bowen
    Apr 6, 2017 at 23:50
4

Why not reading the manual and make use of the mirror/invert options?

to[vC=$C_1$,invert, o-]

or

to[vC=$C_1$,mirror, o-]

or a combination of both should do the trick.

Example:

 \begin{circuitikz} % Begin add-on environment
  \draw (0,0) to[vC=$C_1$] ++(2,0)
    to[vC=$C_1$,invert] ++(2,0)
    to[vC=$C_1$,mirror] ++(2,0)
    to[vC=$C_1$,mirror,invert] ++(2,0);
 \end{circuitikz}

enter image description here

Best regards,

Stefan

1
  • 2
    If it's any consolation, I like this one better. Why re-invent the wheel? Apr 7, 2017 at 14:45

You must log in to answer this question.

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