3

I would like to mix "conventional" tikz node and circuitikz components in the same tikzpicture but I have problem with positioning them.

For example, I would like to obtain this result:

enter image description here

But with the MWE below I obtain this result (the node is overlapping the battery component):

enter image description here

How can I avoid the overlap of the node and the battery without manual increase of the distance between them?

MWE

\documentclass{standalone}
\usepackage{tikz}
\usepackage{circuitikz}

\begin{document}
    \begin{tikzpicture}
        \draw (0,0) to [battery1={bat}, name=bat] ++(0.5,0)%
        (bat.east) -- ++(0.5,0)%
        node[rectangle,draw] (Nod1) {Node 1}%
        ;%
    \end{tikzpicture}
\end{document}
3
  • Try node[anchor=west,rectangle,draw] (Nod1) {Node 1} Mar 10 at 8:19
  • It works like a charm thanks a lot (I'm so silly) ! Do you want to put your comment into an answer ?
    – zetyty
    Mar 10 at 8:24
  • 2
    Notice also that anchor=west is the same as right ;-)
    – Rmano
    Mar 10 at 8:59

1 Answer 1

5

You only need to specify an anchor for the node, the default (which you have) is anchor=center, but you need anchor=west.

Update: following Zarko's comment I provide another option removing the east anchor in the battery and changing the distance.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{circuitikz}

\begin{document}
    \begin{tikzpicture}
        \draw (0,0) to [battery1={bat}, name=bat] ++(0.5,0)%
        (bat.east) -- ++(0.5,0)%
        node[anchor=west,rectangle,draw] (Nod1) {Node 1};
%%%%%%% Or better (See Zarko and Romano's comments):
        \draw (0,-2) to [battery1=bat, name=bat2] ++(0.96,0) node[anchor=west,draw] (Nod1) {Node 1};
    \end{tikzpicture}
\end{document}

enter image description here

7
  • 3
    +1, but to my opinion (bat.east) is superfluous. Code can be simple \begin{tikzpicture} \draw (0,0) to [battery1=bat] ++(0.5,0)% -- ++ (0.5,0) node[right,draw] (Nod1) {Node 1}; \end{tikzpicture}
    – Zarko
    Mar 10 at 8:40
  • @Zarko, you're right but it changes the distance. I left it there because that. If the circuit is more complex I don't want to change anything Mar 10 at 8:49
  • 2
    Juan Castaño (+1), I understand your reasons, but @Zarko has a point — the (bat.east) move the current point back a bit, so there is part of the wire which is double-stroke; it's not a big problem but can create antialiasing artifacts in some viewer.
    – Rmano
    Mar 10 at 8:58
  • 1
    @SylvainRigal, I think there is no need for that. I put 0.96 to approximate the original distance you used. But you can specify whatever distance you need. If you write there ++(1... you won't see many changes Mar 10 at 10:21
  • 1
    Ok I got it thanks!
    – zetyty
    Mar 10 at 10:29

You must log in to answer this question.

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