1

The following example uses circuitikz, but the question is about expressing coordinates in generic tikz.

Look at the following code:

\documentclass[border=10pt]{standalone}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz}[american]
        \draw (0,0) node[npn](Q1){};
        \draw (Q1.E) to[R=$R_E$] (0,-2.5) node[ground]{};
        \draw [gray] (Q1.E) -- ++(2,0) 
            coordinate(tmp) to[C, color=gray] (tmp |- 0, -2.5) 
            node[ground, color=gray]{};
 \end{circuitikz}
\end{document}

where all the grounds are supposed to be at (x, -2.5). The tricky thing is the coordinate (tmp |- 0, -2.5) (hint from here): what I want to express is the concept of a coordinate which is

(the current path x, the absolute y -2.5)

and the solution I found is, as you can see, using a temporary node. Is there an easier way to write that coordinate?

BTW, for easier way I mean something to directly say "move to the coordinate that has the current value of x, and y=-2.5", like for example

\draw [gray] (Q1.E) -- ++(2,0) 
            to[C, color=gray] (\magiccurrentx, -2.5) 
            node[ground, color=gray]{};

...or a similar thing.

output of the snippet above

  • 1
    @phelype-oleinik, thanks for the edit. – Rmano Oct 3 '18 at 11:10
  • 2
    if you know distance from (Q1.E) to (0,-2.5) than you can use only relative coordinates: \draw [gray] (Q1.E) -- ++(2,0) to[C, color=gray] ++ (0,-1.73) node[ground, color=gray]{};. as i see your mwe, this distance is not known, so you determine end of this path by coordinate defined by (tmp |- 0, -2.5) . as far as i know, for this is no better way. – Zarko Oct 3 '18 at 11:42
  • I am sorry, I do not understand the question. Isn't (tmp |- 0, -2.5) already what you're looking for? If not, please consider editing (the current path x, the absolute y -2.5) in such a way that it is a bit clearer. – marmot Oct 3 '18 at 14:55
  • @marmot sorry --- for simpler I mean not having to use a temporary node; some magic to say "move to a coordinate that has the current value of x, and y=-2.5". I have made myself clearer in the question (I hope). – Rmano Oct 3 '18 at 15:26
1

If you want to save code characters you simply change coordinate(coordinate_name) for node(node_name){} and use one \draw statement, relative coordinates, and you can use the node ground coordinate named as G to find the coordinate intersection of the named coordinates from the short of the capacitor and the ground; to change the color including the nodes use color=your_fav_color, in my case red.

RESULT:

enter image description here

MWE:

\documentclass[border=10pt]{standalone}
\usepackage{circuitikz}
\begin{document}
    \begin{tikzpicture}[american]
        \draw
        (0,0)
            node[npn](Q1){}
        (Q1.E)
            to [R=$R_E$] ++(0,-2.5)
            node[ground](G){}
        ;
        \draw[color=red]
        (Q1.E)
            to[short,*-] ++ (2,0) node(C){}
            to[C] (C |- G) 
            node[ground]{}
        ;
    \end{tikzpicture}
\end{document}

OPTIONAL:

Using the two nodenames available from the first ground and the second, and drawing from the second ground to the emiter...

\documentclass[border=10pt]{standalone}
\usepackage{circuitikz}
\begin{document}
    \begin{tikzpicture}[american]
        \draw
        (0,0)
            node[npn](Q1){}
        (Q1.E)
            to [R=$R_E$] ++(0,-2.5)
            node[ground](G1){}
        ;
        \draw[color=red]
        (G1)++(2,0)
            node[ground](G2){}
            to[C] (G2 |- Q1.E) 
            to[short,-*] (Q1.E)
        ;
    \end{tikzpicture}
\end{document}
  • This is more elegant than my solution because the ground level is labelled (and I'll use it), but still need to use a coordinate (node(C){} and \coordinate(C) I think are the same thing). Thanks anyway, this is a good idea. – Rmano Oct 3 '18 at 18:01
  • This coordinate is needed to calculate the intersection to put the ground at the same x position of the first, the other option is using shftings, but writing shiftx=Some_value in a coordinate is not elegant, but I'll try another method to avoid declare the node(C){}... – J Leon V. Oct 3 '18 at 18:13
  • I was toying with the [turn] coordinate system, but no joy, still relative... ;-) – Rmano Oct 3 '18 at 18:20
  • Check the optional code... – J Leon V. Oct 3 '18 at 18:22
  • Yes, it works... although in the end I prefer your first code. Thanks! I'll wait a bit to see if something magic happens... ;-) – Rmano Oct 3 '18 at 18:31
2

Here is an alternative, but I would not call it simpler.

\documentclass[border=10pt]{standalone}
\usepackage{circuitikz}

\begin{document}
\begin{circuitikz}[american]
        \draw (0,0) node[npn](Q1){};
        \draw (Q1.E) to[R=$R_E$] (0,-2.5) node[ground]{};
        \draw [gray] (Q1.E) -- ++(2,0) \pgfextra{\pgfgetlastxy{\xlast}{\ylast}}
            to[C, color=gray]  (\xlast,-2.5)
            node[ground, color=gray]{};
 \end{circuitikz}
\end{document}
1

Very similar to John Kormylo's answer but without \pgfextra (which may cause serious trouble). Similar to John, I am not sure this is more elegant.

\documentclass[border=10pt]{standalone}
\usepackage{circuitikz}
\tikzset{magic xy/.code n args={2}{\pgfgetlastxy{#1}{#2}}}
\begin{document}
\begin{circuitikz}[american]
        \draw (0,0) node[npn](Q1){};
        \draw (Q1.E) to[R=$R_E$] (0,-2.5) node[ground]{};
        \draw [gray] (Q1.E) -- ++(2,0) [magic xy={\magicx}{\magicy}]
            to[C, color=gray]  (\magicx,-2.5)
            node[ground, color=gray]{};
\end{circuitikz}
\end{document}

Or with calc. Both reproduce your picture.

\documentclass[border=10pt]{standalone}
\usepackage{circuitikz}
\usetikzlibrary{calc}
\begin{document}
\begin{circuitikz}[american]
        \draw (0,0) node[npn](Q1){};
        \draw (Q1.E) to[R=$R_E$] (0,-2.5) node[ground]{};
        \draw[gray]  let \p1=(Q1.E) in (Q1.E)  -- ++ (2,0) 
             to[C, color=gray]  (\x1+2cm,-2.5)  node[ground, color=gray]{};
            node[ground, color=gray]{};
 \end{circuitikz}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.