6

I'm struggling to get amplifiers to sit nicely in my circuits. Here's the code:

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage{circuitikz}

\begin{figure}[H]
    \centering
    \begin{circuitikz}
        \draw
        (0, 0) node[op amp] (opamp) {}
        (opamp.-) to[R] (-3, 0.5)
        (opamp.-) -- (-1, 2) to[C] (1, 2) -- (opamp.out)
        ;
    \end{circuitikz}
\end{figure}

\end{document}

But this is what it looks like:

tex

I'm basically having to use trial and error to get those vertical lines to be actually vertical. Surely there is a better way than this?

2 Answers 2

9

The solution by Gonzalo works, but in my opinion, it's better to stick with the circuitikz bipoles (in this case short) so that labeling and connections can be done using the typical circuitikz notation if required:

\documentclass{standalone}
\usepackage{circuitikz}

\begin{document}
\begin{circuitikz}
  \draw
  (0, 0) node[op amp] (opamp) {}
  (opamp.-) to[R] (-3, 0.5)
  (opamp.-) to[short,*-] ++(0,1.5) coordinate (leftC)
  to[C] (leftC -| opamp.out)
  to[short,-*] (opamp.out)
;\end{circuitikz}
\end{document}

The -|/|- syntax is very similar, but it uses some labeled coordinates to find the intermediate location.

enter image description here

2
  • Thanks! What is the ++ syntax? Commented Feb 16, 2015 at 22:09
  • 1
    @ACarter that is relative coordinate specification. (In this case 1.5 units above the last point on the path.) I use it almost exclusively, because I can grab these snippets and drop them in a new diagram without worrying about updating all the numbers. Commented Feb 16, 2015 at 22:21
6

Use the |- ("first vertical, then horizontal"), -| ("first horizontal, then vertical") path modifiers:

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage{circuitikz}

\begin{document}

\begin{figure}
    \centering
    \begin{circuitikz}
        \draw
        (0, 0) node[op amp] (opamp) {}
        (opamp.-) to[R] (-3, 0.5)
        (opamp.-) |- (-1, 2) to[C] (1, 2) -| (opamp.out)
        ;
    \end{circuitikz}
\end{figure}

\end{document}

The result:

enter image description here

Connectors can also be added:

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage{circuitikz}

\begin{document}

\begin{figure}
    \centering
    \begin{circuitikz}
        \draw
        (0, 0) node[op amp] (opamp) {}
        (opamp.-) to[R] (-3, 0.5)
        (opamp.-) |-  (-1, 2) to[C] (1, 2) -| (opamp.out)
        ;
    \draw  (opamp.-) to[short,*-] ++(0,0);    
    \draw  (opamp.out) to[short,*-] ++(0,0);    
    \end{circuitikz}
\end{figure}

\end{document}

enter image description here

3
  • Thanks, works a treat! Do you know how I can draw nodes at the connections when using |-? (As in like you would with *-*) Commented Feb 16, 2015 at 19:45
  • @ACarter Sure: \centering \begin{circuitikz} \draw (0, 0) node[op amp] (opamp) {} (opamp.-) to[R] (-3, 0.5) (opamp.-) |- (-1, 2) to[C] (1, 2) -| (opamp.out) ; \draw (opamp.-) to[short,*-] ++(0,0); \draw (opamp.out) to[short,*-] ++(0,0); \end{circuitikz} \end{figure} Commented Feb 16, 2015 at 20:11
  • @ACarter but with this new requirement, Paul's approach seems to be shorter and the way to go. Commented Feb 16, 2015 at 20:16

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.