GeneralWeird error: A number should have been inserted here

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
thag1987
Posts: 17
Joined: Sun Jun 14, 2015 11:19 pm

Weird error: A number should have been inserted here

Post by thag1987 »

I get the following error when compiling this code.

Missing number, treated as zero.
<to be read again>
p
l. ...eaderbox{tobias}{hagge}{CRM Data Analyst}

A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

Code: Select all

\RequirePackage{tikz}
	\newcommand{\headerbox}[3]{%
		\begin{tikzpicture}[remember picture,overlay]
			% node[<options>](<name>){<text>}
			% simple shape with text on it
			% [1] creates rectangle 4cm high (grey) box at top of page
			\node [rectangle, 
					fill={grey},
					anchor=north, 
					minimum width=\paperwidth, 
					minimum height=4cm]
					(box) at (current page.north){};
			% [2] text {firstname}{lastname} in center of box
			\node [anchor=center] 
					(name) at (box) {%
		      			\fontsize{40pt}{}\selectfont
		      			\color{white}%
		      			{\latofont #1}{#2}
		    		};
		    % [3] text under textbox[2] {job title}
		    \node [anchor=north]
		    		(name) at (name.south) {%
				      	\fontsize{16pt}{}\selectfont
				      	\latofont
				      	\color{white}%
				      	{#3}%
				    };
		\end{tikzpicture}
		\vspace{2.5cm} % vertical blank (white) space after [3]
		\vspace{-2\parskip}
	}

\begin{document}
	\headerbox{first}{last}{Job Title}
\end{document}
Even though it compiles fine otherwise and this error does not cause it to break, I'd like to understand what went wrong and if it's fixable.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Weird error: A number should have been inserted here

Post by rais »

you left the second argument in your calls to \fontsize empty, that's what that message is about.
Typically, the second argument would be about a fifth larger than the first.

KR
Rainer
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Weird error: A number should have been inserted here

Post by Stefan Kottwitz »

Hi Tobias,

I recommend to use styles for all formatting things. I would never use \fontsize etc. in node texts. Not even \node {\textbf{Important}}.

Using styles makes all more consistent. You can even inherit styles.

Here's an example:

Code: Select all

\newcommand*{\basefont}{\latofont}
\tikzset{
  BaseFont/.style    = { font = \basefont },
  BrightFont/.style  = { BaseFont, white },
  NameFont/.style    = { BrightFont,
                         font = \basefont\fontsize{40pt}{48pt}\selectfont },
  TitleFont/.style   = { BrightFont,
                         font = \basefont\fontsize{16pt}{20pt}\selectfont },
}
...
\node [anchor=north, TitleFont]
                                (name) at (name.south) {#3}};
It seems a bit much for that current purpose, but it's very useful in larger drawings with many different color and text and shape formats.

Styles in TikZ can be considered as similar to macros in standard LaTeX. When I made a drawing, I still tweak the styles and look how the drawing changes, until it's perfect. I never have to tweak in each node text this way.

Stefan
LaTeX.org admin
thag1987
Posts: 17
Joined: Sun Jun 14, 2015 11:19 pm

Re: Weird error: A number should have been inserted here

Post by thag1987 »

That actually helped me understanding it better. Wasn't aware that \fontsize{size}{skip} needs the second argument.

Thanks!
Post Reply