4

I want straight voltage arrows in circuitikz, but all are bowed. Someone has a new solution? The bowed arrows are totally ugly.

\documentclass[a4paper,10pt]{scrartcl}
\usepackage{tikz}
\usepackage[european]{circuitikz}
\begin{document}
\begin{circuitikz}[scale=2,transform shape] \draw
 (0,0) to [battery1] (0,2)
 (0,0) --(4,0)
 (0,2) to [R, l=$\mathrm{R_{vor}}$, v=U] (2,2)
 (2,2) -- (4,2)
 (2,2) to [thRp, l=$\mathrm{R_{PT}}$, v=U] (2,0)
 (4,2) to [voltmeter] (4,0)
;\end{circuitikz}
\end{document}
4
  • 2
    They are the standard. Use american if you are not happy with it.
    – percusse
    Apr 23, 2013 at 11:29
  • 1
    But I want normal straight arrows, because this is the German standard.
    – Latex_NOOB
    Apr 23, 2013 at 16:04
  • Could you upload a picture of the voltage you'd like to have? Apr 24, 2013 at 9:52
  • It should look like this, the arrows are straight, not like mine, which are bowed ugly: !example!
    – Latex_NOOB
    Apr 24, 2013 at 10:14

1 Answer 1

3

According to this comment, the following may be a possible solution (beware: it has just been tested with the initial example, so it may need a bit more test-work).

I introduced a new option german (as per this comment) which is in charge to draw straight arrows: activate it with \ctikzset{voltage=german}.

The code:

\documentclass[a4paper,10pt]{scrartcl}
\usepackage[european]{circuitikz}


\makeatletter

\newif\ifpgf@circuit@germanvoltage
\ctikzset{voltage/german/.code = {\pgf@circuit@germanvoltagetrue } }

%% Output routine for generic bipoles

\def\pgf@circ@drawvoltagegeneric{
    \pgfextra{
        \ifnum \ctikzvalof{mirror value}=-1
                        \ifpgf@circuit@bipole@voltage@below\pgf@circuit@bipole@voltage@belowfalse\else\pgf@circuit@bipole@voltage@belowtrue\fi
        \fi

        \ifpgf@circuit@bipole@voltage@below
            \def\pgf@circ@voltage@angle{90}
        \else
            \def\pgf@circ@voltage@angle{-90} 
        \fi 

        \edef\pgf@temp{/tikz/circuitikz/bipoles/\pgfkeysvalueof{/tikz/circuitikz/bipole/kind}/voltage/distance from node}
        \pgfkeysifdefined{\pgf@temp}
            { \edef\distacefromnode{\ctikzvalof{bipoles/\pgfkeysvalueof{/tikz/circuitikz/bipole/kind}/voltage/distance from node}} }
            { \edef\distacefromnode{\ctikzvalof{voltage/distance from node}} }
        \edef\pgf@temp{/tikz/circuitikz/bipoles/\pgfkeysvalueof{/tikz/circuitikz/bipole/kind}/voltage/bump b}
        \pgfkeysifdefined{\pgf@temp}
            { \edef\bumpb{\ctikzvalof{bipoles/\pgfkeysvalueof{/tikz/circuitikz/bipole/kind}/voltage/bump b}} }
            { \edef\bumpb{\ctikzvalof{voltage/bump b}} }
    }

    coordinate (pgfcirc@mid) at ($(\tikztostart) ! \distacefromnode ! (\ctikzvalof{bipole/name}.left)$)
    coordinate (pgfcirc@Vfrom) at ($(pgfcirc@mid) ! -\ctikzvalof{voltage/distance from line}\pgf@circ@Rlen ! \pgf@circ@voltage@angle:(\ctikzvalof{bipole/name}.left)$) 

    coordinate (pgfcirc@mid) at ($(\tikztotarget) ! \distacefromnode ! (\ctikzvalof{bipole/name}.right)$)
    coordinate (pgfcirc@Vto) at ($(pgfcirc@mid) ! \ctikzvalof{voltage/distance from line}\pgf@circ@Rlen ! \pgf@circ@voltage@angle : (\ctikzvalof{bipole/name}.right)$)

    \ifpgf@circuit@bipole@voltage@below
        coordinate (pgfcirc@Vcont1) at ($(\ctikzvalof{bipole/name}.center) ! \bumpb ! (\ctikzvalof{bipole/name}.-110)$)
        coordinate (pgfcirc@Vcont2) at ($(\ctikzvalof{bipole/name}.center) ! \bumpb ! (\ctikzvalof{bipole/name}.-70)$)
    \else
        coordinate (pgfcirc@Vcont1) at ($(\ctikzvalof{bipole/name}.center) ! \bumpb ! (\ctikzvalof{bipole/name}.110)$)
        coordinate (pgfcirc@Vcont2) at ($(\ctikzvalof{bipole/name}.center) ! \bumpb ! (\ctikzvalof{bipole/name}.70)$)
    \fi

    \ifpgf@circuit@germanvoltage
      \ifpgf@circuit@bipole@voltage@below
        coordinate (pgfcirc@Vcont1) at ($(\ctikzvalof{bipole/name}.center) ! \ctikzvalof{voltage/bump a} ! (\ctikzvalof{bipole/name}.-120)$)
        coordinate (pgfcirc@Vcont2) at ($(\ctikzvalof{bipole/name}.center) ! \ctikzvalof{voltage/bump a} ! (\ctikzvalof{bipole/name}.-60)$)
    \else
        coordinate (pgfcirc@Vcont1) at ($ (\ctikzvalof{bipole/name}.center) ! \ctikzvalof{voltage/bump a} ! (\ctikzvalof{bipole/name}.120)$)
        coordinate (pgfcirc@Vcont2) at ($ (\ctikzvalof{bipole/name}.center) ! \ctikzvalof{voltage/bump a} ! (\ctikzvalof{bipole/name}.60)$)
      \fi
    \fi

    \ifpgf@circuit@europeanvoltage
        \ifpgf@circuit@germanvoltage
          \ifpgf@circuit@bipole@voltage@backward
            (pgfcirc@Vcont2)  -- node[currarrow, sloped,  allow upside down, pos=1] {} (pgfcirc@Vcont1)
          \else
            (pgfcirc@Vcont1)  -- node[currarrow, sloped,  allow upside down, pos=1] {} (pgfcirc@Vcont2)
          \fi
        \else
          \ifpgf@circuit@bipole@voltage@backward
            (pgfcirc@Vto) .. controls (pgfcirc@Vcont2)  and (pgfcirc@Vcont1) .. 
                node[currarrow, sloped,  allow upside down, pos=1] {} 
            (pgfcirc@Vfrom) 
          \else
            (pgfcirc@Vfrom) .. controls (pgfcirc@Vcont1)  and (pgfcirc@Vcont2) ..
                node[currarrow, sloped,  allow upside down, pos=1] {}
            (pgfcirc@Vto)   
          \fi  
        \fi      
    \else
        \ifpgf@circuit@bipole@voltage@backward
            (pgfcirc@Vfrom) node[inner sep=0, anchor=\pgf@circ@bipole@voltage@label@anchor]{\scriptsize$+$}   
            (pgfcirc@Vto) node[inner sep=0, anchor=\pgf@circ@bipole@voltage@label@anchor]{$-$}
        \else
            (pgfcirc@Vfrom) node[inner sep=0, anchor=\pgf@circ@bipole@voltage@label@anchor]{\scriptsize$-$}   
            (pgfcirc@Vto) node[inner sep=0, anchor=\pgf@circ@bipole@voltage@label@anchor]{$+$}
        \fi 
    \fi
}
\makeatother


\begin{document}
\begin{circuitikz}[scale=2,transform shape] 
\ctikzset{voltage=german}
\draw
 (0,0) to [battery1] (0,2)
 (0,0) --(4,0)
 (0,2) to [R, l=$\mathrm{R_{vor}}$, v=U] (2,2)
 (2,2) -- (4,2)
 (2,2) to [thRp, l=$\mathrm{R_{PT}}$, v=U] (2,0)
 (4,2) to [voltmeter] (4,0)
;
\end{circuitikz}
\end{document}

The result:

enter image description here

2
  • @Latex_NOOB: I hope it will be robust with some more tests. If you have problems, don't mind to signal here the issues. :) Apr 26, 2013 at 8:40
  • Thanks a lot. Maybe I will ask you more questions. I think you are the man I need :-)
    – Latex_NOOB
    Apr 26, 2013 at 14:34

You must log in to answer this question.

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