# Modify existing CircuiTikZ symbol

I want to use a varcap diode in a circuit. However, since I have rather small symbols, there is a problem with the varcap lines being too close together which gives an ugly result:

I was unable to find a config option for the distance of the two lines, so I copied the code for the varcap diode to the preamble of my document.

\makeatletter
\pgfcircdeclarebipole{
\anchor{strokepathstart}{
\northeast
\pgf@y=0cm
\pgf@x=.8\pgf@x
}
\anchor{strokepathend}{
\northeast
\pgf@y=0cm
}
}{\ctikzvalof{bipoles/varcap/height}}{emptyvarcap}{\ctikzvalof{bipoles/varcap/height}}{\ctikzvalof{bipoles/varcap/width}}{

\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
\pgfscope
\pgftransformxshift{\pgf@circ@res@left}
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-.8\pgf@circ@res@left}{0pt}}
\pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
\pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-.8\pgf@circ@res@left}{0pt}}
\pgfusepath{draw}

\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-.8\pgf@circ@res@left}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-.8\pgf@circ@res@left}{\pgf@circ@res@up}}
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-1.3\pgf@circ@res@left}{\pgf@circ@res@down}}  %%%% MODIFIED HERE
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-1.3\pgf@circ@res@left}{\pgf@circ@res@up}}    %%%% AND HERE
\pgfusepath{draw}

\endpgfscope
}
\makeatother


The two lines marked with %%%% I have modified and inserted the factor 1.3 which then gives this result:

Which looks a lot nicer in my opinion. However, how can I change the anchor where the connecting line starts? as one can see, there is a little 'tail' of the next line.

• A much easier solution is to reduce the line thickness (default=2) using \ctikzset{bipoles/thickness=1} (for example). – John Kormylo Jul 8 '16 at 16:27
• Or simply use [very thin] (tikz command) to reduce both the circuit connection and component thicknesses. – John Kormylo Jul 8 '16 at 16:41

To answer your question: The correct anchor is strokpathstart/strokpathend in this case, because you are using the stroked diode symbols.

Nevertheless, this should not happen and i will adjust the symbol at circuitikz following the above answer.

Btw, if you want to use the stroked symbols, you should use this code(changed strokepathstart anchor)

\pgfcircdeclarebipole{
\anchor{strokepathstart}{
\northeast
\pgf@y=0cm
}
\anchor{strokepathend}{
\northeast
\pgf@y=0cm
}
}{\ctikzvalof{bipoles/varcap/height}}{emptyvarcap}{\ctikzvalof{bipoles/varcap/height}}{\ctikzvalof{bipoles/varcap/width}}{
\pgf@circ@res@temp=\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth
\pgfsetlinewidth{\pgf@circ@res@temp}
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-2\pgf@circ@res@temp}{0pt}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-2\pgf@circ@res@temp}{0pt}}
\pgfusepath{draw}
%
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-2\pgf@circ@res@temp}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-2\pgf@circ@res@temp}{\pgf@circ@res@up}}
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
\pgfusepath{draw}
}


Best regards, Stefan

• Great! this was exactly what I searched for. (I still sometimes have trouble to read PGF code.) – T. Pluess Jul 10 '16 at 9:36

The connection points for a bipole are always at \pgf@circ@res@left and \pgf@circ@res@right, so you will need to fit everything inside those limits.

It later occurred to me that by making the gap the same size as the line thickness, the two lines would never overlap.

\documentclass[border=2mm]{standalone}
\usepackage{circuitikz}

\makeatletter
\pgfcircdeclarebipole{
\anchor{strokepathstart}{
\northeast
\pgf@y=0cm
\pgf@x=.8\pgf@x
}
\anchor{strokepathend}{
\northeast
\pgf@y=0cm
}
}{\ctikzvalof{bipoles/varcap/height}}{emptyvarcap}{\ctikzvalof{bipoles/varcap/height}}{\ctikzvalof{bipoles/varcap/width}}{

\pgf@circ@res@temp=\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth
\pgfsetlinewidth{\pgf@circ@res@temp}
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-2\pgf@circ@res@temp}{0pt}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-2\pgf@circ@res@temp}{0pt}}
\pgfusepath{draw}
%
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-2\pgf@circ@res@temp}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-2\pgf@circ@res@temp}{\pgf@circ@res@up}}
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
\pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
\pgfusepath{draw}
}
\makeatother

\begin{document}
\begin{circuitikz}
\draw (0,0) to[VCo] (2,0) to[VCo] (2,2) to[VCo] (0,0);
\begin{scope}[xshift=3cm,scale=0.5,circuitikz/bipoles/length=.5cm]
\draw (0,0) to[VCo] (2,0) to[VCo] (2,2) to[VCo] (0,0);
\end{scope}
\begin{scope}[xshift=4.5cm,very thin,scale=0.5,circuitikz/bipoles/length=.5cm]
\draw (0,0) to[VCo] (2,0) to[VCo] (2,2) to[VCo] (0,0);
\end{scope}
\end{circuitikz}
\end{document}


• (+1) for nice solution. please, can you show in answer, some other orientation of diode too? for example \draw (0,0) to[VCo] (0,2); or even \draw (0,0) to[VCo] (2,2);. – Zarko Jul 8 '16 at 17:29