我无法访问数组元素:
\documentclass{article}
\usepackage{tikz,ifthen}
\usetikzlibrary{calc,patterns}
\def\PatternArray{%
horizontal lines,%
vertical lines,%
north east lines,%
north west lines,%
grid,%
crosshatch,%
dots,%
crosshatch dots,%
fivepointed stars,%
sixpointed stars,%
bricks,%
checkerboard}
\begin{document}
essai
\pgfmathparse{\PatternArray[0]}
\pgfmathresult
\end{document}
答案1
这有效
\documentclass{article}
\usepackage{tikz,ifthen}
\usetikzlibrary{calc,patterns}
\newcommand\PatternArray{{%
"horizontal lines",%
"vertical lines",%
"checkerboard"}}
\begin{document}
\pgfmathparse{\PatternArray[0]}
\pgfmathresult
\pgfmathparse{\PatternArray[2]}
\pgfmathresult
\end{document}
项目周围必须有一对额外的括号;非数字项目应该用双引号引起来。
也许你会喜欢这种不同的方法。索引从 1 开始,但你也可以使用负索引从末尾开始计数。输入更容易,因为前导和尾随空格已被删除。
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\definearray}{mm}
{
\clist_gclear_new:c { g_tarass_array_#1_clist }
\clist_gset:cn { g_tarass_array_#1_clist } { #2 }
}
\NewExpandableDocumentCommand{\getarrayitem}{mm}
{
\clist_item:cn { g_tarass_array_#1_clist } { #2 }
}
\NewExpandableDocumentCommand{\getarraylength}{m}
{
\clist_count:c { g_tarass_array_#1_clist }
}
\ExplSyntaxOff
\definearray{Pattern}{
horizontal lines,
vertical lines,
north east lines,
north west lines,
grid,
crosshatch,
dots,
crosshatch dots,
fivepointed stars,
sixpointed stars,
bricks,
checkerboard
}
\begin{document}
\getarraylength{Pattern}
\getarrayitem{Pattern}{1}
\getarrayitem{Pattern}{-2}
\end{document}