0

When I used adjustwidth on a long circuit, the entire figure appears. But when I added a figure before that circuit, it just performs as if adjustwidth wasn't there (i.e. part of it gets clipped on the right side of the page). Here is the code:

\documentclass[12pt]{article}

\usepackage{amssymb, graphicx}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{float}
\usepackage{enumitem}
\usepackage{amsfonts,bm}
\usepackage{diagbox}
\usepackage[makeroom]{cancel}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows.meta, positioning}
\usepackage{verbatim}
\usepackage[american,siunitx]{circuitikz}
\usepackage[export]{adjustbox}
\usepackage{mathtools}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}
\usepackage{units}
\usepackage{relsize}
\usepackage[margin=1in]{geometry}
\usepackage{changepage}

\makeatletter
\def\pgfaddtoshape#1#2{% https://tex.stackexchange.com/a/14772/38080
    \begingroup
    \def\pgf@sm@shape@name{#1}%
    \let\anchor\pgf@sh@anchor
    #2%
    \endgroup
}
% we need to add an anchor to muxdemux
\pgfaddtoshape{muxdemux}{
    \anchor{top left ext}{%
        \topleft\advance\pgf@x by -\extshift
}}
\makeatother

\begin{document}
    \tikzset{block/.style={draw, rectangle, 
            minimum height=3em, minimum width=3em},
        sum/.style={draw, circle, node distance=1cm},
        input/.style={coordinate},
        output/.style={coordinate},
        pinstyle/.style={pin edge={to-,thin,black}}}
        \begin{figure}[H]
            \centering
            % The block diagram code is probably more verbose than necessary
            \begin{tikzpicture}[auto, node distance=2cm,>=Latex, scale = 0.85, transform shape]
            % We start by placing the blocks
            \node [input, name=input, label={left:$y\left(t\right)$}] {};
            \node [sum, right of=input, node distance = 2cm, name = sum1] {};
            \node [block, right of= sum1, node distance = 2.5cm] (int1) {$\dfrac{1}{s}$};
            \node [block, right of= int1, node distance = 3 cm] (int2) {$\dfrac{1}{s}$};
            \node [block, below of= int1, node distance = 1.75 cm] (bgain) {$b$};
            \node [block, right of= int2, node distance = 3 cm] (again) {$a$};
            \node [sum, right of= again, node distance = 2 cm, name = sum2] {};
            \node [block, right of= sum2, node distance = 2 cm] (Kgain) {$K$};
            \node [output, right of= Kgain, node distance = 2 cm, label={right:$u\left(t\right)$}] (output) {};
            % Once the nodes are placed, connecting them is easy.
            \draw [draw,->] (input) --node[pos=0.92] {$+$} (sum1);
            \draw [->] (bgain) -| node[pos=0.92] {$-$} (sum1);
            \draw [->] (sum1) -- node [name = zddot, pos = 0.5]{$\ddot{z}$}(int1);
            \draw [->] (int1) -- node [name = zdot, pos = 0.5]{$\dot{z}$}(int2);
            \draw [->] (int2) -- node [name = z, pos = 0.5]{$z$}(again);
            \draw [->] (again) -- node[pos=0.92] {$+$} (sum2);
            \draw [->] (sum2) -- (Kgain);
            \draw [->] (Kgain) -- (output);
            \draw [->] (zdot) -- (zdot |- bgain) -- (bgain);
            \draw [->] (zdot |- bgain) -| node[pos=0.92] {$+$} (sum2);
            \end{tikzpicture}
            \caption{Extended control block diagram for Problem 1b.}
        \end{figure}
        \begin{figure}[H]
            \centering
            % The block diagram code is probably more verbose than necessary
            \begin{circuitikz}[
                ]
                \tikzset{small text/.style={
                        font=\tiny,
                        right,
                        inner xsep=1pt,
                    },
                }
                \draw (9, 5) node[muxdemux, no input leads, muxdemux def={Lh=3, NL=2, w=3, Rh=0, NR=1}](sum1){$\sum\quad$};
                \draw (sum1.blpin 1) node[small text]{$1$} to[short] ++(-1, 0) node[left]{$y\left(t\right)$};
                \draw (sum1.blpin 2) node[small text]{$-b$};
                \draw (sum1.brpin 1) -- ++ (0.5, 0) node [label={[shift={(0,-0.2)}]above:$\ddot{z}$}]{} -- ++ (0.6, 0) node[muxdemux, no input leads, muxdemux def={Lh=2, NL=3, w=2, Rh=0, NR=1}, anchor=lpin 2] (int1){$\int\quad$};
                \draw[line width=0.8pt] (int1.north west -| int1.lpin 2) rectangle (int1.south west -| int1.blpin 2);
                \node [small text] at (int1.lpin 2) {$1$};
                \draw (int1.brpin 1) -- ++ (0.5, 0) node [label={[shift={(0,-0.2)}]above:$\dot{z}$}]{} coordinate (dotz) -- ++ (0.6, 0) node[muxdemux, no input leads, muxdemux def={Lh=2, NL=3, w=2, Rh=0, NR=1}, anchor=lpin 2] (int2){$\int\quad$};
                \draw[line width=0.8pt] (int2.north west -| int2.lpin 2) rectangle (int2.south west -| int2.blpin 2);
                \node [small text] at (int2.lpin 2) {$1$};
                \draw (dotz) -- ++ (0, -1.5) coordinate (belowDotZ) -- ++ (-5, 0) |- (sum1.blpin 2);
                \draw (int2.brpin 1) -- ++ (0.5, 0) node [label={[shift={(0,-0.2)}]above:$z$}]{} -- ++ (0.6, 0) node[muxdemux, no input leads, muxdemux def={Lh=3, NL=2, w=3, Rh=0, NR=1}, anchor = blpin 1](sum2){$\sum\quad$};
                \draw (sum2.blpin 1) node[small text]{$a$};
                \draw (sum2.blpin 2) node[small text]{$1$} -- ++ (-0.5, 0) |- (belowDotZ);
                \draw (sum2.brpin 1) -- ++ (1.1, 0) node[muxdemux, no input leads, muxdemux def={Lh=2, NL=1, w=2, Rh=0, NR=1}, anchor=blpin 1] (gain){$K\quad$};
                \draw (gain.brpin 1) -- ++(0.5, 0) node[right]{$u\left(t\right)$};
            \end{circuitikz}
            \caption{Analog computer diagram for Problem 1b.}
        \end{figure}
        \begin{figure}[H]
            \centering
            \begin{adjustwidth*}{}{-5em} 
                \begin{circuitikz}[scale = 0.55, transform shape]
                    \draw (9, 5) node [op amp] (FBOA) {};
                    \draw (FBOA.-) to[short, -*] ++ (-1.5, 0) coordinate (FBOAnegBreak) to[R, l_=$R_\textrm{FB1}$, -o] ++ (-3, 0)node[label={left:$y\left(t\right)$}]{};
                    \draw (FBOAnegBreak) to[R, l_=$R_\textrm{FB2}$] ++ (0, -5) coordinate (FB2);
                    \draw (FBOAnegBreak) -- ++ (0, 1.5) to [R, l^=$R_\textrm{FB,out}$] ++ (3.5, 0) -| (FBOA.out);
                    \draw (FBOA.+) node[ground]{};
                    \draw (FBOA.out) node[label={below:$-\ddot{z}\left(t\right)$}]{} to [R, l^=$R_\textrm{int1,in}$] ++ (3, 0) node [op amp, anchor = -] (int1) {};
                    \draw (int1.+) node[ground]{};
                    \draw (FBOA |- FB2) node [op amp, xscale = -1] (bOA){};
                    \draw (bOA.+) node[ground]{};
                    \draw (bOA.out) -- (FB2);
                    \draw (int1.-) -- ++ (0, 1.5) to [C, l^=$C_\textrm{int1,out}$] ++ (2.5, 0) coordinate (nearInt1Out) |- (int1.out);
                    \draw (bOA.-) to [R, l^= $R_{b,\textrm{in}}$] ++ (3, 0) coordinate (bOANegIn);
                    \draw (nearInt1Out |- int1.out) node[label={below right:$\dot{z}\left(t\right)$}]{} |- (bOANegIn);
                    \draw (bOA.-) -- ++ (0, 1.5) to [R, l_=$R_{b,\textrm{out}}$] ++ (-2.5, 0) coordinate (nearbOAOut) -- (bOA.out-|nearbOAOut) node[label={below:$-b\dot{z}\left(t\right)$}]{};
                    \draw (nearInt1Out) |- (int1.out) to [R, l^=$R_\textrm{int2,in}$] ++ (3, 0) node [op amp, anchor = -] (int2) {};
                    \draw (int2.+) node[ground]{};
                    \draw (int2.-) -- ++ (0, 1.5) to [C, l^=$C_\textrm{int2,out}$] ++ (2.5, 0) coordinate (nearInt2Out) |- (int2.out);
                    \draw (nearInt2Out) |- (int2.out) node[label={below:$-z\left(t\right)$}]{} to [R, l^=$R_{a,\textrm{in}}$] ++ (3, 0) node [op amp, anchor = -] (aOA) {};
                    \draw (aOA.+) node[ground]{};
                    \draw (aOA.-) -- ++ (0, 1.5) to [R, l^=$R_{a,\textrm{out}}$] ++ (2.5, 0) coordinate (nearaOAOut) |- (aOA.out);
                    \draw (nearaOAOut |- aOA.out) node[label={below:$az\left(t\right)$}]{} to [R, l^= $R_\textrm{sum,1}$,-*] ++ (3, 0) coordinate (nearSumNeg) to[short] ++ (1, 0) node [op amp, anchor = -] (summer) {};
                    \draw (summer.+) node[ground]{};
                    \draw (nearSumNeg) -- (nearSumNeg |- bOANegIn) to [R, l_= $R_\textrm{sum,2}$] ++ (-3, 0) -- (bOANegIn);
                    \draw (nearSumNeg) -- ++ (0, 1.5) to [R, l^=$R_\textrm{sum,out}$] ++ (3, 0) -| (summer.out);
                    \draw (summer.out) node[label={below:$x\left(t\right)$}]{} to [R, l^= $R_{K,\textrm{in}}$] ++ (3, 0) node [op amp, anchor = -] (KOA) {};
                    \draw (KOA.+) node[ground]{};
                    \draw (KOA.-) -- ++ (0, 1.5) to [R, l^=$R_{K,\textrm{out}}$] ++ (2.5, 0) coordinate (nearKOAOut) |- (KOA.out);
                    \draw (nearKOAOut |- KOA.out) to [short, -o] ++ (0.5, 0) node[label={right:$u\left(t\right)$}]{};
                \end{circuitikz}
            \end{adjustwidth*}
            \caption{Circuit for Problem 1b.}
        \end{figure}

\end{document}

Picture: enter image description here

Can someone explain what is going on with adjustwidth?

6
  • 1
    Are you ignoring errors? I'd expect adjustwidth to be given two arguments, both lengths, you're leaving one empty. Plus what exactly are you expecting adjustwidth to do here?
    – daleif
    Feb 28, 2020 at 20:17
  • I am not getting any errors, and in fact, I am trying to shift the Figure 6 to the left so that the entire figure doesn't go off the page.
    – Superman
    Feb 28, 2020 at 20:20
  • 1
    You need the left arg for that, a negative arg will move the gig into the left margin. You're currently just making space for it into the tight margin
    – daleif
    Feb 28, 2020 at 20:25
  • Can you show me how I should code it then so that the long circuit will shift left and be entirely seen as desired?
    – Superman
    Feb 28, 2020 at 20:26
  • 1
    See what happens if you give it a negative length in the first argument (the one currently empty)
    – daleif
    Feb 28, 2020 at 21:11

1 Answer 1

2

Hmmm... let me say that this is not a minimal example, but well... I will put here only the changes.

The main problem is the use of adjustwidth, as noticed by @daelif --- I simply do not know from where it comes (not in found in adjustbox manual I have). If you change your adjustwidth environment with:

\begin{adjustbox}{max width=\linewidth}
...
\end{adjustbox}

everything works, although there are still some points to take into account:

  1. If you rescale the circuit, using [scale=0.55, transform shape] is simply try to test the limits of PGF math precision... better remove it.

  2. You should look at the warnings. Add one of the voltage options to circuitikz (you'll regret that in the future otherwise) like

    \usepackage[american,siunitx,RPvoltages]{circuitikz}
    
  3. On the same line, add

     \pgfplotsset{compat=1.15}
    

    (or whichever version you have) to have future-proof diagrams.

Finally, the resulting circuit:

final circuit

is in my opinion too small to be easily read --- consider putting it on two lines, or at least make the fonts bigger (and you need a connection dot on the output on the first integrator!).

You must log in to answer this question.

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