LaTeX throws error on \heightof

I'm trying use \heightof in my document but XeLaTeX throws an error. Both minimal code end errors are below. Ubuntu 20.04 with latest updates

\documentclass[14pt,a4paper]{extarticle}
\usepackage{calc}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[minimum height=\heightof{A}]{A};
\end{tikzpicture}
\end{document}

ABD: EveryShipout initializing macros
! Undefined control sequence.
\pgfmath@dimen@ ...men@@ #1=0.0pt\relax \pgfmath@

l.6 \node[minimum height=\heightof{A}]{A};


UPD. The height of bold text is height("{\textbf{A}}").

• \heightof works only in \setlength or similar commands... try \documentclass{article} \usepackage{calc} \begin{document} \heightof{A} \end{document} and get a surprise ;-)... – Rmano Jan 23 at 11:13
• Thanks, that cleared things a bit – Alexander Jan 25 at 18:55

\heighof doesn't work inside tikz, use the functions provided by it. See the section "Mathematical Expressions" in the documentation.

\documentclass[14pt,a4paper]{extarticle}
\usepackage{calc}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[minimum height=height("A")]{A};
\end{tikzpicture}
\end{document}


Addition: minimum height does not describe the height of the node content, in the sense of the height of a TeX box, but the total height:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[draw,inner sep=0,minimum height=10pt] (A) {.};

\draw[red,<->] ([xshift=-2pt]A.south west) --++ (0,10pt);
\end{tikzpicture}
\begin{tikzpicture}
\node[draw,minimum height=10pt] (A) {.};

\draw[red,<->] ([xshift=-2pt]A.south west) --++ (0,10pt);
\end{tikzpicture}

\end{document}


• Try with draw and with x in the node instead of A. – egreg Jan 23 at 11:23
• @egreg that is not related to the height function, but that minimum height doesn't set the "height" but the "totalheight". – Ulrike Fischer Jan 23 at 11:39
• Thanks, especially for particular section of manual. But the problem didn't solve. The code \node[minimum height=height(\noexpand\textbf{"A"}), draw=black]{A}; throws error. The difference in "depth" is insignificant but the height should be measure of bold text – Alexander Jan 25 at 19:06

The command \heightof only works in calc package expressions.

You can use height{"A"}, but this wouldn't take care of the inner sep, so you should add it to the minimum height.

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\node[draw,minimum height=height("A")+2*(\pgfkeysvalueof{/pgf/inner ysep})]{A};
\end{tikzpicture}
\begin{tikzpicture}
\node[draw,minimum height=height("A")+2*(\pgfkeysvalueof{/pgf/inner ysep})]{x};
\end{tikzpicture}

\begin{tikzpicture}[inner sep=1pt]
\node[draw,minimum height=height("A")+2*(\pgfkeysvalueof{/pgf/inner ysep})]{A};
\end{tikzpicture}
\begin{tikzpicture}[inner sep=1pt]
\node[draw,minimum height=height("A")+2*(\pgfkeysvalueof{/pgf/inner ysep})]{x};
\end{tikzpicture}

\end{document}


• if one sets inner sep to zero, it still doesn't encompass the A: \node[draw,inner sep=0,minimum height=height("A")+2*(\pgfkeysvalueof{/pgf/inner ysep})]{\smash{A}}; – Ulrike Fischer Jan 23 at 11:42
• @UlrikeFischer The height is set correctly, The node contents is placed so that it lies at the vertical middle of the node; if the object has zero height… – egreg Jan 23 at 11:47
• Thanks, the inner sep issue was easier. Additional condition is the code \node[minimum height=height(\noexpand\textbf{"A"}), draw=black]{A}; trow error – Alexander Jan 25 at 19:13
• @Alet I'm afraid that only simple strings are accepted by inner sep; besides, \textbf would do no good because inside a TikZ picture all fonts are set to \nullfont. – egreg Jan 25 at 20:51