我使用下面的代码来画一个十字架。
\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}