I just came to the following problem - using \settowidth
on a length in a tikzpicture
resets that length to 0? Here is a (totally command-line) MWE, compiled with pdflatex test.tex
:
\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
\newlength{\mypgVTitleWidth}
\newbox\tbxa
\setlength{\mypgVTitleWidth}{1.0pt}
\typeout{ = A: \mypgVTitleWidth is \the\mypgVTitleWidth }
\ %
\settowidth{\mypgVTitleWidth}{MMMMM}
\typeout{ = B: \mypgVTitleWidth is \the\mypgVTitleWidth }
\setbox\tbxa\hbox{{MMMMM}}
\mypgVTitleWidth\wd\tbxa
\typeout{ = B2: \mypgVTitleWidth is \the\mypgVTitleWidth }
\fontsize{10}{10}\selectfont
\ %
\settowidth{\mypgVTitleWidth}{MMMMM}
\typeout{ = C: \mypgVTitleWidth is \the\mypgVTitleWidth }
{
\fontsize{30}{30}\selectfont
\ %
\settowidth{\mypgVTitleWidth}{MMMMM}
\typeout{ = D: \mypgVTitleWidth is \the\mypgVTitleWidth }
}
\begin{tikzpicture}
\typeout{ = E: \mypgVTitleWidth is \the\mypgVTitleWidth }
\fontsize{30}{30}\selectfont
\ %
\settowidth{\mypgVTitleWidth}{MMMMM}
\typeout{ = F: \mypgVTitleWidth is \the\mypgVTitleWidth }
\end{tikzpicture}
\end{document}
first problem
With that code, with tikzpicture
, the following log is generated:
= A: \mypgVTitleWidth is 1.0pt
= B: \mypgVTitleWidth is 53.83278pt
= B2: \mypgVTitleWidth is 53.83278pt
= C: \mypgVTitleWidth is 45.83344pt
LaTeX Font Warning: Font shape `OT1/cmr/m/n' in size <30> not available
(Font) size <24.88> substituted on input line 30.
= D: \mypgVTitleWidth is 105.74562pt
= E: \mypgVTitleWidth is 45.83344pt
= F: \mypgVTitleWidth is 0.0pt
Notably, trace F shows 0.0pt. Comment out the begin and end tikzpicture
- and this shows in the log:
...
= D: \mypgVTitleWidth is 105.74562pt
= E: \mypgVTitleWidth is 45.83344pt
= F: \mypgVTitleWidth is 105.74562pt
... as expected.
second problem
If I use \fontsize..\selectfont in a group to make temporary changes to calculate a length; I get one length inside the {...}
group - and the previous as soon as I exit:
= D: \mypgVTitleWidth is 105.74562pt
= E: \mypgVTitleWidth is 45.83344pt
... Ok, this I guess is the very purpose of the group (to make sure changes are local) - but if I wanted to save this length for using further on in the code (say in the tikzpicture), what would I do? I tried also with second \newlength
set to 0 and \addtolength
, that resets itself as well.
Any ideas why this is happening, and how to: get \settowidth
working also in tikz?
- and read \settowidth
from groups?
tikzpicture
environment the current font isnullfont
, which has no characters. Look fornullfont
on this site.