2

I want to draw simple CircuiTikZ symbols over a .png image. This is what I want:

wanted

This is what I currently get:

result

Here is my code:

\begin{figure} [!ht]
\begin{tikzpicture}[x=1cm,y=1cm]
\node at (0,0) {\includegraphics[trim={40cm 55cm 40cm 55cm},clip,height=10cm]{images/MecanismoEscala_primer_ensayo_Variables.png}};
\node at (-3.7634,-1.5117){
\begin{circuitikz}
\draw
 (0,0) --++ (-1.0778,0)
        to [open,v=$v$,o-o] ++(0,0.7012)
        to[short,i=$i_{a}$] ++(1.0663,0);
\end{circuitikz}
};
\end{tikzpicture}
\end{figure}\FloatBarrier

I would also like to write the $v$ besides the terminals along with the +- signs (with these two signs a little bit more apart from each other, not like the result I get).

4
  • Just a guess: when you add [draw] to your second node to outline its boundaries, you‘ll probably see that the nodes center is at the point you specified. If so, it needs a shift or realignment.
    – MS-SPO
    Oct 9, 2022 at 4:04
  • Thanks for your answer. Is there a way to anchor the first point of the circuitikz drawing to the specified point?
    – el_maxx
    Oct 9, 2022 at 10:12
  • 1
    You are nesting tikzictures. Don't do that. tex.stackexchange.com/questions/47377/…
    – Rmano
    Oct 9, 2022 at 10:48
  • 1
    If you upload/link the base image I can try an answer (later, no time left now). But basically, you can just use the answer from tex.stackexchange.com/questions/9559/… --- circuitikz is the same as tikzpicture.
    – Rmano
    Oct 9, 2022 at 10:51

1 Answer 1

7

First of all. Never nest tikzpictures! And post the basic picture, which in this case I managed to concoct with GIMP and saved as uffa.png.

enter image description here

My approach would be:

  1. load the image as a node at the start of the tikzpicture, so that then you can write on top of it.
  2. Set some kind of grid to have an easy reference.
  3. Draw whatever you want, fine tune coordinates.
  4. Remove the grid.

Let's see: step 1 & 2 would be something like this:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (image) at (0,0) {%
        \includegraphics[width=10cm]{uffa.png}};
        \draw[red,thin] (0,0) grid[step=1] (10,5);
\end{tikzpicture}
\end{document}

picture with the grid

You have 0,0 on the bottom left point, and every grid step is 1cm. Now, the background is not white (I hope you do not print it, otherwise, change it), so I picked the color that results to be a quite dark blue-grey with RGB at 33,40,48 (any color picker will do).

Now I draw the circuit, setting the blue-gray as the fill for open poles.

\documentclass[tikz]{standalone}
\usepackage[RPvoltages, american]{circuitikz}
\begin{document}
\begin{tikzpicture}[color=white]% write in white
    \node[anchor=south west,inner sep=0] (image) at (0,0) {%
        \includegraphics[width=10cm]{uffa.png}};
        \draw[red,thin] (0,0) grid[step=1] (10,5);
        \definecolor{mybg}{RGB}{33,40,48}% with a color picker
        \ctikzset{open poles fill=mybg}% tell circuitikz what is background for you
        \draw (4,4) coordinate(a) to[short, i=$i_a$, o-]  ++(1.8,0);
        \draw (a) ++(0,-1) to[short, o-] ++(1.7,0);
        \draw (a) ++(-0.3,0) to[open, v=$v$] ++(0,-1);
\end{tikzpicture}
\end{document}

with grid and circuit

I tried to use relative and named coordinates where possible, to minimize the number of numbers you need to tweak to obtain the result. Then, you remove the grid and you'll have:

final output

1
  • Thank you very much!
    – el_maxx
    Oct 9, 2022 at 21:11

You must log in to answer this question.

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