
ellipse
을 생성 할 때 일부 상수, 높이 및 너비를 사용하고 싶지만 \newcommand
. 다음은 최소한의 예입니다.
\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}
다음 오류가 발생합니다.
오류: 14행:
Package PGF Math Error: Unknown operator `a' or `an' (in '2and 0.5*2'). ...ay!40] (0,0) ellipse (\width and \height)
답변1
안에 중괄호를 넣으십시오 \width
. 뒤의 공간을 \width
삼켜서 주어야 2and
합니다 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}
그런데, 당신은 또한 사용할 수 있습니다
\pgfmathsetmacro{\width}{2}
\pgfmathsetmacro{\height}{0.5*\width}