矩阵内的框

矩阵内的框

我正在尝试做这样的事情:

在此处输入图片描述

该矩阵由以下代码生成:

    \begin{equation}
    \begingroup % keep the change local
    \setlength\arraycolsep{2pt}
        \begin{pmatrix}
             h_{11}&h_{12}&h_{13}&h_{14}&\cdots&h_{1n}&\cdots&\cdots&h_{1m}\\
             h_{21}&h_{22}&h_{23}&h_{24}&\cdots&h_{2n}&\cdots&\cdots&h_{2m}\\
             0 & h_{32} &h_{33}&h_{34}&\cdots&h_{3n}&\cdots&\cdots&h_{3m}\\
             0 & 0 & h_{43}&h_{44}&\cdots&h_{4n}&\cdots&\cdots&h_{4m}\\
             \vdots & \vdots & & \ddots & \ddots & \vdots & & & \vdots \\
             0 & 0 & & & \ddots & h_{n,n}& & & h_{nm} \\
             0 & 0 & & & & h_{n+1,n}& & & h_{n+1,m} \\
             \vdots & \vdots & & & & & \ddots & \ddots & \vdots \\
             0 & 0 & \cdots & & \cdots & \cdots & 0 & h_{m,m-1} & h_{m,m} \\
        \end{pmatrix}
    \endgroup
    \end{equation}

有什么建议吗?

提前致谢。

答案1

您可以使用tikzmark

\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}
\begin{equation}
    \begingroup % keep the change local
    \setlength\arraycolsep{2pt}
        \begin{pmatrix}
            \tikzmarknode{x}{h_{11}}&h_{12}&h_{13}&h_{14}&\cdots&h_{1n}&\cdots&\cdots&h_{1m}\\
            h_{21}&h_{22}&h_{23}&h_{24}&\cdots&h_{2n}&\cdots&\cdots&h_{2m}\\
            0 & h_{32} &h_{33}&h_{34}&\cdots&h_{3n}&\cdots&\cdots&h_{3m}\\
            0 & 0 & h_{43}&h_{44}&\cdots&h_{4n}&\cdots&\cdots&h_{4m}\\
            \vdots & \vdots & & \ddots & \ddots & \vdots & & & \vdots \\
            0 & 0 & & & \ddots & h_{n,n}& & & h_{nm} \\
            0 & 0 & & & & \tikzmarknode{y}{h_{n+1,n}}& & & h_{n+1,m} \\
            \vdots & \vdots & & & & & \ddots & \ddots & \vdots \\
            0 & 0 & \cdots & & \cdots & \cdots & 0 & h_{m,m-1} & h_{m,m} \\
        \end{pmatrix}
    \endgroup
\end{equation}
\tikz[remember picture,overlay] \draw (x.north west) rectangle (y.south east);
\end{document}

在此处输入图片描述

如果你想要更好的间距,

\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}
\begin{equation}
    \begingroup % keep the change local
    \setlength\arraycolsep{2pt}
        \begin{pmatrix}
            \tikzmarknode[inner sep=.3em]{x}{h_{11}}&h_{12}&h_{13}&h_{14}&\cdots&h_{1n}&\cdots&\cdots&h_{1m}\\
            h_{21}&h_{22}&h_{23}&h_{24}&\cdots&h_{2n}&\cdots&\cdots&h_{2m}\\
            0 & h_{32} &h_{33}&h_{34}&\cdots&h_{3n}&\cdots&\cdots&h_{3m}\\
            0 & 0 & h_{43}&h_{44}&\cdots&h_{4n}&\cdots&\cdots&h_{4m}\\
            \vdots & \vdots & & \ddots & \ddots & \vdots & & & \vdots \\
            0 & 0 & & & \ddots & h_{n,n}& & & h_{nm} \\
            0 & 0 & & & & \tikzmarknode[inner sep=.3em]{y}{h_{n+1,n}}& & & h_{n+1,m} \\
            \vdots & \vdots & & & & & \ddots & \ddots & \vdots \\
            0 & 0 & \cdots & & \cdots & \cdots & 0 & h_{m,m-1} & h_{m,m} \\
        \end{pmatrix}
    \endgroup
\end{equation}
\tikz[remember picture,overlay] \draw[red] (x.north west) rectangle (y.south east);
\end{document}

在此处输入图片描述

答案2

您可以使用nicematrix

\documentclass{article}
\usepackage{amsmath}
\usepackage{nicematrix}
\NiceMatrixOptions{exterior-arraycolsep}
\begin{document}

\begin{equation}
    \begingroup % keep the change local
    \setlength\arraycolsep{2pt}
        \begin{pNiceMatrix}[name=A,]
             h_{11}&h_{12}&h_{13}&h_{14}&\Cdots&h_{1n}&\Cdots&&h_{1m}\\
             h_{21}&h_{22}&h_{23}&h_{24}&\Cdots&h_{2n}&\Cdots&&h_{2m}\\
             0 & h_{32} &h_{33}&h_{34}&\Cdots&h_{3n}&\Cdots&&h_{3m}\\
             0 & 0 & h_{43}&h_{44}&\Cdots&h_{4n}&\Cdots&&h_{4m}\\
             \Vdots & \Vdots & & \Ddots & \Ddots & \Vdots & & & \Vdots \\
             0 & 0 & & & & h_{n,n}& \Cdots& & h_{nm} \\
             0 & 0 & & & & h_{n+1,n}& & & h_{n+1,m} \\
             \Vdots & \Vdots & & & & & \Ddots &  & \Vdots \\
             0 & 0 & \Cdots & &  &  & 0 & h_{m,m-1} & h_{m,m} \\
        \end{pNiceMatrix}
        \begin{tikzpicture}[overlay,remember picture]
        \node [red,draw,fit=(A-1-1)(A-6-6),inner sep=1.5pt]{};
        \end{tikzpicture}
    \endgroup
    \end{equation}
\end{document}

在此处输入图片描述

答案3

解决方案是pstricks。我使用 进行了一些间距改进cellspace

    \documentclass[svgnames]{article}
    \usepackage{mathtools}
    \usepackage{pst-node}
    \usepackage[math]{cellspace}
    \setlength{\cellspacetoplimit}{3pt}
    \setlength{\cellspacebottomlimit}{3pt}
    \usepackage{auto-pst-pdf}

    \begin{document}

    \begin{equation}
     \begin{pmatrix}
     \:\pnode[-2pt,2.5ex]{A} h_{11} &h_{12}&h_{13}&h_{14}&\cdots&h_{1n}&\cdots&\cdots&h_{1m}\\
    \: h_{21}&h_{22}&h_{23}&h_{24}&\cdots&h_{2n}&\cdots&\cdots&h_{2m}\\
     0 & h_{32} &h_{33}&h_{34}&\cdots&h_{3n}&\cdots&\cdots&h_{3m}\\
     0 & 0 & h_{43}&h_{44}&\cdots&h_{4n}&\cdots&\cdots&h_{4m}\\
     \vdots & \vdots & & \ddots & \ddots & \vdots & & & \vdots \\
     0 & 0 & & & \ddots & h_{n,n}& & & h_{nm} \\
     0 & 0 & & & & h_{n+1,n}\pnode[0.5ex,-1.5ex]{B}& & & h_{n+1,m} \\
     \vdots & \vdots & & & & & \ddots & \ddots & \vdots \\
     0 & 0 & \cdots & & \cdots & \cdots & 0 & h_{m,m-1} & h_{m,m} \\
     \end{pmatrix}
     \psframe[linecolor=Crimson](A)(B)
    \end{equation}

    \end{document} 

在此处输入图片描述

相关内容