Specify tikz drawing size without scaling it

tikz-pgf

I want to specify the rectangle into which a tikzpicture (not a pgfplot) will be drawn, without scaling. The goal is to require a fixed height for a figure (in points, cm, etc.) so that the height won't change as the details of the drawing change. It's expected that you could end up with a large blank area if the drawing is actually much smaller. Or, if the drawing is larger than the provided rectangle, then the drawing is allowed to overwrite the adjoining text, or it may be clipped to the drawing rectangle — it doesn't matter which of the two it does, although I would prefer overwriting.

What I'm hoping for is something like

\begin{tikzpicture}[height=200pt]

I emphatically do not want to scale the picture to make it fit a given box.

It seems like it should be possible to tweak the height of the relevant hbox or vbox that contains the drawing. If I understand how boxes work, then this would have the effect of letting the drawing scribble wherever it wants, but LaTeX would consider the drawing to have the size I specified.


@AlainMatthes asks exactly what I am after, and maybe this wasn't as clear as it could be.

I'm writing a program that allows one to edit tikz pictures as they sit on the page. That is, you can see both the surrounding text (as produced by LaTeX) and the picture you are editing. The tikz editor needs to know exactly how big the drawing area is, for obvious reasons. When the finished drawing is inserted back into the original LaTeX document, it shouldn't be changed; in particular, it should not be rescaled.

So I want to set the exact size of the box (vbox or hbox, whichever it is) that LaTeX will use when it lays out the page. I think that the answer provided by @hpekristiansen will do it. And I think the answer from @AlainMatthes would work too if you want the figure to be clipped.

Best Answer

\documentclass{article} 
\usepackage{lipsum}
\usepackage{tikz}
\begin{document}
\lipsum[1] 
\begin{tikzpicture}
\useasboundingbox (0pt,0pt) rectangle (100pt,200pt); %this sets the width and height
\draw[dashed] (0pt,0pt) rectangle (100pt,200pt); %just to show the area
\draw[red, ultra thick] (-50pt,-50pt) -- (150pt,250pt); %draws outside the area
\end{tikzpicture}
\lipsum[2] 
\end{document}

Page with text and red line