# How to specify width and height of \makebox using \widthof and \heightof without generating error?

As soon as the following (working) definition

\newcommand
{\TESTFRACTION}
{%
\makebox
[\widthof{${}\left(\frac{a}{1}\right){}$}]
{${}\left(\frac{b}{1}\right){}$}
}


is changed to one which also includes height

\newcommand
{\TESTFRACTION}
{%
\makebox
(\widthof{${}\left(\frac{a}{1}\right){}$},
\heightof{${}\left(\frac{a}{1}\right){}$})
{${}\left(\frac{b}{1}\right){}$}
}


! Missing number, treated as zero. error is generated on the same line where \TESTFRACTION is used inside equation environment.

Following is a working version to serve as a scaffolding to try to get \makebox' accept, both, width and height using\widthofand\heightof

\documentclass{standalone}
\usepackage[alignedleftspaceno]{amsmath}
\usepackage{calc}
\usepackage{tikz}

\newcommand
{\TESTFRACTION}
{%
\makebox
[\widthof{${}\left(\frac{a}{1}\right){}$}]
{${}\left(\frac{b}{1}\right){}$}
}

\begin{document}
\begin{tikzpicture}
\path node
{%
$% \begin{gathered} \TESTFRACTION \end{gathered}$
};
\end{tikzpicture}
\end{document}


• What is the idea or main purpose behind your macro? – Werner Oct 23 '17 at 1:02
• Fixed-width? You're making them a width similar to what they already are. It's still not clear what your intent is... perhaps you only showed a small example that doesn't highlight the actual use-case. – Werner Oct 23 '17 at 2:14

Wait for others too, but I think, parbox is better to do what you want:

WE with parbox:

\documentclass{standalone}
\usepackage[alignedleftspaceno]{amsmath}
\usepackage{calc}
\usepackage{tikz}

\newcommand
{\TESTFRACTION}
{%
\parbox[c]
[\heightof{${}\left(\frac{a}{1}\right){}$}][c]
{\widthof{${}\left(\frac{a}{1}\right){}$}}
{${}\left(\frac{b}{1}\right){}$}
}

\begin{document}
\begin{tikzpicture}
\path node
{
$% \begin{gathered} \TESTFRACTION \end{gathered}$
};
\end{tikzpicture}
\end{document}


I also think, that the makebox version you are trying to use has to be in a picture environment. And this makes things strange for your needs.

TikZ has nothing to do with this: calc related computations are not available in coordinates, such as in \makebox(x,y){BOX}. By the way, the coordinates should be in multiples of \unitlength rather than lengths.

You can exploit picture for being able to pass lengths also in this case, but \widthof and \heightof are out of question.

\documentclass{standalone}
\usepackage{amsmath}
\usepackage{picture}
\usepackage{tikz}

\newlength{\TFW}\newlength{\TFH}

\newcommand{\TESTFRACTION}{%
\settowidth{\TFW}{$\left(\frac{a}{1}\right)$}%
\settowidth{\TFH}{$\left(\frac{a}{1}\right)$}%
\makebox(\TFW,\TFH){$\left(\frac{b}{1}\right)$}%
}

\begin{document}

\begin{tikzpicture}
\path node {%
$\begin{gathered} \TESTFRACTION \end{gathered}$%
};
\end{tikzpicture}

\end{document}
`