TikZ 仅脚本化上三角元素

TikZ 仅脚本化上三角元素

我想按照下面的代码片段做一些事情,但是却收到很多错误:

\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}

在此处输入图片描述

相关内容