Usando \newcommand com elipse no tikz

Usando \newcommand com elipse no tikz

Quero usar algumas constantes, altura e largura, ao criar um, ellipsemas não funcionará com \newcommand. Aqui está um exemplo mínimo:

\documentclass[12pt, a4paper]{article}

\usepackage{amsthm, tikz}
\usetikzlibrary{arrows, shapes, trees, positioning}
\begin{document}

\begin{figure}
\centering
\begin{tikzpicture} 

    \newcommand*{\width}{2}%
    \newcommand*{\height}{0.5*\width}%

    \draw[fill=gray!40] (0, 0) ellipse (\width and \height); \node (Y) at (0,0) {\(Y\)};    

\end{tikzpicture}
\end{figure}

\end{document} 

Estou tendo o erro a seguir:

erro: linha 14:

Package PGF Math Error: Unknown operator `a' or `an' (in '2and 0.5*2'). ...ay!40] (0,0) ellipse (\width and \height)

Responder1

Coloque \widthaparelho dentro. O espaço depois \widthé engolido para dar 2ando que deveria ser 2 and.

\documentclass[12pt, a4paper]{article}

\usepackage{amsthm, tikz}
\usetikzlibrary{arrows, shapes, trees, positioning}
\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}

    \newcommand*{\width}{2}%
    \newcommand*{\height}{0.5*\width}%

    \draw[fill=gray!40] (0, 0) ellipse ({\width} and {\height}); \node (Y) at (0,0) {\(Y\)};

\end{tikzpicture}
\end{figure}

\end{document}

insira a descrição da imagem aqui

Aliás, você também pode usar

\pgfmathsetmacro{\width}{2}
\pgfmathsetmacro{\height}{0.5*\width}

informação relacionada