Tx · LaTeX & TikZ

Change a CircuiTikZ Current Arrow and Label Color Together

Published By the 9to5Science editorial team

At a glance

  1. 1. Set the draw color

    Add color=<color> to the circuit drawing or the individual component path.

  2. 2. Add the current label

    Use a current annotation such as i>^={I} on the component.

  3. 3. Check the scope

    The color applies to the component path too, not just the current arrow and label.

To give a CircuiTikZ current arrow and its label the same color, set the TikZ color key on the path that draws the component. For example, color=red colors both the current arrow and the label red.

The key applies to the component path as well. If you want a black component with a colored current annotation, use a separate annotation or more specific styling rather than setting the color for the whole component path.

A minimal working example

The following document compiles with CircuiTikZ and draws a resistor with a red current arrow and label:

\documentclass{standalone}
\usepackage{circuitikz}

\begin{document}
\begin{circuitikz}
  \draw (0,0)
    to[R, color=red, i>^={$I$}] (3,0);
\end{circuitikz}
\end{document}

Here, i>^={$I$} adds a current arrow and places the label above it. The color=red option sets the draw color for that component path, so both the arrow and the label inherit red. The resistor is red as well.

To use another color, replace red with a standard color name such as blue, or define a color with xcolor and use its name. The same approach works with other current-label placements, such as i>_={$I$}, which puts the label below the arrow.

Apply the color to several components

If several component paths should all use the same color, put the draw command in a TikZ scope:

\begin{circuitikz}
  \begin{scope}[color=blue]
    \draw (0,0) to[R, i>^={$I_1$}] (2,0);
    \draw (2,0) to[L, i>^={$I_2$}] (4,0);
  \end{scope}
\end{circuitikz}

The scope’s color applies to both components and their current annotations. Draw components outside the scope if they should keep a different color.

If the component should stay black

A single color=... setting on the component path colors the component along with its current arrow and label. If that is not what you want, keep the component black and add the current annotation as a separate drawing. For example, you can draw the component first, then place a colored arrow and label along a suitable wire segment:

\begin{circuitikz}
  \draw (0,0) to[R] (3,0);
  \draw[red, ->] (0.7,0.35) -- (2.3,0.35)
    node[midway, above] {$I$};
\end{circuitikz}

This separate arrow is an ordinary TikZ arrow, not CircuiTikZ’s automatically positioned current annotation. Adjust its endpoints and label position to fit your circuit. This approach is useful when the component and its annotation need independent colors or placement.

Common mistakes

  • Expecting color=red to affect only the annotation: On the component path, it also colors the component. Use a separate annotation if the component must remain unchanged.
  • Putting the color on the label text only: Coloring $I$ alone changes the label but not the arrow. Set the path color to color both together.
  • Using draw=red when the label should change too: draw controls drawn lines and arrows; it does not necessarily set the text color. Use color=red for a shared line-and-text color.
  • Using i= without a direction marker: Include a marker such as i> to request a current arrow, along with the label syntax you want.

For the standard case, the key is simple: set color=<color> on the same component path that carries the current annotation.

References

  1. CircuiTikZ package documentation
  2. TikZ and PGF Manual

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.