# Scale to fixed width of tikzpicture [duplicate]

After looking for something like that here and searching the site. I haven't found something that works (may be I skipped something important).

I would like an automated way of telling tikz the final size of the tikzpicture.

I want to draw something and I want tikz to calculate automatically the scale to show me the maximum possible. Something like \begin{tikzpicture}[scale to width = \textwidth] will scale the figure so the final tikzpicture has a width of \textwidth. The cool thing would be to make also something like scale to height = …, with both forms keeping the original ratio of the tikzpicture. But if both are issued at the same time there should be a way of having the final size fixed.

I would like this to work within tikzpicture (and not with scalebox or resizebox) so that the resulting image has the correct font size and line width.

Example:

\documentclass{scrartcl}
\usepackage{tikz}
…% Some magic code
\begin{document}

\begin{tikzpicture}
\draw (0,0) rectangle (1,1);
\draw (0.5,0.5) node {Center};
\end{tikzpicture}% This should be a square of 1cm x 1cm.

\begin{tikzpicture}[scale to with = 10cm]
\draw (0,0) rectangle (1,1);
\draw (0.5,0.5) node {Center};
\end{tikzpicture}% This should be a square of 10cm x 10cm with the word in correct size

\begin{tikzpicture}[scale to height = 8cm]
\draw (0,0) rectangle (1,1);
\draw (0.5,0.5) node {Center};
\end{tikzpicture}% This should be a square of 8cm x 8cm with the word in a correct size

\begin{tikzpicture}[scale to with = 10cm, scale to height = 6cm]
\draw (0,0) rectangle (1,1);
\draw (0.5,0.5) node {Center};
\end{tikzpicture}% This should be a rectangle of 10cm x 6cm with the word in a correct size/shape

\end{document}

-

## marked as duplicate by Jake, Martin Schröder, Manuel, Benedikt Bauer, JesseFeb 20 '14 at 11:28

This is where the tikzscale package comes in handy. See (How to scale tikz drawing to paperwidth?). –  Jake Feb 20 '14 at 10:51
I saw it in the tags. But that's NOT handy (in my opinion). Should I move all my figures to external .tikz files and then use \includegraphics[width=10cm]{figure.tikz}? I think that's far from handy. It would be much better to have that option inside the tikzpicture options. –  Manuel Feb 20 '14 at 10:54
@UlrikeFischer Okey. Fair enough. Then this question is can be closed (as a duplicate, may be). EDIT Isn't a possible way of having an option in tikzpicture which does exactly that: process the complete image to get the size, then calculate the scale factor and then reprocess it? –  Manuel Feb 20 '14 at 11:12
@Manuel: You can define a new environment manuelstikzpicture that wraps around the process described in Ulrike's answer (or you could redefine tikzpicture to do the same). –  Jake Feb 20 '14 at 11:31