COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### set a tikzpicture to a specific width

• Email
• Follow

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.

 0

See related articles to this posting

Le 25/10/2010 05:45, John S. a �crit :
> 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 ??

 0

On Oct 25, 5:45=A0am, "John S." <johnjamessmi...@gmail.com> wrote:
> 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=3D\linewidth]
{external_tikzpicture}.

Ignasi

 0

On Oct 25, 4:45=A0am, "John S." <johnjamessmi...@gmail.com> wrote:
> 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

 0

Am 25.10.2010 05:45, schrieb 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}{!}{%
}

needs package graphicx

Herbert

 0

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?

 0

Le 26/10/2010 04:22, John S. a �crit :
> 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}%
}

\fbox{\box0}

\end{document}\endinput

 0
Reply gouailles (1755) 10/26/2010 8:00:31 AM

Le 26/10/2010 10:00, GL a �crit :
> Le 26/10/2010 04:22, John S. a �crit :
>> 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}%
> }
>
>
> \fbox{\box0}
>
> \end{document}\endinput


 0
Reply gouailles (1755) 10/26/2010 8:36:36 AM

Am Mon, 25 Oct 2010 19:22:06 -0700 (PDT) schrieb 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

 0

Le 26/10/2010 10:50, Ulrike Fischer a �crit :
> Am Mon, 25 Oct 2010 19:22:06 -0700 (PDT) schrieb John S.:
>
>
> 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] ?

 0

On 2010-10-26 10:58, GL wrote:

>
> 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.

 0

Le 27/10/2010 02:12, Martin Heller a �crit :
> On 2010-10-26 10:58, GL wrote:
>
>>
>> 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.

 0

On Mon, 25 Oct 2010, John S. wrote:

> 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          itayf@fastmail.fm
--------------------------------------
http://longitude.weizmann.ac.il/~itayf
--


 0