Problema con subfigure e circuitikz

Oct 25 2020

Ho un problema quando voglio inserire un circuito all'interno di una sottofigura . Il problema è su ">" e "<", perché se li tolgo, il codice funziona!

Sto usando i seguenti pacchetti:

\usepackage{subfigure}

Codice:

\begin{figure}[h]
    \centering
    \subfigure[circuit]{
    \begin{circuitikz}[scale=0.75,transform shape]
        \draw   (0,0) coordinate (base)
                (base)  to [R,l=$R_2$]  ++ (0,-3) node[ground]{}
                (base)  to [R,l_=$R_1$] ++ (0,3)
                        to [short,-*]           ++ (2.5,0) coordinate (cole);
        \draw   (base)  to [open]   ++ (2.5,0) node[npn](Q){}
                (base)  to [short,*-, f < = $I_B$]     (Q.B)
                %HERE THE PROBLEM! ("f < =")
                (Q.E)   to [R,l=$R_E$]      ++ (0,-2.25) node [ground]{}
                (Q.C)   to [R,l_=$R_C$] (cole);
        \draw   (cole)  to [short]  ++ (3,0) 
                        to [battery,l=$V_{CC}$]     ++ (0,-6) node[ground]{};
    \end{circuitikz}
    }

\end{figure}

L'errore è:

Argument of \language@active@arg< has an extra }. }

se metto il pacchetto: "subcaption" l'errore è:

Package subcaption Error: This package can't be used in cooperation(subcaption) with the subfigure package. \subcaption@CheckCompatibility

Grazie in anticipo!!

Risposte

3 Zarko Oct 25 2020 at 02:00

Hai due diversi problemi, uno è l'uso di pacchetti obsoleti, l'altro è la scrittura di errori di digitazione / sintassi (che è risolto dalla risposta @rmano). Fammi notare che nel tuo caso particolare, finora sembra che tu non abbia problemi con l'uso di pacchetti obsoleti.

Per quanto riguarda il primo, hai due opzioni:

  • utilizzo di subfigure:
\documentclass{article}
\usepackage[siunitx, nooldvoltagedirection]{circuitikz}
\usepackage{subfig} % <---

\begin{document}
    \begin{figure}
\subfloat[ subfloat caprion, if needed] 
{
\begin{circuitikz}
\draw   (0,0)   coordinate (aux1)
                to [R=$R_1$]    ++  (0,-3)  coordinate (base)
                to [short,*-,f< = $I_B$]    ++  (2,0)   node[right,npn](Q){}
        (base)  to [R=$R_2$]    ++  (0,-3)  coordinate (aux2)   node [ground]{}
        (aux1)  to [short,*-]   (aux1 -| Q.C)
                to [R=$R_C$]    (Q.C)
        (Q.E)   to [R=$R_E$]    (Q.E |- aux2)  node [ground]{}
(aux1 -| Q.C)   to [short,*-]   ++ (2,0)    coordinate (aux3)
                to [battery,l=$V_{CC}$] (aux3 |- aux2)  node[ground]{};
\end{circuitikz}
}
\caption{Main caption}
    \end{figure}
\end{document}

  • uso di subcaption
\documentclass{article}
\usepackage[siunitx, nooldvoltagedirection]{circuitikz}
\usepackage{subcaption} % <---

\begin{document}
    \begin{figure}
\begin{subfigure}{\linewidth}
    \centering
\draw   (0,0)   coordinate (aux1)
                to [R=$R_1$]    ++  (0,-3)  coordinate (base)
                to [short,*-,f< = $I_B$]    ++  (2,0)   node[right,npn](Q){}
        (base)  to [R=$R_2$]    ++  (0,-3)  coordinate (aux2)   node [ground]{}
        (aux1)  to [short,*-]   (aux1 -| Q.C)
                to [R=$R_C$]    (Q.C)
        (Q.E)   to [R=$R_E$]    (Q.E |- aux2)  node [ground]{}
(aux1 -| Q.C)   to [short,*-]   ++ (2,0)    coordinate (aux3)
                to [battery,l=$V_{CC}$] (aux3 |- aux2)  node[ground]{};
\end{circuitikz}
    \caption{sub figure caption, if needed}
\end{subfigure}
\caption{Main caption}
    \end{figure}
\end{document}

dove è questo caso particolare lo stesso di prima. Per il codice immagine viene utilizzato il codice da @rmano answer (+1).

3 Rmano Oct 25 2020 at 01:10

L'errore è:

Package pgfkeys Error: I do not know the key '/tikz/f <', to which you passed '$I_B$', and I am going to ignore it. Perhaps you misspelled it.

Si noti che il parser Ti k Z pensa che tu abbia usato la chiave f <e non la riconosce.

Se lo cambi con la chiave reale, che è f<(senza spazio), funzionerà.

\documentclass[border=10pt]{standalone}
\usepackage[siunitx, nooldvoltagedirection]{circuitikz}
\begin{document}
\begin{circuitikz}[scale=0.75,transform shape]
    \draw   (0,0) coordinate (base)
    (base)  to [R,l=$R_2$]  ++ (0,-3) node[ground]{}
    (base)  to [R,l_=$R_1$] ++ (0,3)
    to [short,-*]           ++ (2.5,0) coordinate (cole);
    \draw   (base)  to [open]   ++ (2.5,0) node[npn](Q){}
    (base)  to [short,*-, f< = $I_B$]     (Q.B)
    %HERE THE PROBLEM! ("f < =") is a different key than "f<="
    (Q.E)   to [R,l=$R_E$]      ++ (0,-2.25) node [ground]{}
    (Q.C)   to [R,l_=$R_C$] (cole);
    \draw   (cole)  to [short]  ++ (3,0) 
    to [battery,l=$V_{CC}$]     ++ (0,-6) node[ground]{};
\end{circuitikz}
\end{document}