![從 arrayjobx 陣列中取得 tikz 節點名稱](https://rvso.com/image/475716/%E5%BE%9E%20arrayjobx%20%E9%99%A3%E5%88%97%E4%B8%AD%E5%8F%96%E5%BE%97%20tikz%20%E7%AF%80%E9%BB%9E%E5%90%8D%E7%A8%B1.png)
我正在嘗試創建一個命令,用於排版具有兩個玩家的正常形式遊戲,並為每個玩家提供一組可變的操作。到目前為止,我有以下程式碼:
\documentclass{article}
\usepackage{tikz}
\usepackage{arrayjobx}
\newcommand \Length [1] {%
\csname total@#1\endcsname
}
\newcommand{\nfgrid}[2]{
\newarray\row
\readarray{row}{#1}
\newarray\col
\readarray{col}{#2}
\draw[-,very thick] (0,0) to (2*\Length{col},0);
\foreach \i in {1,2,...,\Length{row}}{
\draw[-,very thick] (0,2*\i) to (2*\Length{col},2*\i);
\node (A) at (-1,2*\i-1) {\row(\the\numexpr\Length{row}-\i+1\relax)};
}
\draw[-,very thick] (0,0) to (0,2*\Length{row});
\foreach \i in {1,2,...,\Length{col}}{
\draw[-,very thick] (2*\i,0) to (2*\i,2*\Length{row});
\node (A) at (2*\i-1,2*\Length{row}+1) {\col(\the\numexpr\i\relax)};
}
\foreach \i in {1,2,...,\Length{row}}{
\foreach \j in {1,2,...,\Length{col}}{
\node (A) at (2*\j-1.5,2*\i-1.5) {R\row(\the\numexpr\Length{row}-\i+1\relax)\col(\the\numexpr \j\relax)};
\node (A) at (2*\j-0.5,2*\i-0.5) {C\row(\the\numexpr\Length{row}-\i+1\relax)\col(\the\numexpr \j\relax)};
\draw[-,very thin] (2*\j,2*\i-2) to (2*\j-2,2*\i);
}
}
}
\begin{document}
\begin{tikzpicture}
\nfgrid{A&B&C}{W&X&Y&Z}
\end{tikzpicture}
\end{document}
我想創建一個不同的命令來設定收益,這意味著當前標記為 RAW、CAW 的節點的標籤……為此,我希望這些節點的名稱與我目前設定為標籤的字串相同;本質上我希望在第 22-23 行中使用這段程式碼(這不起作用):
\node (R\row(\the\numexpr#1-\i+1\relax)\col(\the\numexpr \j\relax)) at (2*\j-1.5,2*\i-1.5) {};
\node (C\row(\the\numexpr#1-\i+1\relax)\col(\the\numexpr \j\relax)) at (2*\j-0.5,2*\i-0.5) {};
但是,我嘗試過的任何方法都不允許我使用 arrayjobx 數組值作為 tikz 節點的名稱。有什麼解決方法嗎?我願意使用與 arrayjobx 不同的包,只要它允許我輕鬆地從命令輸入中讀取行/列名稱數組。
答案1
(R\row(\the\numexpr#1-\i+1\relax)\col(\the\numexpr \j\relax))
名稱的建議代碼\node
不起作用,因為\row(1)
不可擴展,如下所示。
\documentclass[border=6pt]{standalone}
\usepackage{arrayjobx}
\begin{document}
\newarray\row
\readarray{row}{a&b&c}
\def\testA{\row(1)}%\def works but \edef does not work
\testA
\end{document}
下面的程式碼使用expl3
而不是arrayjobx
.
該框架是用單一grid
.
該命令\seq_map_indexed_inline:Nn
用於循環序列並追蹤索引。
\documentclass[border=6pt]{standalone}
\usepackage{tikz}
\ExplSyntaxOn
\seq_new:N \l__Chip_row_seq
\seq_new:N \l__Chip_column_seq
\NewDocumentCommand \nfgrid { m m }
{
\seq_set_from_clist:Nn \l__Chip_row_seq {#1}
\seq_set_from_clist:Nn \l__Chip_column_seq {#2}
\draw [ very~thick , step = 2 ] ( 0 , 0 ) grid ( 2 * \seq_count:N \l__Chip_column_seq , 2 * \seq_count:N \l__Chip_row_seq ) ;
\seq_map_indexed_inline:Nn \l__Chip_row_seq
{
\node (##2) at ( -1 , { 2 * ( \seq_count:N \l__Chip_row_seq - ##1 ) + 1 } ) {##2};
}
\seq_map_indexed_inline:Nn \l__Chip_column_seq
{
\node (##2) at ( 2 * ##1 - 1 , 2 * \seq_count:N \l__Chip_row_seq + 1 ) {##2};
}
\seq_map_indexed_inline:Nn \l__Chip_row_seq
{
\seq_map_indexed_inline:Nn \l__Chip_column_seq
{
\node ( R ##2 ####2 ) at ( 2 * ####1 - 1.5 , { 2 * ( \seq_count:N \l__Chip_row_seq - ##1 ) + 0.5 } ) { R ##2 ####2 };
\node ( C ##2 ####2 ) at ( 2 * ####1 - 0.5 , { 2 * ( \seq_count:N \l__Chip_row_seq - ##1 ) + 1.5 } ) { C ##2 ####2 };
\draw [ very~thin ] ( 2 * ####1 - 2 , 2 * ##1 ) -- ++ ( 2 , -2 ) ;
}
}
}
\ExplSyntaxOff
\begin{document}
\begin{tikzpicture}
\nfgrid{A,B,C}{W,X,Y,Z}
\end{tikzpicture}
\end{document}