
我用下面的程式碼畫了一個十字。
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\begin{document}
\begin{frame}[t]
\frametitle{Cross 3}
\begin{tikzpicture}[line join=round, line cap=round]
\def\edge{
(.5,.5) -- ++ (0,1.05) to [out=0,in=-90] ++ (.5,.5) to [out=90,in=0] ++ (-.5,.5) to [out=90,in=0] ++ (-.5,.5) to [out=180,in=90] ++ (-.5,-.5) to [out=-180,in=90] ++ (-.5,-.5) to [out=-90,in=180] ++ (.5,-.5) -- ++ (0,-1.05)}
\draw[line width=.16cm,blue!60!black, fill=blue!80!black] (.5,.5) foreach \i in {0,90,180,270}{[rotate=\i] -- \edge} -- cycle;
\end{tikzpicture}
\end{frame}
\end{document}
是否可以修改\foreach
循環的一部分以產生以下圖形。
答案1
絕對地。您只需要使用\ifnum
.當您使用我之前的答案中的縮寫時\edge
,這會特別順利,從而避免了不必要的重複。更詳細地,讓我們定義
\def\edge{
(.5,.5) -- ++ \ifnum\i=180 (0,2.5) \else (0,1.05)\fi
foreach \j in {0,90,180} {to [out=\j,in=\j,looseness=1.6] ++ (\j+90:1)}
}
在這裡你可以看到,如果\i
等於 180,就會有一條長度的線2.5
,而對於所有其他的線,\i
它都是1.05
單位長。
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\begin{document}
\begin{frame}[t]
\frametitle{Cross 3}
\begin{tikzpicture}[line join=round, line cap=round]
\def\edge{
(.5,.5) -- ++ \ifnum\i=180 (0,2.5) \else (0,1.05)\fi
foreach \j in {0,90,180} {to [out=\j,in=\j,looseness=1.6] ++ (\j+90:1)}
}
\draw[line width=.16cm,blue!60!black, fill=blue!80!black] (.5,.5)
foreach \i in {0,90,180,270}{[rotate=\i] -- \edge} -- cycle;
\end{tikzpicture}
\end{frame}
\end{document}
和
\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage{verbatim}
\usepackage{tikz}
\begin{document}
\begin{frame}[t]
\frametitle{Cross 3}
\begin{tikzpicture}[line join=round, line cap=round]
\def\edge{
(.5,.5) -- ++ \ifnum\i=180 (0,2.5)to[out=90,in=90] ++ (-1,0) \else (0,1.05)
foreach \j in {0,90,180} {to [out=\j,in=\j] ++ (\j+90:1)} \fi
}
\draw[line width=.16cm,blue!60!black, fill=blue!80!black,looseness=1.6]
(.5,.5)
foreach \i in {0,90,180,270}{[rotate=\i] -- \edge} -- cycle;
\end{tikzpicture}
\end{frame}
\end{document}