4

First of all, this is a crosspost from the german website golatex.de. I am hoping another set of eyes on it might help find a solution.

If I draw two voltage sources with circuitikz and the second voltage source is dotted (or dashed), the arrowhead is not adjusted. It remains normal and the dotted (or dashed) lines are just "drawn over".

My minimal working example illustrates the problem:

\documentclass{article}
\usepackage{circuitikz}
\usepackage{showframe}

\begin{document}

\begin{circuitikz}
\draw
   (8,2) to [american voltage source, v_<=$\omega_RL_qi_q$] (8,4);

\draw[lightgray,dotted] %or dashed
  (8,0) to [american voltage source, v_<=$\omega_R\psi$,color=lightgray] (8,2);
\end{circuitikz}

\end{document}

In the picture it can be seen that everything of the second voltage source can be colored but the arrowhead remains normal and the dotted (or dashed) lines are just "drawn over" as mentioned above.

enter image description here

What do I have to do to get the arrowhead also dotted (or dashed)?

Thanks in advance.

4

Yes, I know. The problem is that arrows in circuitikz are not real arrows, but they are built manually with the currarrow shape. I am not sure why, but probably because circuitikz predates arrows.meta and... whatever. I plan to change it, but it is a big change, and difficult to do in a backward compatible way.

If you change, in the definition of currarrow (file pgfcircshapes.tex, at line 308 in current git version) the command

\pgfusepath{draw,fill}

into

\pgfusepath{fill}

the result is a bit better (see below), but I am not sure if it can have other nasty effects around. If you want, you can open an issue on github so that I can track it...

enter image description here

Otherwise, you can remove the fill, but now you have a quite bad effect on the rest of the circuit:

enter image description here

(yes, this is the dotted version of the arrow outline. Quite bad, but the points are random, and not lined up with the corners. I really do not know how to make a dotted or dashed outline of an arrow work. densely dotted gives:

enter image description here

but still...)

Notice that the standard arrows do not change with linestyle, and although you can make them unfilled, there is no provision (chapter 16.3 of the 3.0.1 TikZ manual) to make them something not solid:

\draw[-{Triangle[fill=none, ]}, densely dotted] (9,0) -- (10,0);

enter image description here

Stop gap solution...

You can redefine the shape and add a bit of configurability like that:

\documentclass[border=10pt]{standalone}
\usepackage[RPvoltages]{circuitikzgit}

\makeatletter

%% Current arrow
\def\arrowfilldraw{\pgfusepath{draw,fill}}
\def\arrowfillonly{\pgfusepath{fill}}
\let\arrowuse=\arrowfilldraw
\tikzset{ctikzarrdraw/.is choice}
\tikzset{ctikzarrdraw/true/.code={\let\arrowuse=\arrowfilldraw}}
\tikzset{ctikzarrdraw/false/.code={\let\arrowuse=\arrowfillonly}}


\pgfdeclareshape{currarrow}{
    \savedanchor{\northeast}{%
        \pgf@circ@res@step = \pgf@circ@Rlen
        \divide \pgf@circ@res@step by \pgfkeysvalueof{/tikz/circuitikz/current arrow scale}
        \pgf@x=.5\pgf@circ@res@step
        \pgf@y=\pgf@x%
    }
    \anchor{north}{\northeast\pgf@x=0cm\relax}
    \anchor{east}{\northeast\pgf@y=0cm\relax}
    \anchor{south}{\northeast\pgf@y=-\pgf@y \pgf@x=0cm\relax}
    \anchor{west}{\northeast\pgf@y=0cm\pgf@x=-\pgf@x}
    \anchor{north east}{\northeast}
    \anchor{north west}{\northeast\pgf@x=-\pgf@x}
    \anchor{south east}{\northeast\pgf@y=-\pgf@y}
    \anchor{south west}{\northeast\pgf@y=-\pgf@y\pgf@x=-\pgf@x}
    \anchor{center}{
        \pgfpointorigin
    }
    \anchor{tip}{
        \pgfpointorigin
        \pgf@circ@res@step = \pgf@circ@Rlen
        \divide \pgf@circ@res@step by \pgfkeysvalueof{/tikz/circuitikz/current arrow scale}
        \pgf@x  =\pgf@circ@res@step
    }
    \behindforegroundpath{
        \pgfscope
            \pgf@circ@res@step = \pgf@circ@Rlen
            \divide \pgf@circ@res@step by \pgfkeysvalueof{/tikz/circuitikz/current arrow scale}

            \pgfpathmoveto{\pgfpoint{-.7\pgf@circ@res@step}{0pt}}
            \pgfpathlineto{\pgfpoint{-.7\pgf@circ@res@step}{-.8\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpoint{1\pgf@circ@res@step}{0pt}}
            \pgfpathlineto{\pgfpoint{-.7\pgf@circ@res@step}{.8\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpoint{-.7\pgf@circ@res@step}{0pt}}
            \pgfsetcolor{\pgfkeysvalueof{/tikz/circuitikz/color}}
            % this is the change needed: substitute the \pgfpathuse{...} with:
            \arrowuse
        \endpgfscope
    }
}

\makeatother


\begin{document}

\begin{circuitikz}
    \draw
    (6,2) to [american voltage source, v_=$\omega_RL_qi_q$] ++(0,-2);
    \draw[color=lightgray, densely dotted] %or dashed
    (8,2) to [american voltage source, v_=$\omega_R\psi$,color=lightgray] ++(0,-2);
    \draw[color=lightgray, densely dotted] %or dashed
    (10,2) to [american voltage source, v_=$\omega_R\psi$,color=lightgray, ctikzarrdraw=false] ++(0,-2);
    \draw[] (12,2) to [american current source, ] ++(0,-2);
\end{circuitikz}

\end{document}

And you'll have

enter image description here

Zooming:

enter image description here

and if you add, for example

\def\arrowstrange{\pgfsetfillcolor{white}\pgfusepath{fill, draw}}
\tikzset{ctikzarrdraw/strange/.code={\let\arrowuse=\arrowstrange}}

you can also say

\draw[color=lightgray, densely dotted] %or dashed
(10,2) to [american voltage source, v_=$\omega_R\psi$,color=lightgray,  ctikzarrdraw=strange] ++(0,-2);

which will give:

enter image description here

  • Ok, I checked. I can't change the fill,draw to fill, because the tip anchor will be misplaced by the line width, which is variable, which is a problem. Maybe using \deferredanchor... – Rmano Apr 28 '19 at 8:46
  • ...and no, doesn't work. – Rmano Apr 28 '19 at 8:50
  • 1
    Your last answer with the unfilled arrowhead it's what I've been looking for. Unfortunately I have to use circuitikzgit and add some additional code before the preamble because currently I don't know, if the rest of my code is still functionally. – Roland Deschain Apr 28 '19 at 13:00
  • You can't use the released circuitikz because circuitikz/current arrow scale is a new thing. But you can extract the definition of currarrow from your installation (file pgfcircshape.tex) and modify that... – Rmano Apr 29 '19 at 8:20
  • @Rmano May I know how to remove the arrow of an american voltage source then bridge the gap it left between the text and the source drawing? – Diaa Nov 2 '19 at 10:55
4

If you would rather not get into the circuitikz source, you can manually add a label.

\documentclass{standalone}
\usepackage{circuitikz}
\usetikzlibrary{arrows.meta}
\newlength{\offset}
\makeatletter
  \let\Rlen=\pgf@circ@Rlen
\makeatother

\begin{document}
\begin{circuitikz}
\draw
   (8,2) to [american voltage source, v_<=$\omega_RL_qi_q$] (8,4);

\draw[lightgray,dotted] %or dashed
  (8,0) to [american voltage source,color=lightgray,name=V2] (8,2);
  \offset=\ctikzvalof{voltage/distance from line}\Rlen
  \draw[-Triangle,dotted,color=lightgray] ($(V2.se)+(\offset,0)$) --
    ($(V2.sw)+(\offset,0)$)
    node[midway,right=\offset,inner sep=2pt,color=lightgray] {$\omega_R\psi$};
\end{circuitikz}

\end{document}
  • Yes, this is probably cleaner, +1; but the OP seems to want a dotted arrow tip, which is quite a difficult thing to make looking nice... – Rmano Apr 29 '19 at 8:16

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.