I've been trying to draw the schematic of a linear power supply using a three-terminal linear regulator. As you can see, I have succeeded with the regulator. Sort of:

enter image description here

However, the code that I'm using seems unnecessarily complicated and I can't help but feel that there must be a better way. Here is a minimal example, take a look:




  \draw (0,0) -- (1,0) ++(1,0) node[rectangle,draw,
    minimum width=2cm,minimum height=1.2cm,
    label={[left]east:out}]{} ++(1,0) -- (4,0);


Look especially at the clumsy way the coordinates for the ++ operator are computed: In order to have the left side of the rectangle abut the line, we have to move half the width of the rectangle to the right. And similarly for the right side.

What I would ideally want is a thing that I can use like I can use all the other graphical elements in circuitikz, with proper anchors. I have looked at the circuitikz manual, but didn't find any graphical elements that looked like the one I want, and I have looked into the TikZ manual, but didn't know where to look. Can anyone help?

Edit added minimal complete example

  • 2
    Welcome to TeX.SE :) // Can you please complete the code, so we can copy and compile it right away? That's the standard, making things easier for all. Thanks.
    – MS-SPO
    Commented Nov 8, 2021 at 13:54
  • 1
    Sorry, I should already have known this. Commented Nov 8, 2021 at 14:01
  • While the default is to position the center of a node, you can use [anchor=west] for example to position the node with any anchor point. Commented Nov 8, 2021 at 16:10
  • No problem (with the code) // There are some packages available for block diagrams, e.g. blox, at ctan.org/topic/diagram-block?lang=en . I'm afraid, the code won't become more concise, but may be a little more ideal.
    – MS-SPO
    Commented Nov 8, 2021 at 16:13
  • @John Kormylo thanks, I did not know this! Commented Nov 8, 2021 at 18:26

1 Answer 1


If you think to reuse the circuit, I suggest looking at the manual about muxdemuxes (example here) and at subcircuits (example here).

My take would be something like this (please see the comments in the code snippet):


% bare shape for the object.
    muxdemux def={
        Lh=2, Rh=2, w=4,
% se manual section 3.4 "subcircuits"
\ctikzsubcircuitdef{lmTOS}{% TOS=three one seven, no numbers allowed here
    in, out, adj, center}{% anchors
    coordinate (#1-center)
    node [regulatorshape, anchor=center](#1-shape){} % main node
    % labels
    (#1-shape.north) node[font=\ttfamily\small, below]{LM317}
    (#1-shape.blpin 1)  node[font=\ttfamily\small, right]{in}
    (#1-shape.brpin 1)  node[font=\ttfamily\small, left]{out}
    (#1-shape.bbpin 1)  node[font=\ttfamily\small, above]{adj}
    % anchors
    (#1-shape.lpin 1) coordinate(#1-in)
    (#1-shape.bpin 1) coordinate(#1-adj)
    (#1-shape.rpin 1) coordinate(#1-out)
    % we are leaving the "current" position at the output

        \draw (0,0) -- ++(1,0) \lmTOS{myreg}{in} % position using anchor "-in"
            -- ++(1,0); % this work because the subcircuit
                        % "end" position is -out
        % otherwise you need
        % ... \lmTOS{myref}{in} (myreg-out) -- ++(1,0)
        \draw (myreg-adj) to[R] ++(0,-2) node[ground]{};
        % you can acces the internal anchors too:
        \draw [red, <-] (myreg-shape.brpin 1) -- ++(45:1);


enter image description here

  • That looks very nice, thank you! I'll try it out and if it works for me, I'll accept and upvote. Commented Nov 12, 2021 at 11:52
  • Sorry, still didn't get around to it. But it's not forgotten. Thanks again! Commented Nov 15, 2021 at 7:25

You must log in to answer this question.

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