Nicematrix:在最後一列中新增 ttfamily

Nicematrix:在最後一列中新增 ttfamily

我怎樣才能nicematrix將最後一個註釋列放入\footnotsize\ttfamily為我服務?

注意:我通常在那裡使用符號+, -, ·和羅馬數字(I, II, III,...)。
所以沒有強制理由在這裡保留數學模式。

因此,可能的結果可能如下所示:

在此輸入影像描述

我的MWE:

在此輸入影像描述

\documentclass{article}
\usepackage{amsmath}
\usepackage{nicematrix} 
\usepackage{tikz} 
\begin{document}

$\begin{bNiceArray}{c c c   |   c}[
last-col,
%code-for-last-col = ???,
]
1 & -2 & 3 & 5 & \\
0 & 3 & 2 & 2 & II + 2\mathord{\cdot} I - III  \\
0 & 1 & 1 & 3 &
\end{bNiceArray}$
\end{document}

順便說一句:我想在這裡有\lgroup\rgroup括號(而不是大括號“[]”);我NiceArrayWithDelims從手冊中了解到;但這不喜歡我第一次嘗試其他東西。有沒有簡單的方法可以在這裡使用組括號?

答案1

更新

(v. 6.16)的最新版本提供了直接將分隔符號和(通過和)放入環境(例如 )的前導碼中的nicematrix功能。\lgroup\rgroup\left\lbroup\right\rgroup{NiceArray}

使用該新版本,您可以編寫:

\documentclass{article}
\usepackage{nicematrix} 
\usepackage{amsmath}

\begin{document}

\newcolumntype{L}{>{$\ttfamily\footnotesize}l<{$}}

$\begin{NiceArray}{\left\lgroup ccc|c\right\rgroup L}
1 & -2 & 3 & 5 & \\
0 & 3 & 2 & 2 & II + 2I - III  \\
0 & 1 & 1 & 3 & \\
0 & 1 & 1 & 5 &
\end{NiceArray}$

\end{document}

上述程式碼的輸出


nicematrix抱歉,目前版本的(6.15)無法做到這一點。

如果您願意,這裡有一個解決方法。我不使用金鑰last-col,但我在數組的前導碼中明確添加列,並將括號放置在前導碼中。

\documentclass{article}
\usepackage{nicematrix} 
\usepackage{amsmath}

\begin{document}

\newcolumntype{L}{>{$\ttfamily\footnotesize}l<{$}}

$\begin{NiceArray}{(ccc|c)L}
1 & -2 & 3 & 5 & \\
0 & 3 & 2 & 2 & II + 2I - III  \\
0 & 1 & 1 & 3 & \\
0 & 1 & 1 & 5 &
\end{NiceArray}$

\end{document}

第一個程式碼的輸出

不可能在序言中放入分隔符\lgroup\rgroup但這裡有一個技巧,可以在前面放入\{\}重新定義...

\documentclass{article}
\usepackage{nicematrix} 
\usepackage{amsmath}

\begin{document}

\newcolumntype{L}{>{$\ttfamily\footnotesize}l<{$}}

\NewDocumentEnvironment{MyNiceArray}{}
  {%
    \let \{ \lgroup 
    \let \} \rgroup
    \begin{NiceArray}%
  }
  {\end{NiceArray}}

$\begin{MyNiceArray}{\{ccc|c\}L}
1 & -2 & 3 & 5 & \\
0 & 3 & 2 & 2 & II + 2I - III  \\
0 & 1 & 1 & 3 & \\
0 & 1 & 1 & 5 &
\end{MyNiceArray}$

\end{document}

上述程式碼的輸出

答案2

像這樣的東西可能是解決方案,但由於節點的內容預設為數學模式,因此\ttfamily無法使用,您需要將註釋放在\texttt巨集中:

\documentclass{article}
\usepackage{nicematrix} 
\usepackage{tikz} 

\begin{document}

$\begin{NiceArrayWithDelims}{\lgroup}{\rgroup}{ c c c | c }[
    last-col,
    code-for-last-col={\footnotesize}
]
1 & -2 & 3 & 5 & \\
0 & 3 & 2 & 2 & \texttt{II + 2\cdot I - III} \\
0 & 1 & 1 & 3 &
\end{NiceArrayWithDelims}$

\end{document}

在此輸入影像描述

據我所知,nicematrix沒有提供某種方法來通過某些宏將最後一列中的內容括起來,您只能使用 來添加宏code-for-last-col,但這在這裡沒有多大幫助。另外,你不能反其道而行,只讓相關列在數學模式下排版,因為NiceArrayWithDelims環境需要完全處於數學模式。


如果您希望使分隔符號更大一點,您可以使用\SubMatrix提供選項的巢狀extra-height(例如,套件作者已提出此解決方案這裡):

\documentclass{article}
\usepackage{nicematrix} 
\usepackage{tikz} 

\NewDocumentEnvironment{ MybNiceArray } { } { 
    \NiceMatrixOptions{exterior-arraycolsep}
    \begin{NiceArray} 
} {
    \CodeAfter
        \SubMatrix\lgroup{1-1}{last-last}\rgroup[extra-height=1ex]
    \end{NiceArray}
}

\begin{document}

$\begin{MybNiceArray}{ c c c | c }[
    last-col,
    code-for-last-col={\footnotesize}
]
1 & -2 & 3 & 5 & \\
0 & 3 & 2 & 2 & \texttt{II + 2\cdot I - III} \\
0 & 1 & 1 & 3 &
\end{MybNiceArray}$

\end{document}

在此輸入影像描述

相關內容