# How to scale Tikz drawings and text together?

I'm trying to build a diagram (a logo, actually) that I can scale easily through a parameter. I'd like to be able to scale both drawing and fonts through a single parameter.

Here's my current MWE, which I hope will illustrate my difficulties:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{fontspec}
\begin{document}
\begin{tikzpicture}[scale=1.0]
\node [draw=black] at (0,0)
{\fontspec[Scale=2.0]{Bookman Old Style Bold}B};
\node [draw=none] at (0,-0.5)
{\fontspec[Scale=1.0]{Bookman Old Style} This is a B};
\end{tikzpicture}
~
\begin{tikzpicture}[scale=2.0]
\node [draw=black] at (0,0)
{\fontspec[Scale=4.0]{Bookman Old Style Bold}B};
\node [draw=none] at (0,-0.5)
{\fontspec[Scale=2.0]{Bookman Old Style} This is a B};
\end{tikzpicture}
\end{document}


which gives me this:

I have two problems:

1. How can I derive the scale=1/2/4s from a single parameter?

2. Why is there proportionally less space between the box and the dot on the "i" of "is".

Update:

The consensual approach seems to be "transform everything", which I am happy with, although it seems to me to be (somewhat) a second-best solution. Why?

Well, as I understand it, scaling fonts isn't strictly linear point-by point. In other words, I believe that a 10pt font scaled by x2 is not the same as the same font at 20pt.

As well as this, global scaling will also scale the line thicknesses; this may well limit just how far I can scale up or down.

Clearly I was assuming that fontspec scale= does a proper "font upsizing". Otherwise my code is just as "second-best" as everyone else's.

I'll leave things alone for a bit more time, then accept and vote on the answers.

BTW, for those who don't have the font family installed, that's not an important part of the question. "Any font will do, except Comic Sans".

-
use \scalebox from graphicx. Ok it's not a TikZ solution, but it works... –  Seamus May 14 '11 at 15:02
@Seamus: In principle, I would be happy to use scalebox, but would it scale the fonts in a correct typographically respectful manner? (Ie not just "explode the bitmap") –  Brent.Longborough May 14 '11 at 15:05
I can't compile your MWE because I miss the fonts. I actually installed TeXLive with all packages... –  Martin Scharrer May 14 '11 at 15:16
That's a good point. Although I guess it's more an argument against using bitmap fonts rather than against just scaling TikZ's output... –  Seamus May 14 '11 at 15:22
@Martin Scharrer: The font in itself isn't too important; you may care to change the fonts to something you can compile... –  Brent.Longborough May 14 '11 at 17:14

To scale everything together you might want to wrap everything in a \scalebox{<factor>}{...} (graphic/x package, already loaded by tikz). The scale option of tikz works differently: it only scales coordinates. The inner sep value which determines the border will not be scaled by it, which results in the i being further away from the border. You would need to adjust this value with the scale factor as well if you don't use \scalebox.

Alternatively you can try to use drawing units which are relative to the font size, measured in either ex or em. The default you use at the moment is in cm. Even better would be to use anchors for the positioning instead, i.e. try this:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{fontspec}
\begin{document}
\begin{tikzpicture}[scale=1.0,inner sep=4pt]
\node [draw=black] (B)
{\fontspec[Scale=2.0]{Bookman Old Style Bold}B};
\node [draw=none,anchor=north] at (B.south)
{\fontspec[Scale=1.0]{Bookman Old Style} This is a B};
\end{tikzpicture}
~
\begin{tikzpicture}[scale=2.0,inner sep=8pt]
\node [draw=black] (B)
{\fontspec[Scale=4.0]{Bookman Old Style Bold}B};
\node [draw=none,anchor=north] at (B.south)
{\fontspec[Scale=2.0]{Bookman Old Style} This is a B};
\end{tikzpicture}
\end{document}


I can't compile it by myself due to the missing fonts.

-

You can use the transform canvas transformation in Tikz. It transforms EVERYTHING. An example is :

\documentclass{minimal}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[]

\begin{scope}[]
\node [draw=black] at (0,0) {\textbf{B}};
\node [draw=none] at (0,-0.5) {This is a B};
\end{scope}

\begin{scope}[shift={(2,0)},transform canvas={scale=2.0}]
\node [draw=black] at (0,0) {\textbf{B}};
\node [draw=none] at (0,-0.5) {This is a B};
\end{scope}

\begin{scope}[shift={(8,0)},transform canvas={yscale=4.0}]
\node [draw=black] at (0,0) {\textbf{B}};
\node [draw=none] at (0,-0.5) {This is a B};
\end{scope}

\end{tikzpicture}
\end{document}


The output is

-
Thank you for an interesting answer. I haven't accepted it --- sorry --- as in the end I chose to go with Martin's, because I already have a fair bit of trouble getting my head round TikZ' multiplicity of frames of reference. –  Brent.Longborough May 15 '11 at 8:26

I might be missing something about the more complicated answers above (since I can't compile the code), but nodes (and their contents) will ignore external transformations unless you use the "transform shape" option on the nodes, or enclosing scope. See the manual section 16.7. Once you do this external scaling applies to nodes and the text.

-