我想做一些類似以下程式碼片段的事情,但我卻收到了很多錯誤:
\foreach \x in {0,...,8} {
\foreach \y [evaluate=\y as \z using int(4-\y)] in {0,...,4} {
\ifthenelse{\less{x}{y} \OR \equal{x}{y}}
{ \node at (\x cm,\y cm) (g-\x-\y) {$a_{\x,\z}$}; }
{ }
}
}
意義僅當節點屬於上三角形時才顯示該節點。
答案1
你是這個意思嗎?
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \x in {0,...,8} {
\foreach \y [evaluate=\y as \z using int(4-\y)] in {0,...,4} {
\pgfmathtruncatemacro{\myresult}{\x<\z ? 1 : 0}
\ifnum\myresult=0%
\node at (\x cm,\y cm) (g-\x-\y) {$a_{\x,\z}$};\fi
}
}
\end{tikzpicture}
\end{document}
答案2
你想要這樣的東西嗎?
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round, scale=1]
\foreach \x in {0,...,8} {
\foreach \y [evaluate=\y as \z using int(4-\y)] in {0,...,4} {
\pgfmathparse{\x<=\y ? "\noexpand\node at (\x cm,\y cm) (g-\x-\y) {$a_{\x,\z}$};" : " " }
\pgfmathresult
}
}
\end{tikzpicture}
\end{document}