
Quero usar algumas constantes, altura e largura, ao criar um, ellipse
mas 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 \width
aparelho dentro. O espaço depois \width
é engolido para dar 2and
o 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}
Aliás, você também pode usar
\pgfmathsetmacro{\width}{2}
\pgfmathsetmacro{\height}{0.5*\width}