1

I am trying to draw a simple circuit with circuitikz, but in order to better suit my needs I had to modify the size of all components through /tikz/circuitikz/bipoles/length=0.9cm (default length should be 1.4cm). However, when compiling the figure on the left in the mwe below, you see that the shape of the voltage source is not satisfying.

I merged two answers from TeX.SE to try and cope with this, but I obtained the picture on the right, where the shape of the voltage source is indeed ok, but its label is scaled and the starting coordinate of the path is not where I expected it to be! I guess it has to do with the transform shape option, but I do not really know how to circumvent this issue and achieve what I wanted.

\documentclass[a4paper]{book}

\usepackage[english]{babel} \usepackage[utf8]{inputenc}

\usepackage{pgfplots} \usepgfplotslibrary{external} \tikzexternalize[prefix=mwe-\overlaynumber-] \tikzsetexternalprefix{tikzpics/} \usetikzlibrary{3D, calc, external, positioning, circuits.logic.mux, shapes.gates.logic.US} \usepackage[americaninductors]{circuitikz}

\begin{document}

\begin{figure}[h] \centering \begin{tikzpicture}[auto, node distance=4mm and 4mm, circuit logic,every node/.style={font=\tiny}, >=latex,% /tikz/circuitikz/bipoles/length=0.9cm] \def\nodedist{4mm} \def\complen{9mm} \ctikzset{tripoles/mos style/arrows, tripoles/nmos/arrow pos=0.8, tripoles/pmos/arrow pos=0.6,}

\draw (0,0) to [C, name=c] ++(\complen, 0) node[american not port, name=inv1, anchor=in] {};
\node (inv2) [right=of inv1, american not port] {};
\draw ({$(c.east)!.5!(inv1.in)$} |- inv1.in) to [short,*-] ++(0,.7*\complen) to [R] ({$(inv1.out)!.5!(inv2.in)$} |- {$(inv1.out)+(0,.7*\complen)$}) to [short,-*] ({$(inv1.out)!.5!(inv2.in)$} |- inv1.out);
\draw ({$(c.east)!.5!(inv1.in)$} |- inv1.in) to [american voltage source, l=$V_\textup{CM}$] ({$(c.east)!.5!(inv1.in)$} |- {$(inv1.in) + (0,-2*\complen)$});

\draw (inv1.out) -- (inv2.in);

\end{tikzpicture}\hfil \begin{tikzpicture}[auto, node distance=4mm and 4mm, circuit logic,every node/.style={font=\tiny}, >=latex,% /tikz/circuitikz/bipoles/length=0.9cm] \def\nodedist{4mm} \def\complen{9mm} \ctikzset{tripoles/mos style/arrows, tripoles/nmos/arrow pos=0.8, tripoles/pmos/arrow pos=0.6,}

\draw (0,0) to [C, name=c] ++(\complen, 0) node[american not port, name=inv1, anchor=in] {};
\node (inv2) [right=of inv1, american not port] {};
\draw ({$(c.east)!.5!(inv1.in)$} |- inv1.in) to [short,*-] ++(0,.7*\complen) to [R] ({$(inv1.out)!.5!(inv2.in)$} |- {$(inv1.out)+(0,.7*\complen)$}) to [short,-*] ({$(inv1.out)!.5!(inv2.in)$} |- inv1.out);
\draw \pgfextra{\ctikzset{/tikz/circuitikz/bipoles/length=1.4cm, transform shape}} ({$(c.east)!.5!(inv1.in)$} |- inv1.in) to [american voltage source, l=$V_\textup{CM}$, scale=0.6] ({$(c.east)!.5!(inv1.in)$} |- {$(inv1.in) + (0,-2*\complen)$});

\draw (inv1.out) -- (inv2.in);

\end{tikzpicture} \end{figure}

\end{document}

enter image description here

DavideM
  • 181
  • 1
    You are mixing circuitikz with internal TikZ library without using the compatibility options, so anything can happen: https://texdoc.org/serve/circuitikz/0#subsection.1.6. Moreover, I do not have tikz libraries 3D nor logic.mux. Could you please try to do a minimal example with only circuitikz? – Rmano Jul 22 '21 at 09:20
  • @Rmano, I tried adding compatibility options but to no avail. Sure, I could write a more minimal example (although I don't have the time right now), but in the end I need a solution that works with the preamble in the mwe above. – DavideM Jul 22 '21 at 09:52
  • my problem is that I do not understand the problem --- your circuit is easy to do with plain circuitikz and the styling options. So probably you have more constraints that I do not know (really the "node distance" thing will not work well with circuitikz, where the idea is to build a circuit along a path, and not positioning the nodes and then connect them like in a, say, block diagram. Anyway, without using the compatibility key to circuitikz, it will not work --- please read the manual section I linked above. – Rmano Jul 22 '21 at 10:10
  • @Rmano, I'm simply used to drawing by using nodes, distances, etc. which appears more straightforward to me, while circuitikz is quite new and I haven't fully grasped it yet. Anyway, I read the manual section that you linked and tried using the compatibility key, but unfortunately that didn't fix the problem. – DavideM Jul 22 '21 at 11:37
  • As a different question: I am curious to know where the compatibility key has failed. If you can prepare an example showing that I will investigate. – Rmano Jul 22 '21 at 12:02
  • Also --- you should not use scale nor transform shape in a path. It will change all the coordinates of that path, which you normally do not want... – Rmano Jul 22 '21 at 15:22

1 Answers1

3

Well --- first of all, as it is said in the manual at the very start, circuitikz and the internal circuit libraries are basically incompatible. The problem is that there are keys that override each other loading both... let me cite myself:

Anyway, the compatibility code is a best-effort task and only very lightly tested — the authors' advice is to choose one or the other, without mixing them.

I propose a pure circuitikz solution to the circuit --- I really do not know how to do it with the internal library, so I'll let it to somebody else.

Notice that I removed things that are not relevant to the scaling problem (comments in the code). I am not sure of your objective, so I did the second diagram with smaller components by using the class style method, and then changing the size of the "numerical" coordinates with scale (that, without transform shape, it doesn't scale the nodes nor the text).

\documentclass[a4paper]{book}

\usepackage[english]{babel} \usepackage[T1]{fontenc}% utf8 is standard, T1 not, and you want it

\usepackage{pgfplots}\pgfplotsset{compat=1.18}%never omit the compact key %\usepgfplotslibrary{external} %\tikzexternalize[prefix=mwe-\overlaynumber-]% will break outside beamer %\tikzsetexternalprefix{tikzpics/} \usetikzlibrary{calc, positioning,}%removed internal circuits libraries % it seems you want american shapes \usepackage[americaninductors, american]{circuitikz} \ctikzset{tripoles/mos style/arrows, tripoles/nmos/arrow pos=0.8, tripoles/pmos/arrow pos=0.6} \ctikzset{bipoles/length=0.9cm}% This CAN'T BE CHANGED midway a path % which such a small basic length we have to tweak the font of the generators \ctikzset{bipoles/vsourceam/inner plus={\tiny $+$}} \ctikzset{bipoles/vsourceam/inner minus={\tiny $-$}} \ctikzset{logic ports=ieee}

\begin{document}

\centering \begin{tikzpicture}[auto, node distance=4mm and 4mm, every node/.style={font=\tiny}, >=latex, scale=0.7, % coordinates are 0.7cm apart baseline, ] \draw (0,0) to[C=$C$, -*] ++(1,0) coordinate(c-r) to[inline not, -*] ++(2,0) coordinate (not1-r) to[inline not] ++(2,0); % generator \draw (c-r) to[V=$V_{\mathrm{CM}}$] ++(0,-3); % feedback \draw (c-r) -- ++(0,1) coordinate(tmp) to[R] (tmp-|not1-r) -- (not1-r); \end{tikzpicture}\quad \ctikzset{resistors/scale=0.6, capacitors/scale=0.7, logic ports/scale=0.8, sources/scale=0.8} \begin{tikzpicture}[auto, node distance=4mm and 4mm, every node/.style={font=\tiny}, >=latex, scale=0.5, % coordinates are 0.5cm apart baseline, ] \draw (0,0) to[C=$C$, -*] ++(1,0) coordinate(c-r) to[inline not, -*] ++(2,0) coordinate (not1-r) to[inline not] ++(2,0); % generator \draw (c-r) to[V=$V_{\mathrm{CM}}$] ++(0,-3); % feedback \draw (c-r) -- ++(0,1) coordinate(tmp) to[R] (tmp-|not1-r) -- (not1-r); \end{tikzpicture} \end{document}

enter image description here

PS next time, please post an MWE that compiles in a standard distribution...

Rmano
  • 40,848
  • 3
  • 64
  • 125
  • I'm sorry if the mwe I provided caused you trouble. Anyway, I'm not sure what you mean by "standard distribution", on my side I cannot compile your mwe. – DavideM Jul 22 '21 at 11:40
  • Ok, which version of TikZ and circuitikz are you on (and which LaTeX)? My distribution is TeXLive2021, updated yesterday. Have a look here: https://tex.stackexchange.com/questions/524328/i-need-to-use-a-different-version-of-circuitikz-how-can-i-do-that – Rmano Jul 22 '21 at 11:57
  • My distribution is TeXLive2019, running TikZ 3.1.4 and circuitikz 0.9.3. So, I guess updating to the latest release wouldn't be a bad idea – DavideM Jul 23 '21 at 05:59
  • Yes, that circuitikz is ancient. It's 1.4.1 now, will be .2 in a few days. – Rmano Jul 23 '21 at 07:40