Discussion:
set a tikzpicture to a specific width
(too old to reply)
John S.
2010-10-25 03:45:14 UTC
Permalink
How would you resize a tikzpicture so that the width matches exactly,
say, the width of the textblock? I feel like this is a very common and
important issue, but I haven't found anything on it. One shouldn't
have to set scaling and clipping just to do this.

Thanks.
GL
2010-10-25 07:20:36 UTC
Permalink
Post by John S.
How would you resize a tikzpicture so that the width matches exactly,
say, the width of the textblock? I feel like this is a very common and
important issue, but I haven't found anything on it. One shouldn't
have to set scaling and clipping just to do this.
Thanks.
\begin{tikzpicture}[x=2cm,y=2ex]

no ??
Ignasi Furio
2010-10-25 07:24:16 UTC
Permalink
Post by John S.
How would you resize a tikzpicture so that the width matches exactly,
say, the width of the textblock? I feel like this is a very common and
important issue, but I haven't found anything on it. One shouldn't
have to set scaling and clipping just to do this.
Thanks.
Probably is not what you want but you can draw your tikzpicture on an
external pdf and the include with \includegraphics[width=\linewidth]
{external_tikzpicture}.

Ignasi
Marc van Dongen
2010-10-25 16:40:54 UTC
Permalink
Post by John S.
How would you resize a tikzpicture so that the width matches exactly,
say, the width of the textblock? I feel like this is a very common and
important issue, but I haven't found anything on it. One shouldn't
have to set scaling and clipping just to do this.
Thanks.
Hi,

This is something I've tried to figure out myself. Unfortunately, I've
never managed to figure out how to do this (with tikz). The best thing
I can suggest is that you just put your tikzpicture in a tex or latex
box.

Regards,


Marc van Dongen
Herbert Voss
2010-10-25 16:49:00 UTC
Permalink
Post by John S.
How would you resize a tikzpicture so that the width matches exactly,
say, the width of the textblock? I feel like this is a very common and
important issue, but I haven't found anything on it. One shouldn't
have to set scaling and clipping just to do this.
\resizebox{\linewidth}{!}{%
... your tikz stuff ...
}

needs package graphicx

Herbert
John S.
2010-10-26 02:22:06 UTC
Permalink
Thanks everyone, but I should have been clearer. The solutions using
other graphics packages scale a tikzpicture all together; I'm
interested in keeping the nodes at the right size so that the text
(labels, etc.) isn't distorted. Is this possible?
GL
2010-10-26 08:00:31 UTC
Permalink
Post by John S.
Thanks everyone, but I should have been clearer. The solutions using
other graphics packages scale a tikzpicture all together; I'm
interested in keeping the nodes at the right size so that the text
(labels, etc.) isn't distorted. Is this possible?
Here you have a box containing a TikZpicture of exactly 200pt x 150pt

\begin{document}\makeatletter

\setbox0=\hbox{%
\begin{tikzpicture}[x=1pt,y=1pt]
\path [use as bounding box,red] (0,0) rectangle (200pt,150pt);
\draw (0,20) -- ++(20,0) node [blue] {Hello}
[->,very thick,orange] -- ++(0,40) node [green,anchor=south]
{\Large Wolrd};
\end{tikzpicture}%
}

box0:\quad wd=\the\wd0\quad ht=\the\ht0\quad dp=\the\dp0

\fbox{\box0}

\end{document}\endinput
GL
2010-10-26 08:36:36 UTC
Permalink
Post by John S.
Thanks everyone, but I should have been clearer. The solutions using
other graphics packages scale a tikzpicture all together; I'm
interested in keeping the nodes at the right size so that the text
(labels, etc.) isn't distorted. Is this possible?
Would you 100pt x 75pt ? Then add [scale=.5] in the {tikzpicture} envir.
options.
Here you have a box containing a TikZpicture of exactly 200pt x 150pt
\begin{document}\makeatletter
\setbox0=\hbox{%
\begin{tikzpicture}[x=1pt,y=1pt]
\path [use as bounding box,red] (0,0) rectangle (200pt,150pt);
\draw (0,20) -- ++(20,0) node [blue] {Hello}
[->,very thick,orange] -- ++(0,40) node [green,anchor=south] {\Large
Wolrd};
\end{tikzpicture}%
}
box0:\quad wd=\the\wd0\quad ht=\the\ht0\quad dp=\the\dp0
\fbox{\box0}
\end{document}\endinput
Ulrike Fischer
2010-10-26 08:50:47 UTC
Permalink
Post by John S.
Thanks everyone, but I should have been clearer. The solutions using
other graphics packages scale a tikzpicture all together; I'm
interested in keeping the nodes at the right size so that the text
(labels, etc.) isn't distorted. Is this possible?
\documentclass{book}
\usepackage{tikz}
\newsavebox\mybox
\begin{document}
\newcommand\myscalefactor{1}
\newcommand\tikzcontent{%
\begin{tikzpicture}
\pgftransformscale{\myscalefactor}
\draw (-4,0)--(4,0);
\node {root} child {node {left}} child {node {right} child {node
{child}}
child {node {child}} };
\end{tikzpicture}}

\savebox\mybox{%
\fbox{\tikzcontent}}

\usebox{\mybox}

\pgfmathparse{\textwidth/\wd\mybox}
\edef\myscalefactor{\pgfmathresult}
\noindent\fbox{\tikzcontent}

\noindent \rule{\textwidth}{2pt}
\end{document}


the nodes should not define the natural size of the picture or the
result will be wrong (remove the \draw to see the effect).
--
Ulrike Fischer
GL
2010-10-26 08:58:17 UTC
Permalink
Post by Ulrike Fischer
the nodes should not define the natural size of the picture or the
result will be wrong (remove the \draw to see the effect).
What do you think about [use as bounding box] ?
Martin Heller
2010-10-27 00:12:29 UTC
Permalink
Post by GL
What do you think about [use as bounding box] ?
[use as bounding box] will override the automatic bounding box
calculation done by pgf/tikz. This will give you a box of a known size
that you can scale to a given size. This will scale everything including
text in nodes. This is not what the OP was asking for.
GL
2010-10-27 16:56:17 UTC
Permalink
Post by Martin Heller
Post by GL
What do you think about [use as bounding box] ?
[use as bounding box] will override the automatic bounding box
calculation done by pgf/tikz. This will give you a box of a known size
that you can scale to a given size. This will scale everything including
text in nodes. This is not what the OP was asking for.
Hmmm.. \begin{tikzpicture}[scale=.5]
\path [use as bounding box] ... rectangle ...

does not scale the text (I mean the fonts...)

But the OP is not very clear on his intentions may be.
Itay
2010-11-01 13:18:12 UTC
Permalink
Post by John S.
Thanks everyone, but I should have been clearer. The solutions using
other graphics packages scale a tikzpicture all together; I'm
interested in keeping the nodes at the right size so that the text
(labels, etc.) isn't distorted. Is this possible?
Just use a dummy object of the required width.
Try the code below with the two offered versions of \documentclass.
See comments inside the code below.

HTH
Itay


<code>
\documentclass{article} % Full width text
%\documentclass[twocolumn]{article} % Narrow width text
\usepackage{tikz}
\begin{document}
\fbox{% % Depict the actual tikzpicture width.
\begin{tikzpicture}
% The next line forces a picture of width ~ \linewidth.
% \linewidth is determined by the class option.
% May replace with \textwidth, or any other tex length.
\path (0cm,0cm) -- (\linewidth, 0cm);
\draw[line width=4pt] (1,-3) -- ++ (0,6)
node[anchor=south] {This is a 4pt line};
\end{tikzpicture}%
}
% The next line demonstrates that we didn't scale
% the objects inside tikzpicture.
This rule has width of 4pt: \rule{4em}{4pt}
\end{document}
</code>
--
Itay Furman ***@fastmail.fm
--------------------------------------
http://longitude.weizmann.ac.il/~itayf
--
Loading...