# Circuitikz Current Label Placement

This is a follow-up question on this. In the aforementioned question, the current label I_\textrm{G} = 0 is overlapping with a resistor, so I ask about current arrow and label placement.

Code:

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{float}
\pgfplotsset{compat=1.17}
\usepackage[RPvoltages, american,siunitx]{circuitikz}
\usetikzlibrary{shapes, arrows.meta, automata, positioning, matrix, calc}
\usepackage[margin=1in]{geometry}
\begin{document}
\begin{figure}[H]
\centering
\begin{circuitikz}[declare function = {hypo = 4; x = 1; r ={1/2};}]
\def\myeq{=}
\ctikzset{label/align = straight}
\draw({hypo*sqrt(2) + 2},0) to [battery , l_= $V_\textrm{in}$] ++({-hypo*sqrt(2) - 2},0);
\draw(0,0) to[short, i = $I$] ++(0, -5) to[short, -*] ++(1, 0) node[label={below:$C$}](C){} to [R, l^= $R_1$, -*] ++(45:hypo) node[label={above:$A$}](A){} to[R, l^=$R_2$, -*] ++(-45:hypo) node[label = {below:$D$}](D){} to [short] ++(1, 0) to [short, i = $I$] ++(0,5);
\draw(C) to[R, l_= $R_k$, -*] ++(-45:hypo) node[label = {below:$B$}](B){} to [R, l_=$R_x$] ++(45:hypo);
%\draw(A) to [rmeter, t=G, i=$I_\textrm{G} \myeq 0$] (B);
\draw(A) to[short] ++(0, {-hypo/sqrt(2) + 1}) coordinate (belowA);
\draw(B) to[short] ++(0, {hypo/sqrt(2) - 1}) coordinate (aboveB);
\draw(belowA) to [rmeter, t=G, i=$I_\textrm{G} \myeq 0$] (aboveB);
\draw($(A) + (-x,0)$) -- ++(45:{x*sqrt(2) - r}) coordinate(arcBeforeA);
\draw(arcBeforeA) arc(135:45:r) node[pos = 0.5, label = {above:$I_A$}]{} coordinate(arcAfterA);
\draw(arcAfterA) -- ++(-45:{x*sqrt(2) - r}) node[currarrow, rotate=-45, anchor=tip]{};
\draw($(B) + (-x,0)$) -- ++(-45:{x*sqrt(2) - r}) coordinate(arcBeforeB);
\draw(arcBeforeB) arc(-135:-45:r) node[pos = 0.5, label = {below:$I_B$}]{} coordinate(arcAfterB);
\draw(arcAfterB) -- ++(45:{x*sqrt(2) - r}) node[currarrow, rotate=45, anchor=tip]{};
\end{circuitikz}
\end{figure}
\end{document}


Output:

I found a rather ad-hoc way of placing the current arrow and label. Is there a way to draw the component G directly from node A to node B while able to control where the current arrow goes, like the command node[pos = 0.4] when placing the label? Usually, the current arrow and label are either halfway between starting point and component, or halfway between finishing point and component.

I dive into the code in pgfcirccurrent.tex. Below is the related code of currarrow.

    coordinate[currarrow,pos=\ctikzvalof{current/distance},rotate=\pgf@circ@ffffff,
anchor=center](Iarrow)
(Iarrow.\pgf@circ@bipole@current@label@where)
node[anchor=\pgf@circ@dir, \circuitikzbasekey/bipole current style]
(\ctikzvalof{bipole/name}current){\pgf@circ@finallabels{current/label}}


The pos of the currarrow is controled by pos=\ctikzvalof{current/distance}. So you can change the value of the key .../current/distance to change of pos of the arrow.

Circuitikz provides a command \ctikzsetvalof in pgfcirc.defines.tex to do such thing:

\def\ctikzsetvalof#1#2{\pgfkeyssetvalue{\circuitikzbasekey/#1}{#2}}


Then you can define a key:

\tikzset{
cpos/.code={\ctikzsetvalof{current/distance}{#1}}
}


and write

\draw(A) to [rmeter, cpos=.2, t=G, i=$I_\textrm{G} \myeq 0$] (B);


Complete code:

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{float}
\pgfplotsset{compat=1.17}
\usepackage[RPvoltages, american,siunitx]{circuitikz}
\usetikzlibrary{shapes, arrows.meta, automata, positioning, matrix, calc}
\usepackage[margin=1in]{geometry}
\tikzset{
cpos/.code={\ctikzsetvalof{current/distance}{#1}}
}
\begin{document}
\begin{figure}[H]
\centering
\begin{circuitikz}[declare function = {hypo = 4; x = 1; r ={1/2};}]
\def\myeq{=}
\ctikzset{label/align = straight}
\draw({hypo*sqrt(2) + 2},0) to [battery , l_= $V_\textrm{in}$] ++({-hypo*sqrt(2) - 2},0);
\draw(0,0) to[short, i = $I$] ++(0, -5) to[short, -*] ++(1, 0) node[label={below:$C$}](C){} to [R, l^= $R_1$, -*] ++(45:hypo) node[label={above:$A$}](A){} to[R, l^=$R_2$, -*] ++(-45:hypo) node[label = {below:$D$}](D){} to [short] ++(1, 0) to [short, i = $I$] ++(0,5);
\draw(C) to[R, l_= $R_k$, -*] ++(-45:hypo) node[label = {below:$B$}](B){} to [R, l_=$R_x$] ++(45:hypo);
\draw(A) to [rmeter, cpos=.2, t=G, i=$I_\textrm{G} \myeq 0$] (B);
\draw($(A) + (-x,0)$) -- ++(45:{x*sqrt(2) - r}) coordinate(arcBeforeA);
\draw(arcBeforeA) arc(135:45:r) node[pos = 0.5, label = {above:$I_A$}]{} coordinate(arcAfterA);
\draw(arcAfterA) -- ++(-45:{x*sqrt(2) - r}) node[currarrow, rotate=-45, anchor=tip]{};
\draw($(B) + (-x,0)$) -- ++(-45:{x*sqrt(2) - r}) coordinate(arcBeforeB);
\draw(arcBeforeB) arc(-135:-45:r) node[pos = 0.5, label = {below:$I_B$}]{} coordinate(arcAfterB);
\draw(arcAfterB) -- ++(45:{x*sqrt(2) - r}) node[currarrow, rotate=45, anchor=tip]{};
\end{circuitikz}
\end{figure}
\end{document}


Actually, there has been an example in the manual that shows how to change the position of the current, in sec 4.6 Global properties of voltages and currents of page 140