1

I'm currently using Tikz together with the standalone package to generate vector graphics, that I convert from pdf to svg using pdf2sg.

To draw circuits I'm using circuitikz, but the question is about sizing Tikz figures in general. For reference, this is how my figures look:

\documentclass[convert = false]{standalone}
\usepackage[american]{circuitikz}
\begin{document}
\begin{circuitikz}
    \draw (0, 2) to [battery1] (0, 0);
    \draw (0, 2) to[R, l=$R_\mathrm{1}$] (3, 2);
    \draw (3, 2) to[D, l=$D_\mathrm{1}$] (3, 0);
    \draw (3, 0) -- (0, 0);
\end{circuitikz}
\end{document}

When I open up the resulting .svg file, the dimensions are set to width="127.815pt" and height="77.858pt"

Is there an option within Tex to specify the size of the figure I'm creating with Tikz?

Edit: Changed the word from "determine" to "specify" to clarify my intentions.

0

You can use the adjustbox to adjust the size of anything, including tikzpictures ans circuitikz.

\documentclass[convert = false]{standalone}
\usepackage[american]{circuitikz}
\usepackage{adjustbox}
\begin{document}
\begin{adjustbox}{width=3cm,height=2cm}
\begin{circuitikz}
    \draw (0, 2) to [battery1] (0, 0);
    \draw (0, 2) to[R, l=$R_\mathrm{1}$] (3, 2);
    \draw (3, 2) to[D, l=$D_\mathrm{1}$] (3, 0);
    \draw (3, 0) -- (0, 0);
\end{circuitikz}
\end{adjustbox}
\end{document}

ORIGINAL ANSWER: Compiling

\documentclass[convert = false]{standalone}
\usepackage[american]{circuitikz}
\usetikzlibrary{calc}
\tikzset{every picture/.append style={execute at end picture={
\path let \p1=($(current bounding box.north east)-(current bounding box.south
west)$) in \pgfextra{\message{x dimension=\x1, y dimension=\y1^^J}};}}}
\begin{document}
\begin{circuitikz}
    \draw (0, 2) to [battery1] (0, 0);
    \draw (0, 2) to[R, l=$R_\mathrm{1}$] (3, 2);
    \draw (3, 2) to[D, l=$D_\mathrm{1}$] (3, 0);
    \draw (3, 0) -- (0, 0);
\end{circuitikz}
\end{document}

yields the message

x dimension=124.65718pt, y dimension=76.92181pt

| improve this answer | |
  • Hi, I think I should've used a different phrasing. Is it possible to specify what dimensions I want the final figure to have? As in, can I set a x and y value that Tikz will then try to follow? Ultimately, I would like be able to scale up the svg by some factor. – Rasmus Källqvist Sep 28 '19 at 23:22
  • @RasmusKällqvist You can use the adjustbox package to achieve this, see my update. – user194703 Sep 28 '19 at 23:33
  • @SchrödingersCat That package did the trick! The background to the question was that I wanted to use this in web layouting, so this helps tremendously. – Rasmus Källqvist Sep 28 '19 at 23:42

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.