8

This is a problem I found a while ago, and haven't been able to figure out. Maybe is something wrong with my distribution, but don't know exactly how to fix it. Here is the idea

Consider this script

\documentclass[border = 5pt, tikz]{standalone}
\usepackage{circuitikz}

\begin{document}
\foreach \k in {1,...,10}
{
\begin{tikzpicture}
  \draw (0, 0) rectangle (2, 2);
  \fill[red] (\k/5, 1) circle (0.1);
\end{tikzpicture}
}
\end{document}

When I run it, it produces 10 pages which then I can use to produce a gif

enter image description here

If on the other hand I change the enviroment to circuitikz

\documentclass[border = 5pt, tikz]{standalone}
\usepackage{circuitikz}

\begin{document}
\foreach \k in {1,...,10}
{
\begin{circuitikz}
  \draw (0, 0) rectangle (2, 2);
  \fill[red] (\k/5, 1) circle (0.1);
\end{circuitikz}
}
\end{document}

I get one single page with all frames on it

enter image description here

and then transforming this to a gif has proven a bit difficult to do.

Any ideas as to why this is happening? Thanks!

I'm using Version 3.14159265-2.6-1.40.19 (TeX Live 2018/MacPorts 2018.47642_7)

  • I didn't know that standalone could produce more than a single page document. – Sigur Jan 7 at 19:27
  • 2
    @Sigur Many animations are produced by producing a multipage pdf first and then convert this to an animated gif via convert -density <density> -delay <delay> -loop 0 -alpha remove multipage.pdf anited.gif. – user121799 Jan 7 at 19:32
  • 1
    @Sigur Yes, it does. If you compile the fist file in the above question, you get a multipage pdf. – user121799 Jan 7 at 19:38
  • 1
    Btw, shouldn't animated SVG be the preferred format nowadays ;-) ? – AlexG Jan 8 at 4:46
  • 1
    The tikz option not only loads tikz, it also sets [multi=tikzpicture] (which is not always a good thing to do). [multi={circuitikz,tikzpicture}] is what you want. – John Kormylo Jan 8 at 16:19
13

If you say \documentclass[border = 5pt, tikz]{standalone} this does not just load tikz but also tells standalone that it should produce single pdf pages for each tikzpicture. In order to generate separate pdf pages for circuitikz you could do

\documentclass[border = 5pt, tikz]{standalone}
\usepackage{circuitikz}
\standaloneenv{circuitikz}
\begin{document}
\foreach \k in {1,...,10}
{
\begin{circuitikz}
  \draw (0, 0) rectangle (2, 2);
  \fill[red] (\k/5, 1) circle (0.1);
\end{circuitikz}
}
\end{document}

enter image description here

Note that this possibility is not unique. Another possibility is to use

\documentclass[border = 5pt, multi={circuitikz}]{standalone}
\usepackage{circuitikz}
\begin{document}
\foreach \k in {1,...,10}
{
\begin{circuitikz}
  \draw (0, 0) rectangle (2, 2);
  \fill[red] (\k/5, 1) circle (0.1);
\end{circuitikz}
}
\end{document}

instead. For further information, please consult the standalone manual on p. 10.

  • Note to myself: next time ask sooner :) Thanks a bunch – caverac Jan 7 at 19:33
  • This MWE will be very useful in the future. – Sigur Jan 7 at 19:38
3

The same as an animated SVG, using the animations library of TikZ/Pgf-3.1:

Compile with

latex example
dvisvgm --zoom=-1 example 

example.tex:

\documentclass[dvisvgm]{standalone}
\usepackage{circuitikz}
\usetikzlibrary{animations}

\begin{document}

\begin{circuitikz}
  \draw (0, 0) rectangle (2, 2);
  \scoped [name=circle, animate = {
      object=circle, :shift = { 0s = "{(1/5,1)}", 3s = "{(2,1)}", repeats }
    }
  ] \fill[red] (0,0) circle (0.1);
\end{circuitikz}

\end{document}
  • Amazing, was this introduced in 3.1? – caverac Jan 8 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.