TransWikia.com

LaTeX throws error on heightof

TeX - LaTeX Asked on August 6, 2021

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.0ptrelax pgfmath@ 
                                                  
l.6 node[minimum height=heightof{A}]{A};

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

2 Answers

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}

enter image description here

Answered by Ulrike Fischer on August 6, 2021

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}

enter image description here

Answered by egreg on August 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP