带有数学符号的 Jordan 范式

带有数学符号的 Jordan 范式

我想要创建一个 Jordan 范式,如下所示:

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}

\begin{document}

\[
\newcommand{\?}[1]{\multicolumn{1}{c|}{#1}}
\left(\begin{array}{ccccccc}
2 & 1 & \?0 & 0 &   0 & 0 & 0 \\
0 & 2 & \?1 & 0 &   0 & 0 & 0 \\
0 & 0 & \?2 & 0 &   0 & 0 & 0 \\
\cline{1-5}
0 & 0 & \?0 & 2 & \?1 & 0 & 0 \\
0 & 0 & \?0 & 0 & \?2 & 0 & 0 \\
\cline{4-6}
0 & 0 &   0 & 0 & \?0 & \?3 & 0 \\
\cline{6-7}
0 & 0 &   0 & 0 &   0 & \?0 & 3
\end{array}\right)
\]

\end{document} 

但我想用 $\alpha$、$\beta$ 代替数字。但这行不通。我需要如何更改代码才能使用数学符号?

答案1

\alpha除了根据需要用、等替换数字之外\beta,您可能还想从使用array环境切换到pmatrix环境(由包提供amsmath)。

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath} % for 'pmatrix' env.
\usepackage{array}   % for '\extrarowheight' macro
\newcommand{\?}[1]{\multicolumn{1}{c|}{#1}}

\begin{document}
\[
\setlength\extrarowheight{1pt} % for a more open "look"
\begin{pmatrix}
\alpha & \beta & \?0 & 0 & 0 & 0 & 0 \\
0 & \gamma & \?{\delta} & 0 & 0 & 0 & 0 \\
0 & 0 & \?2 & 0 & 0 & 0 & 0 \\
\cline{1-5}
0 & 0 & \?0 & 2 & \?1 & 0 & 0 \\
0 & 0 & \?0 & 0 & \?2 & 0 & 0 \\
\cline{4-6}
0 & 0 & 0 & 0 & \?0 & \?3 & 0 \\
\cline{6-7}
0 & 0 & 0 & 0 & 0 & \?0 & \omega
\end{pmatrix}
\]
\end{document} 

答案2

从 Mico 的解决方案中,我又添加了 2 种使用 TikZ 库\matrix和 的方法\tikzmark。虽然它们不如 Mico 的轻量级,但它们具有高度可定制性。

在此处输入图片描述

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath} % for 'pmatrix' env.
\usepackage{array}   % for '\extrarowheight' macro
\newcommand{\?}[1]{\multicolumn{1}{c|}{#1}}
\usepackage{tikz}
\usetikzlibrary{matrix,tikzmark,backgrounds}
\begin{document}
This is Mico's solution.    
% https://tex.stackexchange.com/a/695396/140722
\begin{equation}J_1=
    \setlength\extrarowheight{1pt} % for a more open "look"
    \begin{pmatrix}
        \alpha & \beta & \?0 & 0 & 0 & 0 & 0 \\
        0 & \gamma & \?{\delta} & 0 & 0 & 0 & 0 \\
        0 & 0 & \?2 & 0 & 0 & 0 & 0 \\
        \cline{1-5}
        0 & 0 & \?0 & 2 & \?1 & 0 & 0 \\
        0 & 0 & \?0 & 0 & \?2 & 0 & 0 \\
        \cline{4-6}
        0 & 0 & 0 & 0 & \?0 & \?3 & 0 \\
        \cline{6-7}
        0 & 0 & 0 & 0 & 0 & \?0 & \omega\\
    \end{pmatrix}.
\end{equation}
This is a solution using the \verb|matrix| library of TikZ.
\begin{equation}
\begin{tikzpicture}[every left delimiter/.style={xshift=2mm},
    every right delimiter/.style={xshift=-2mm}]
\path (0,0) node (mat) [matrix,matrix of math nodes,left delimiter=(,right delimiter=),column sep=2mm,row sep=1mm]
{
|(A)|\alpha & \beta & 0 & 0 & 0 & 0 & 0 \\
0 &\gamma & \delta & 0 & 0 & 0 & 0 \\
0 & 0 & |(B)|2 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & |(C)|2 & 1 & 0 & 0 \\
0 & 0 & 0 & 0 & |(D)|2 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & |(E)|3 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & |[blue] (F)|\omega\\
};
\path 
(B)--(C) coordinate[midway] (P)
(D)--(E) coordinate[midway] (Q)
(E)--(F) coordinate[midway] (R)
;
\begin{scope}[on background layer]
\draw[fill=yellow!50] (P) rectangle (Q) rectangle (R);
\fill[green!20] (P) rectangle (A.north west);
\draw 
(P)--(P-|A.west) (P)--(P|-A.north)
(R)--(R-|F.east) (R)--(R|-F.south);
\end{scope}
\path (mat.west) node[left=2mm]{$J_2=$};
\end{tikzpicture}
\end{equation}
This is a solution using the \verb|tikzmark| library of TikZ.
\begin{equation}
J_3=
\setlength\extrarowheight{1pt} % for a more open "look"
\begin{pmatrix}
\tikzmarknode{A}{\alpha} & \beta & 0 & 0 & 0 & 0 & 0 \\
0 & \gamma & \delta & 0 & 0 & 0 & 0 \\
0 & 0 & \tikzmarknode{B}{2} & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & \tikzmarknode{C}{2} & 1 & 0 & 0 \\
0 & 0 & 0 & 0 & \tikzmarknode{D}{2} & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & \tikzmarknode{E}{3} & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & \tikzmarknode{F}{\omega}\\
\end{pmatrix}
\end{equation}
\begin{tikzpicture}[overlay,remember picture]
\path 
(B)--(C) coordinate[midway] (P)
(D)--(E) coordinate[midway] (Q)
(E)--(F) coordinate[midway] (R)
;
\begin{scope}[on background layer]
\draw (P) rectangle (Q) rectangle (R);
\draw 
(P)--(P-|A.west) (P)--(P|-A.north)
(R)--(R-|F.east) (R)--(R|-F.south);
\end{scope}
\end{tikzpicture}
\end{document} 

答案3

只需将数字替换为\alpha\beta,而不是$\alpha$$\beta$。在方程式或数组等环境中,您不需要$$

答案4

{pNiceMatrix}这是用构建该矩阵的一种方法nicematrix。您需要进行多次编译。

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

\begin{document}

\[
\begin{pNiceMatrix}[left-margin,right-margin=1pt,color-inside]
  \Block[fill=green!15,borders={bottom,right}]{3-3}{}
  \alpha & \beta & 0 & 0 & 0 & 0 & 0 \\
  0 & \gamma & \delta & 0 & 0 & 0 & 0 \\
  0 & 0 & 2 & 0 & 0 & 0 & 0 \\
  0 & 0 & 0 & \Block[fill=yellow!50,draw]{2-2}{}
              2 & 1 & 0 & 0 \\
  0 & 0 & 0 & 0 & 2 & 0 & 0 \\
  0 & 0 & 0 & 0 & 0 & \Block[fill=yellow!50,draw]{}{3} & 0 \\
  0 & 0 & 0 & 0 & 0 & 0 & \Block[borders={top,left}]{}{\omega}
\end{pNiceMatrix}
\]

\end{document}

第一个代码的输出

如果愿意,也可以将所有格式指令放在主数组之外(和中\CodeBefore\CodeAfter

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

\begin{document}

\[
\begin{pNiceMatrix}[left-margin,right-margin=1pt,color-inside]
\CodeBefore
  \rectanglecolor{green!15}{1-1}{3-3}
  \rectanglecolor{yellow!50}{4-4}{5-5}
  \cellcolor{yellow!50}{6-6}
\Body
  \alpha & \beta & 0 & 0 & 0 & 0 & 0 \\
  0 & \gamma & \delta & 0 & 0 & 0 & 0 \\
  0 & 0 & 2 & 0 & 0 & 0 & 0 \\
  0 & 0 & 0 & 2 & 1 & 0 & 0 \\
  0 & 0 & 0 & 0 & 2 & 0 & 0 \\
  0 & 0 & 0 & 0 & 0 & 0 & 0 \\
  0 & 0 & 0 & 0 & 0 & 0 & \omega \\
\CodeAfter
  \begin{tikzpicture}
  \draw (4-|1) -| (7-|6) -- (7-|8) ; 
  \draw (1-|4) |- (6-|7) -- (8-|7) ; 
  \end{tikzpicture}
\end{pNiceMatrix}
\]

\end{document}

第二段代码的输出

相关内容