
Quiero usar algunas constantes, altura y ancho, al crear un archivo, ellipse
pero no funciona \newcommand
. Aquí hay un ejemplo 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}
Obtuve el siguiente error:
error: línea 14:
Package PGF Math Error: Unknown operator `a' or `an' (in '2and 0.5*2'). ...ay!40] (0,0) ellipse (\width and \height)
Respuesta1
Poner \width
tirantes interiores. El espacio posterior \width
se traga para dar 2and
lo que debería 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}
Por cierto, también puedes usar
\pgfmathsetmacro{\width}{2}
\pgfmathsetmacro{\height}{0.5*\width}