![TikZ 仅脚本化上三角元素](https://linux22.com/image/254187/TikZ%20%E4%BB%85%E8%84%9A%E6%9C%AC%E5%8C%96%E4%B8%8A%E4%B8%89%E8%A7%92%E5%85%83%E7%B4%A0.png)
我想按照下面的代码片段做一些事情,但是却收到很多错误:
\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}