我使用 生成了以下圖像nicematrix
。
一切正常;所以目前沒有什麼緊急的問題。
筆記:結果或光學效果完全符合預期。在下文中,我只關心程式碼的一些微妙之處,以優化使用 Nicematrix-package。
然而,出於個人興趣,我會對兩件事感興趣:
"A1 A2 ... A4"
應整體垂直居中。
我這裡的使用 還好嗎? 或者說我應該做得更好?
\Block{2-1}{A1} & \Block{2-1}{A2} & \Block{2-1}{\cdots} & \Block{2-1}{A4} ... \\
nicematrix.sty
我在上面和下面
"A1 A2 ... A4"
添加了垂直線,每條垂直線都位於矩陣的兩端。
為了下線我必須進行視覺調整:
\draw[
shorten <=1em+2pt
] (2-\col) -- (last-|\col.5);
這意味著如果內容發生變化,可能需要再次調整。
這可以變得更加穩定/靈活嗎?
代碼:
\documentclass{article}
\usepackage{amsmath}
\usepackage{nicematrix}
\usepackage{tikz}
\begin{document}
$M=\begin{NiceArray}{(c c c c) c (c c c c)}
& & & & \Block{*-1}{\cdot} & B1 & & & \\
\Block{2-1}{A1} & \Block{2-1}{A2} & \Block{2-1}{\cdots} & \Block{2-1}{A4}
& & & B2 & & \\
& & & & & & & \ddots & \\
& & & & & & & & B4
\CodeAfter
\begin{tikzpicture}[]
% Verticals =====================
\foreach \col in {1,2,4}{%%
\draw[shorten <=0pt] (2-\col) -- (1-|\col.5) ;
\draw[shorten <=1em+2pt] (2-\col) -- (last-|\col.5) ;
}%%
\end{tikzpicture}
% Underbracing =================
\UnderBrace[yshift=2pt]{4-6}{4-9}{=X}
\end{NiceArray}$
\end{document}
答案1
要獲得所需的基線,可以baseline=<row number>
使用NiceArray
.但這要求A1
位於其自己的行中,而不是位於一個區塊中。一種可能性是使數組具有 5 行和 10 列。然後在「第二個」陣列中使用 2 x 2 Block
for \ddots
。
其他變化:
\,
在列的右側和左側放置一個細空格 ( )\cdot
,以便間距與使用兩個單獨的陣列時相同。- 建立一個新樣式(
myline
在下面的程式碼中)以縮短垂直線。由於A1
、A2
等位於各自的單元格中,因此間距是均勻的。
這是代碼:
\documentclass{article}
\usepackage{amsmath}
\usepackage{nicematrix}
\usepackage{tikz}
\tikzset{myline/.style={shorten <=3pt}}
\begin{document}
$M=\begin{NiceArray}{(cccc)!\,c!\,(ccccc)}[baseline=3]
& & & & \Block{*-1}{\cdot} & B1\\
& & & & & & B2 \\
A1 & A2 & \cdots & A4 & & & & \Block{2-2}{\ddots} \\
\\
& & & & & & & & & B4
\CodeAfter
\begin{tikzpicture}[]
% Verticals =====================
\foreach \col in {1,2,4}{%%
\draw[myline] (3-\col) -- (1-|\col.5) ;
\draw[myline] (3-\col) -- (last-|\col.5) ;
}%%
\end{tikzpicture}
% Underbracing =================
\UnderBrace[yshift=2pt]{5-6}{5-10}{=X}
\end{NiceArray}$
\end{document}
答案2
如果您希望這些行保留在下面"A1 A2 ... A4"
,那麼您需要使用\tikzmarknode
fromtikzmark
庫
\documentclass{article}
\usepackage[x11names]{xcolor}
\usepackage{amsmath}
\usepackage{nicematrix}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{tikzmark}
\begin{document}
\begin{equation*}
\setlength{\arraycolsep}{1em}
\smash{\rlap{\rule{11cm}{0.1pt}}}
M
=
\begin{NiceArray}{(c c c c) c (c c c c)}
\CodeBefore [create-cell-nodes]
\Body
& & & & \Block{*-1}{\cdot} & B1 & & & \\
\Block{2-1}{\tikzmarknode{A1}{A1}} & \Block{2-1}{\tikzmarknode{A2}{A2}} & \Block{2-1}{\cdots} & \Block{2-1}{\tikzmarknode{A4}{A4}}
& & & B2 & & \\
& & & & & & & \ddots & \\
& & & & & & & & B4
\CodeAfter
\begin{tikzpicture}[]
% Verticals =====================
\draw[shorten <=1pt] (A1.north) -- (1-|1.5);
\draw[shorten <=1pt] (A2.north) -- (1-|2.5);
\draw[shorten <=1pt] (A4.north) -- (1-|4.5);
\draw[shorten >=1pt] (last-|1.5) -- (A1.south);
\draw[shorten >=1pt] (last-|2.5) -- (A2.south);
\draw[shorten >=1pt] (last-|4.5) -- (A4.south);
\end{tikzpicture}
% Underbracing =================
\UnderBrace[yshift=2pt]{4-6}{4-9}{=X}
\end{NiceArray}
\end{equation*}
\end{document}