Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This question already has an answer here:

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}
share|improve this question

marked as duplicate by Jake, Martin Schröder, Manuel, Benedikt Bauer, Jesse Feb 20 at 11:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
This is where the tikzscale package comes in handy. See (How to scale tikz drawing to paperwidth?). –  Jake Feb 20 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 at 10:54
2  
You can't have an inside solution: one has to process the complete image to get the size, then calculate the scale factor and then reprocess it. To use tikzscale you don't need to move the images to external files: You can use the filecontents to create the external files on the fly. –  Ulrike Fischer Feb 20 at 11:08
    
@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 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 at 11:31

Browse other questions tagged or ask your own question.