
Ich möchte beim Erstellen eines einige Konstanten (Höhe und Breite) verwenden, ellipse
aber das funktioniert nicht mit \newcommand
. Hier ist ein Minimalbeispiel:
\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}
Ich erhalte die folgende Fehlermeldung:
Fehler: Zeile 14:
Package PGF Math Error: Unknown operator `a' or `an' (in '2and 0.5*2'). ...ay!40] (0,0) ellipse (\width and \height)
Antwort1
Setzen Sie es \width
in Klammern. Das Leerzeichen danach \width
wird verschluckt, um 2and
das folgende Ergebnis zu erhalten 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}
Übrigens können Sie auch
\pgfmathsetmacro{\width}{2}
\pgfmathsetmacro{\height}{0.5*\width}