
我想添加/繪製線條(如圖所示的紅色線條)和在字母 A、B 和 D 下(不在 處\cdots
)-分別到矩陣的上端與下端。
Nicematrix 的正確方法是什麼?
· 在「空單元格」處繪圖時似乎有問題。 Nicematrix 是否知道像 TikZ-matrix 那樣的金鑰nodes into empty cells
?
·我可以使用 foreach 迴圈優雅地完成該任務嗎?
\documentclass{article}
\usepackage{amsmath}
\usepackage{nicematrix}
\usepackage{tikz}
\begin{document}
$\begin{NiceArray}{(c c c c) }
& & & \\
A & B & \cdots & D \\
& & & \\
\CodeAfter
\begin{tikzpicture}[]
%\draw[red] (2-1) -- (1-1); % does not work-->' No shape named `1-1' is known.'
\draw[red] (2-1) -- (1.5|-1); % work
\end{tikzpicture}
\end{NiceArray}$
\end{document}
答案1
你的 Tikz 指令\draw (2-1) -- (1-|1.5) ;
看起來不錯(如果我真的理解你想畫什麼...)。
對於循環,可以(例如)使用foreach
循環(由 提供,pgffor
由 加載pgf
,本身由 加載nicematrix
)。
這是一個例子:
\documentclass{article}
\usepackage{nicematrix}
\usepackage{tikz}
\begin{document}
$\begin{NiceArray}{(c c c c)}
\NotEmpty & & & \\
A & B & \cdots & D \\
& & & \\
\CodeAfter
\begin{tikzpicture} [red]
\foreach \i in {1,...,\value{jCol}}
{
\draw (2-\i) -- (1-|\i.5) ;
\draw (2-\i) -- (last-|\i.5) ;
} ;
\end{tikzpicture}
\end{NiceArray}$
\end{document}
在\CodeAfter
LaTeX 計數器中jCol
包含陣列的總列數(而在陣列主體中,它包含目前列的編號)。
您在問題中說您不希望有任何高於和低於 的規則\cdots
。當然,前面的程式碼不會自動檢測\cdots
單元格中的命令...您是否真的想要一個能夠自動檢測潛在命令位置的程式碼\cdots
(可以編寫具有此類功能的程式碼,但這並不簡單)?