循環與 tikz 索引問題

循環與 tikz 索引問題

我需要一個以測試結束的循環,為什麼這個循環不起作用以及如何在這種循環中使用索引?

\documentclass[tikz]{standalone}
\usepackage{}
\usetikzlibrary{}

\begin{document}

\begin{tikzpicture}
\count255 = 0
\loop
\draw (0,0) -- (\count225,1) ;  
\advance\count255 by 1
\ifnum\count255 < 4
\repeat
\end{tikzpicture}

\end{document}

答案1

您需要在座標\the之前新增一個\count255

\documentclass{article}
%\url{http://tex.stackexchange.com/q/176229/86}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\count255 = 1
\loop
\draw (0,0) -- (0,\the\count255) ;
\advance\count255 by 1
\ifnum\count255 < 3
\repeat
\end{tikzpicture}

\end{document}

答案2

一個可能的解決方案LuaLaTeX

\documentclass{article}
\usepackage{luacode}
\usepackage{tikz}


\begin{document}
\luaexec{
tp = tex.print
count = 1
while count < 3 do
tp("\\begin{tikzpicture}")
tp("\\draw (0,0) -- (0,"..count..");")
tp("\\end{tikzpicture}");
count = count + 1
end
}

\end{document}

相關內容