blue voltage arrow from manual label wrong rotation #448
Comments
|
This is quite complex, really. One of the problem is that the "smart" label positioning works only for labels, not for voltages --- I have prepared a simple example here (attached below). Notice that the "normal" voltages labels, called $v_n$, are always straight, even if I use the To get the anchor used by the label, you can use \documentclass[class=report, 11pt,a4paper,tikz,border=5pt]{standalone}
\usepackage[european, straightvoltages, americaninductors, betterproportions, nooldvoltagedirection]{circuitikz}
\begin{document}
\begin{tikzpicture}
\def\myvv#1#2{%
\draw [thin, blue, ->,]
(#1-Vfrom) .. controls (#1-Vcont1) and (#1-Vcont2).. (#1-Vto)
node [pos=0.5, anchor=\ctikzgetanchor{#1}{Vlab},
rotate=\ctikzgetdirection{#1}] at (#1-Vlab) {#2}; }
% Normal voltages
\begin{scope}[yshift=2cm]
\draw (-30:3) to[L, o-, l={\(L_{ab}\)}] (-30:1.5) to [V, -*, name=V1, v=$v_n$,] (-30:0);
\end{scope}
% extended voltage
\draw (-30:3) to[L, o-, l={\(L_{ab}\)}, v=$v_{ab}$] (-30:1.5) to[V, -*, name=V1, ] (-30:0);
\myvv{V1}{\(v_{12}\)}
% extended voltage, no special source treatment
\begin{scope}[yshift=-2cm]
\draw (-30:3) to[L, o-, l={\(L_{ab}\)}] (-30:1.5) to[V, -*, name=V1, v, bipole/is voltage=false] (-30:0);
\myvv{V1}{\(v_{12}\)}
\end{scope}
% normal voltage, no special source treatment
\begin{scope}[yshift=-4cm]
\draw (-30:3) to[L, o-, l={\(L_{ab}\)}] (-30:1.5) to[V, -*, name=V1, v=$v_n$, bipole/is voltage=false] (-30:0);
\end{scope}
\end{tikzpicture}%
\end{document} |
|
Anyway, in this case, you have an easy solution: you can use the label-positioning options of TikZ for placing your voltage label. Maybe you need to leave a manual knob for above / below, but what about this? \documentclass[class=report, 11pt,a4paper,tikz, border=4pt]{standalone}
\usepackage[european, straightvoltages, americaninductors, betterproportions, nooldvoltagedirection]{circuitikz}
\newcommand{\myvv}[3][below]{%
\draw [thin, blue, ->,] (#2-Vfrom) -- (#2-Vto) node [pos=0.5, #1, sloped] {#3};
}
\begin{document}
\begin{tikzpicture}
\draw (-30:3) to[L, o-, l=$L_{ab}$, v, name=L1] (-30:1.5) to[V, -*, name=V1,] (-30:0);
\myvv{V1}{$v_{12}$}
\myvv[above]{L1}{$v_{ab}$}
\end{tikzpicture}%
\end{document}PS given that the voltages are straight, you can do them with a line, no need to use a Bezier curve. I also have removed |
|
Yes, this is quite good. Still not perfect in some cases: Additinally: |
Yes; technically it is doing what you ask (voltage label
Unfortunately, they are not really arrowhead. But you can simulate them quite well with a
That should work with adding \documentclass[class=report, 11pt,a4paper,tikz, border=4pt]{standalone}
\usepackage[european, straightvoltages, americaninductors, betterproportions, nooldvoltagedirection]{circuitikz}
\newcommand{\myvv}[3][below]{%
\draw [thin, blue, -latex,] (#2-Vfrom) -- (#2-Vto) node [pos=0.5, #1, sloped] {#3};
}
\begin{document}
\begin{tikzpicture}
\draw (90:3) to[L, o-, l=$L_{ab}$, v, name=L1] (90:1.5) to[V, -*, v_, name=V1,] (-30:0);
\myvv{V1}{\rotatebox{90}{$v_{12}$}}
\myvv{L1}{\rotatebox{90}{$v_{ab}$}}
\end{tikzpicture}%
\end{document}(PS: you can do a screenshot and paste the image directly in the answer to have it inline...) |
|
Ok thanks a lot. This works for me. |
|
Thanks! I will try to tackle the main problem also --- there is something pesky in the code (this is why is marked experimental in the manual!). So I'll leave this open for now. |
|
So... I finally think this is not an error. Voltage labels are always drawn straight, and the correct way to mimic (but in blue) the normal positioning is not using \def\myvv#1#2{\draw [thin, blue, ->,]
(#1-Vfrom) .. controls (#1-Vcont1) and (#1-Vcont2).. (#1-Vto)
node [anchor=\ctikzgetanchor{#1}{Vlab}] at (#1-Vlab) {{#2}}; }
So it is not really a bug, maybe a lack of feature ;-) |
|
Maybe someone can use this: |
|
Hmmm... this can be transformed to an enhancement request to export also label direction (the label position is already there, giving that the label node is accessible). |
|
Added in PR #452 : |
|
So, one question: what is the difference between annotation and voltage label? does it make sense to use an annotation instead of the voltage? |
|
An |
|
I came around playing with this a bit. However, \ctikzgetrotation doesn't seem to work? The example below errors with |
|
Will look into it |
|
Well, the easy thing is that it's called |
|
Well, I tried
and so I thought this is supposed to work... |
|
Yes, that is a typo, look at the code. For the more fundamental problem (the erroring out) I have an idea of what's happening, but I have to check and I have no time right now... I hope to solve it asap. It seems an expansion problem in the TikZ parameter list. |
|
Ok, found the problem. There is no label defined for |
|
About your second question, there is no a "default label" for components --- and the anchors can be generated only if we have to typeset a label (this is different for You can always define a style for the components you use: \tikzset{
L+/.style={L, v=\null, i=~, f, l=~, a=~}, % use \null or ~ whatever you prefer
V+/.style={V, v=~, i=~, f, l=~, a=~},
}and then use them like (in your example): \draw (150:4) to[L+, o-, l=$L_{ab}$, name=L1,] (150:2) to[V+, -*, v_={\(v_{12}\)}, name=V1] (0:0);so that you can always override the direction or the label if you want (like For the current direction, no, there is not a pre-defined function, but you can easily (well, after a bit of TikZ manual digging): \newcommand{\darr}[1]{
\pgfmathanglebetweenpoints{\pgfpointanchor{#1-Ifrom}{center}}{\pgfpointanchor{#1-Ito}{center}}
\edef\myangletmp{\pgfmathresult}
%\typeout{\myangletmp}
\node [flowarrow, rotate=\myangletmp, color=green] at (#1-Ipos){};
}and you can use them like \draw (150:4) to[L+, o-, l=$L_{ab}$, name=L1,i>_] (150:2) to[V+, -*, v_={\(v_{12}\)}, name=V1] (0:0);
\varr{V1}{$v_{12}$}
\varr{L1}{$v_{longName}$}
\iarr{V1}{$i$}\darr{V1}
\iarr{L1}{$i$}\darr{L1} |
|
BTW, adding something as Doing that now will be quite a lot of work, because the bipoles are defined one by one and that will mean a lot of work. But if I (or some brave soul) come out to try to streamline it with a set of meta-macros, it could be done (and probably that will help also to solve #346). Lot of |
|
@judober if you want to match the arrow size (Not necessary I think, but...) you can find info here: https://tex.stackexchange.com/questions/549347/circuitikz-arrowhead |
|
I updated my code in case some one can use it. Thanks for your input. \documentclass[class=report, 11pt,a4paper,tikz, border=4pt]{standalone}
\usepackage[european, straightvoltages, americaninductors, betterproportions, nooldvoltagedirection]{circuitikz}[
]
\usepackage{xifthen}
\usetikzlibrary{math}
\tikzset{
L+/.style={L, v=~, i=~, f, l=~, a=~},
V+/.style={V, v=~, i=~, f, l=~, a=~},
}
\newcommand{\vhorz}[3][blue]{
\draw [thin, #1, -Triangle,] (#2-Vfrom) .. controls (#2-Vcont1) and (#2-Vcont2).. (#2-Vto) node [anchor=\ctikzgetanchor{#2}{Vlab}] at (#2-Vlab) {{#3}};
}
\newcommand{\vcrossauto}[3][blue]{
\tikzmath{
coordinate \dpC, \dpV;
\dpC = (#2.center);
\dpV = (#2voltage.center);
if \dpCy < \dpVy then{
{\draw [thin, #1, -Triangle,] (#2-Vfrom) .. controls (#2-Vcont1) and (#2-Vcont2).. (#2-Vto) node [pos=0.5, above, sloped] {#3};};
} else {
{\draw [thin, #1, -Triangle,] (#2-Vfrom) .. controls (#2-Vcont1) and (#2-Vcont2).. (#2-Vto) node [pos=0.5, below, sloped] {#3};};
};
}
}
\newcommand{\varr}[3][blue]{
\tikzmath{
\dprot = \ctikzgetdirection{#2label};
if \dprot == 0 then{
{\vhorz[#1]{#2}{#3}};
}else{
{\vcrossauto[#1]{#2}{#3}};
};
}
}
\newcommand{\iarr}[3][red]{ %1. optional color, 2. Referenz to element, 3. label
\pgfmathanglebetweenpoints{\pgfpointanchor{#2-Ifrom}{center}}{\pgfpointanchor{#2-Ito}{center}}
\edef\myangletmp{\pgfmathresult}
% \typeout{\myangletmp}
\node [currarrow, rotate=\myangletmp, color=#1] at (#2-Ipos){};
% Name not rotated -> label not rotated
\pgfmathparse{notequal(\ctikzgetdirection{#2label},0)}
\edef\namerottmp{\pgfmathresult}
% rotate 180 if angle is between 90 and 270
\pgfmathparse{\myangletmp + ifthenelse(and(\myangletmp>90,\myangletmp<270),180,0)}
\edef\mylabangletmp{\pgfmathresult}
% \typeout{\mylabangletmp}
% placement above or below
\tikzmath{
coordinate \dpC, \dpI;
\dpC = (#2-Ipos);
\dpI = (#2current.center);
if {\namerottmp} then {
if \dpCy < \dpIy then{ %above
{\node [above, rotate=\mylabangletmp, #1] at (#2-Ipos) {#3};};
} else { %below
{\node [below, rotate=\mylabangletmp, #1] at (#2-Ipos) {#3};};
};
} else { %not rotated -> use default position
{\node [anchor=\ctikzgetanchor{#2}{Ilab}, #1] at (#2-Ipos) {#3};};
};
}
}
\begin{document}
\begin{tikzpicture}
\draw (130:4) to[L+, o-, l=$L_{ab}$, v=v, name=L1, i=i] (130:2) to[V+, -*, v_={\(v_{12}\)}, name=V1, i>_=~] (0:0);
\varr[purple]{V1}{$v_{12}$}
\varr{L1}{$v_{longName}$}
\iarr{V1}{$i$}
\iarr[green]{L1}{$i_{longName}$}
\end{tikzpicture}%
\end{document} |
|
Actually, I just noticed that this does not work as I intended: \tikzset{
L+/.style={L, v, i, f, l, a},
V+/.style={V, v, i, f, l, a},
}that fixes this. But I depend on |
|
Not sure if I understand (could you make a small example?) Can't you use |
|
Anyway, for now no, there is no way to have the void label for |
|
Let's say I want only a current label for the first source and a voltage for the second. Using the definitions I get \begin{document}
\begin{tikzpicture}
\draw (40:4) to[L+, o-, l=$L_{ab}$, name=L1] (40:2) to[V+, -*, name=V1] (0:0);
\draw (130:4) to[L+, o-, l=$L_{ab}$, name=L2] (130:2) to[V+, -*, name=V2] (0:0);
\draw (220:4) to[L+, o-, l=$L_{ab}$, name=L3] (220:2) to[V+, -*, name=V3] (0:0);
\iarr{V1}{$i$} % current for 1. voltage source
\varr{V2}{$v$} % voltage vor 2. voltage source
\end{tikzpicture}%
\end{document}
So every voltage and current arrow (black) is present due to using L+, V+. Using L and V instead errors: \begin{document}
\begin{tikzpicture}
\draw (40:4) to[L, o-, l=$L_{ab}$, name=L1] (40:2) to[V, -*, name=V1] (0:0);
\draw (130:4) to[L, o-, l=$L_{ab}$, name=L2] (130:2) to[V, -*, name=V2] (0:0);
\draw (220:4) to[L, o-, l=$L_{ab}$, name=L3] (220:2) to[V, -*, name=V3] (0:0);
\iarr{V1}{$i$} % current for 1. voltage source
\varr{V2}{$v$} % voltage vor 2. voltage source
\end{tikzpicture}%
\end{document}I have to define \begin{document}
\begin{tikzpicture}
\draw (40:4) to[L, o-, l=$L_{ab}$, name=L1] (40:2) to[V, -*, name=V1, i=~, l=~] (0:0);
\draw (130:4) to[L, o-, l=$L_{ab}$, name=L2] (130:2) to[V, -*, name=V2, v=~, l=~] (0:0);
\draw (220:4) to[L, o-, l=$L_{ab}$, name=L3] (220:2) to[V, -*, name=V3] (0:0);
\iarr{V1}{$i$} % current for 1. voltage source
\varr{V2}{$v$} % voltage vor 2. voltage source
\end{tikzpicture}%
\end{document}I still have the problem that the blue voltage arrow does not fully cancel out the black one. It would be nice if just defining |
|
Ok, I think I understand the problem. I will see if I can add the "label references" even when there is no label to print; it was not there because the idea is that when using a simple I still thing you are trying to over-automatize it; for example, for the current I would do the following --- using the NewDocumentCommand to have two different optional argument --- and probably something similar for the voltages. Then I'll add the \documentclass[tikz]{standalone}
\usepackage{circuitikz}
\NewDocumentCommand{\iarr}{O{red} D(){below} m m}{% color, where, name, label
\pgfmathanglebetweenpoints{\pgfpointanchor{#3-Ifrom}{center}}{\pgfpointanchor{#3-Ito}{center}}
\edef\myangletmp{\pgfmathresult}
%\typeout{\myangletmp}
\node [currarrow, rotate=\myangletmp, color=#1 ] at (#3-Ipos){};
\node [color=#1, rotate=\myangletmp, #2] at (#3-Ipos) {#4};
}
\NewDocumentCommand{\varr}{O{blue} D(){below} m m}{% color, where, name, label
\draw [thin, #1, -Triangle,] (#3-Vfrom) .. controls (#3-Vcont1) and (#3-Vcont2).. (#3-Vto) node [midway, sloped, #2] {#4};
}
\begin{document}
\begin{tikzpicture}
\draw (40:4) to[L, o-, l=$L_{ab}$, name=L1] (40:2) to[V, -*, name=V1, i] (0:0);
\draw (130:4) to[L, o-, l=$L_{ab}$, name=L2] (130:2) to[V, -*, name=V2, v] (0:0);
\draw (220:4) to[L, o-, l=$L_{ab}$, name=L3] (220:2) to[V, -*, name=V3] (0:0);
\iarr[blue]{V1}{$i$} % current for 1. voltage source
\iarr(above){V1}{$i$} % current for 1. voltage source
\varr(above){V2}{$v$} % voltage vor 2. voltage source
\end{tikzpicture}%
\end{document}Anyway, I will open a enhancement ticket to track this. |
|
First of all thanks for showing me \begin{document}
\begin{tikzpicture}
\draw (40:4) to[L, o-, l=$L_{ab}$, name=L1] (40:2) to[V, -*, name=V1, i>] (0:0);
\draw (130:4) to[L, o-, l=$L_{ab}$, name=L2] (130:2) to[V, -*, name=V2, v_] (0:0);
\draw (220:4) to[L, o-, l=$L_{ab}$, name=L3] (220:2) to[V, -*, name=V3] (0:0);
\iarr(above){V1}{$i$} % current for 1. voltage source
\varr(below){V2}{$v$} % voltage vor 2. voltage source
\end{tikzpicture}%
\end{document}which can be fixed defining \NewDocumentCommand{\iarr}{O{red} D(){below} m m}{% color, where, name, label
\pgfmathanglebetweenpoints{\pgfpointanchor{#3-Ifrom}{center}}{\pgfpointanchor{#3-Ito}{center}}
\edef\myangletmp{\pgfmathresult}
%\typeout{\myangletmp}
\node [currarrow, rotate=\myangletmp, color=#1 ] at (#3-Ipos){};
% rotate 180 if angle is between 90 and 270
\pgfmathparse{\myangletmp + ifthenelse(and(\myangletmp>90,\myangletmp<270),180,0)}
\edef\mylabangletmp{\pgfmathresult}
\node [color=#1, rotate=\mylabangletmp, #2] at (#3-Ipos) {#4};
}What I wanted to achieve originally was to have the same rotation for the voltage/current label as for the bipole-label. See e.g. this: \begin{document}
\begin{tikzpicture}
\draw (40:4) to[L+, o-, l=$L_{ab}$, v=v, name=L1, i=i] (40:2) to[V+, -*, v_={\(v_{12}\)}, name=V1, i=\(i\)] (0:0);
\varr[purple]{V1}{$v_{12}$}
\varr{L1}{$v_{longName}$}
\iarr{V1}{$i$}
\iarr[green]{L1}{$i_{longName}$}
\end{tikzpicture}%
\end{document}Thus, I need the to decect the label rotation. I tried \NewDocumentCommand{\iarr}{O{red} D(){below} m m}{% color, where, name, label
\pgfmathanglebetweenpoints{\pgfpointanchor{#3-Ifrom}{center}}{\pgfpointanchor{#3-Ito}{center}}
\edef\myangletmp{\pgfmathresult}
%\typeout{\myangletmp}
\node [currarrow, rotate=\myangletmp, color=#1 ] at (#3-Ipos){};
% Name not rotated -> current label not rotated
\pgfmathparse{notequal(\ctikzgetdirection{#3label},0)}
\edef\namerottmp{\pgfmathresult}
% rotate 180 if angle is between 90 and 270
\pgfmathparse{\namerottmp*(\myangletmp + ifthenelse(and(\myangletmp>90,\myangletmp<270),180,0))}
\edef\mylabangletmp{\pgfmathresult}
\node [color=#1, rotate=\mylabangletmp, #2] at (#3-Ipos) {#4};
}
\NewDocumentCommand{\varr}{O{blue} D(){below} m m}{% color, where, name, label
\draw [thin, #1, -Triangle,] (#3-Vfrom) .. controls (#3-Vcont1) and (#3-Vcont2).. (#3-Vto) node [midway, sloped, #2] {#4};
}
\begin{document}
\begin{tikzpicture}
\draw (90:4) to[L, o-, l=$L_{ab}$, name=L1] (90:2) to[V, -*, name=V1, i>, l=~] (0:0);
\draw (180:4) to[L, o-, l=$L_{ab}$, name=L2] (180:2) to[V, -*, name=V2, v_] (0:0);
\iarr(above){V1}{$i$} % current for 1. voltage source
\varr(below){V2}{$v$} % voltage vor 2. voltage source
\end{tikzpicture}%
\end{document}But this places the current label in the curcuit and thats why I used the position of the original label. |
|
I am quite convinced that I'll try to generate the label info always (even if there is just an |
|
Yes I think having the label info would fix this problem. |
|
Ok, let's move to #567 |
















I have two questions regartind the blue voltage from manual page 152:
first: I had to replace the node position to above when using this on a voltage source. Is there a general approach for a version that works with voltage sources as well as other bipoles?
second: The retation seems not to use the "smart" behavior of the element labels (see example). Can this behaviour be used?
Voltagesource2.pdf
The text was updated successfully, but these errors were encountered: