I'd like to scale a TikZ picture based on font size surrounding the environment.
For example...
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
{
\begin{tikzpicture}
\draw (-1,-1) rectangle (1,1);
\node at (0,0) {Hello world};
\end{tikzpicture}
}
{
\Huge
\begin{tikzpicture}
\draw (-1,-1) rectangle (1,1);
\node at (0,0) {Hello world};
\end{tikzpicture}
}
{
\tiny
\begin{tikzpicture}
\draw (-1,-1) rectangle (1,1);
\node at (0,0) {Hello world};
\end{tikzpicture}
}
\end{document}
I expect the second and third of these images to look like the first one, but scaled. Is it possible to use the x=
and y=
keys on the TikZ picture environment to allow for scaling of the image relative to the current font size?
EDIT
After a little more work I came up with the following...
\documentclass{standalone}
\usepackage{tikz}
\usepackage{printlen}
\newlength{\textsizenow}
\makeatletter
\newcommand{\refreshtextsizenow}{%
\setlength{\textsizenow}{\f@size pt}
}
\makeatother
\newcommand{\example}{%
\refreshtextsizenow
\begin{tikzpicture}[x=\textsizenow,y=\textsizenow]
\draw (-3,-3) rectangle (3,3);
\node at (0,0) {Hello world};
\end{tikzpicture}
}
\begin{document}
{
\Huge
\example
}
{
\huge
\example
}
{
\LARGE
\example
}
{
\Large
\example
}
{
\large
\example
}
{
\normalsize
\example
}
{
\small
\example
}
{
\footnotesize
\example
}
{
\scriptsize
\example
}
{
\tiny
\example
}
\end{document}
It uses \f@size
to set a length before each image is drawn. I then use the x=...,y=...
keys to set the coordinate size. This seems to get close to what I am trying to do. However, if the code above is compiled, the horizontal spacing between the text and the sides shrink as the text size gets smaller. The vertical spacing seems somewhat consistent. I expect both the horizontal and vertical spacing to stay the same. Is this possible to fix?
\node
at the end of the picture environment.em
as unit in your TikZ environment which is a unit that is relative to the font size.