Using circuitikz to draw circuits / figures

Added by Paco Riviere about 4 years ago

I try to write a question including a circuit diagram with circuitkz without success.
The code between comment lines works fine in a tex doc, but crashes in AMC.
What is wrong?

...
\usepackage{tikz}
\usepackage[american]{circuitikz}
...
\begin{question}{Llei dOhm}
Quin és el corrent del circuit de la figura, si V val 3 V i R 6\ohm?
%% circuit diagram ---
\begin{figure}[h!]
\begin{circuitikz}
\draw (0,0)
to[V,v=$V_o$] (0,2) % Font de tensió
to[short] (2,2) % conductor
to[R=$R_1$=2<\ohm>] (2,0) % resistor
to[short] (0,0); % conductor
\end{circuitikz}
\end{figure}
%% end of circuit diagram ---
\begin{choices}
\correctchoice{0,5 A}
\wrongchoice{2 A}
\wrongchoice{5 A}
\wrongchoice{1,5 A}
\end{choices}
\end{question}


Replies (8)

RE: Using circuitikz to draw circuits / figures - Added by Frédéric Bréal about 4 years ago

http://www.texfaq.org/FAQ-parmoderr
https://tex.stackexchange.com/questions/124346/latex-error-not-in-outer-par-mode

figure is a float environment and inside question environment, the tikz picture can't float.
Use float package and replace h! by H

off topic : use siunitx package https://www.ctan.org/pkg/siunitx

RE: Using circuitikz to draw circuits / figures - Added by Paco Riviere about 4 years ago

Thanks Gérard,

Does this means that {figure} should be inside {circuitikz} ?

Btw. adding float package and replacing h! by H gives the following error message:
Undefined control sequance simple.tex 71

Where line 71 is:
Quin és el corrent del circuit de la figura, si V val 3 V i R 6\ohm?

RE: Using circuitikz to draw circuits / figures - Added by Frédéric Bréal about 4 years ago

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{tikz,siunitx,float}
\usepackage{circuitikz}    
\usepackage[francais,bloc,completemulti]{automultiplechoice}
\usepackage{babel}
\begin{document}
\exemplaire{10}{    

\noindent{\bf QCM  \hfill TEST}

\vspace*{.5cm}
\begin{minipage}{.4\linewidth}
\centering\large\bf Test\\ Examen du 01/01/2008\end{minipage}
\champnom{\fbox{    
                \begin{minipage}{.5\linewidth}
                  Nom et prénom :

                  \vspace*{.5cm}\dotfill
                  \vspace*{1mm}
                \end{minipage}
         }}

\begin{question}{Llei dOhm}
%% circuit diagram ---
Quin és el corrent del circuit de la figura, si V val 3 V i R 6%$\ohm$?

\begin{figure}[H]
\begin{circuitikz}
\draw (0,0)
to[V,v=$V_o$] (0,2) % Font de tensió
to[short] (2,2) % conductor
to[R=$R_1$=2<\ohm>] (2,0) % resistor
to[short] (0,0); % conductor
\end{circuitikz}
%\caption{heading}
\end{figure}

%% end of circuit diagram ---
\begin{choices}
\correctchoice{0,5 A}
\wrongchoice{2 A}
\wrongchoice{5 A}
\wrongchoice{1,5 A}
\end{choices}
\end{question}
}   
\end{document}

RE: Using circuitikz to draw circuits / figures - Added by Paco Riviere about 4 years ago

(/usr/share/texlive/texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/tik
zlibrarytopaths.code.tex)))
! LaTeX Error: File `siunitx.sty' not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: sty)
Enter file name: 
! Emergency stop.

RE: Using circuitikz to draw circuits / figures - Added by Frédéric Bréal about 4 years ago

Don't worry : delete siunitx in the preamble.

RE: Using circuitikz to draw circuits / figures - Added by Paco Riviere about 4 years ago

Merci,
Malheuresement
I am not able to see the difference. I get the same error.

RE: Using circuitikz to draw circuits / figures - Added by Alexis Bienvenüe about 4 years ago

Maybe you can use the same workaround as in #746 (in French): save the graph in a box outside AMC stuff, and use it when needed.

RE: Using circuitikz to draw circuits / figures - Added by Paco Riviere about 4 years ago

I works fine!

Even so, I don't succeed to add a caption. As sson as I add a figure environment it fails to compile, unless I comment these lines:

\newsavebox{\CirVR}
\savebox{\CirVR}{
%\begin{figure}[H]
  \begin{tikzpicture}
    \draw (0,0) to [battery, l_=V,-] (0,2);
    \draw (2,2) to [short, i=$I$] (0,2);
    \draw (2,2) to [R,l=R,-] (2,0);
    \draw (2,0) to [short, -] (0,0);
  \end{tikzpicture}
%\caption{heading}
%\end{figure}
}

(1-8/8)