将方程的左侧相对于“nicematrix”数组向上或向下移动

将方程的左侧相对于“nicematrix”数组向上或向下移动

我使用奇妙的nicematrix包裹。但是,由于主矩阵下方和右侧的注释框在技术上都是一个大矩阵的一部分niceArray,因此将\hat{A} = \begin{NiceArray} ...矩阵符号和等号的位置放得太低了。

我如何手动移动/对齐等号和等式的左侧向上/向下以完美对齐submatrix

在此处输入图片描述

梅威瑟:

% document class
\documentclass[preview]{standalone}
% formatting
\usepackage[utf8]{inputenc}
% fonts
\usepackage{amsfonts}
% matrices
\usepackage{nicematrix}
% drawing
\usepackage{tikz}
\usetikzlibrary{fit}


\tikzset{highlight/.style={rectangle,
                           fill=red!15,
                           rounded corners = 0.5 mm,
                           inner sep=1pt,
                           fit=#1}}

\begin{document}

% *{6}{c} defines centered text alignment for 6 consecutive columns
% https://en.wikibooks.org/wiki/LaTeX/Tables#Defining_multiple_columns

% @{\hspace{6mm}} replaces the default inter-columns spacing with 6mm of spacing
% https://en.wikibooks.org/wiki/LaTeX/Tables#@_and_!_expressions

% ascenders/descenders ('f' or 'y' for instance) cause \rotate to misalign rows. Use '\strut' to prevent this
% https://tex.stackexchange.com/a/638990/

\[
\setlength{\arraycolsep}{1.5pt} % set column width, compare https://tex.stackexchange.com/a/609405/
\hat{A} = \begin{NiceArray}{ *{8}{c} @{\hspace{2mm}} *{3}{c}} % two empty columns hugging an \hspace to ensure enough space between matrix and right annotations
    \CodeBefore [create-cell-nodes]
        \begin{tikzpicture}
            \node [highlight = (1-1) (4-4)] { } ;
            %\node [highlight = (5-5) (5-5)] { } ;
            \node [highlight = (7-7) (7-7)] { } ;
        \end{tikzpicture}
    \Body
    % 1
        3
        &
        2
        &  
        \Cdots
        & 
        5
        & 
        7
        &
        \Cdots
        &
        8
        &
        % empty column
        &
        % empty column
        &
        \Block[borders={bottom,top,right,left,tikz=solid}]{1-1}{} \text{sector 1}
        &
        \Block[borders={bottom,top,right,left,tikz=solid}]{4-1}{} \text{country 1}
    % 2
    \\
        1
        &
        2
        &
        \Cdots
        &
        3
        &
        1
        &
        \Cdots
        &
        9
        &
        % empty column
        &
        % empty column
        &
        \Block[borders={bottom,top,right,left,tikz=solid}]{1-1}{} \text{sector 2} & \text{country 1}
    % 3
    \\
        \Vdots
        &
        \Vdots
        &
        \Ddots
        &
        \Vdots
        &
        \Vdots
        &
        \Ddots
        &
        \Vdots
        &
        % empty column
        &
        % empty column
        &
        \Block[borders={bottom,top,right,left,tikz=solid}]{1-1}{} \vdots
        &
        \Vdots
    % 4
    \\
        9
        &
        4
        &
        \Cdots
        &
        1
        &
        2
        &
        \Cdots
        &
        3
        &
        % empty column
        &
        % empty column
        &
        \Block[borders={bottom,top,right,left,tikz=solid}]{1-1}{} \text{sector n} & \text{country 1}
    % 5
    \\
        6
        &
        2
        &
        \Cdots
        &
        2
        &
        7
        &
        \Cdots
        &
        1
        &
        % empty column
        &
        % empty column
        &
        \Block[borders={top,right,left,tikz=solid}]{1-1}{} \text{sector 1} 
        & 
        \Block[borders={top,right,left,tikz=solid}]{1-1}{} \text{country 2}
    % 6
    \\
        \Vdots
        &
        \Vdots
        &
        \Ddots
        &
        \Vdots
        &
        \Vdots
        &
        \Ddots
        &
        \Vdots
        &
        
        &
        
        &
        \Block[borders={left,right,tikz=dashed}]{1-1}{} \vdots
        &
        \Block[borders={left,right,tikz=dashed}]{1-1}{} \Vdots
    % 7    
    \\
        3
        &
        2
        &
        \Cdots
        &
        1
        &
        5
        &
        \Cdots
        &
        3
        &
        &
        &
        \Block[borders={bottom,right,left,tikz=solid}]{1-1}{} \text{sector n}
        &
        \Block[borders={bottom,right,left,tikz=solid}]{1-1}{} \text{country m}
    % empty line and lower end of matrix
    \\[-8pt]
        &&&&&&&&&&
    % 8
    \\
        \RowStyle[cell-space-limits = 1pt, nb-rows = 2]{\rotate}
        \Block[borders={bottom,top,right,left,tikz=solid}]{1-1}{} \text{sector 1 \strut}
        &
        \Block[borders={bottom,top,right,left,tikz=solid}]{1-1}{} \text{sector 2 \strut}
        &
        \Block[borders={bottom,top,right,left,tikz=solid}]{1-1}{} \vdots
        &
        \Block[borders={bottom,top,right,left,tikz=solid}]{1-1}{} \text{sector n \strut}
        &
        \Block[borders={bottom,top,left,tikz=solid}]{1-1}{} \text{sector 1 \strut}
        &
        \Block[borders={bottom,top,tikz=dashed}]{1-1}{} \vdots
        &
        \Block[borders={bottom,top,right,tikz=solid}]{1-1}{} \text{sector n \strut}
        &
        
        &
        
        &
        
        &

    % 9
    \\
        \Block[borders={bottom,top,right,left,tikz=solid}]{1-4}{} \text{country 1}
        &
        \text{country 1}
        &
        \Cdots
        &
        \text{country 1}
        &
        \Block[borders={bottom,top,left,tikz=solid}]{1-1}{} \text{country 2}
        &
        \Block[borders={bottom,top,tikz=dashed}]{1-1}{} \Cdots
        &
        \Block[borders={bottom,top,right,tikz=solid}]{1-1}{} \text{country m}
        &
        
        &
        
        &
        
        &
    % end of matrix
    \\
    \CodeAfter
        \SubMatrix[{1-1}{7-7}]
    \end{NiceArray}
\]
\end{document}

答案1

添加[baseline=4]一些水平空间以补偿括号。无论如何,这是一段有趣的代码。

% document class
\documentclass{article}
% fonts
\usepackage{amsfonts}
% matrices
\usepackage{nicematrix}
% drawing
\usepackage{tikz}
\usetikzlibrary{fit}


\tikzset{highlight/.style={rectangle,
   fill=red!15,
   rounded corners = 0.5 mm,
   inner sep=1pt,
   fit=#1}}

\begin{document}

% *{6}{c} defines centered text alignment for 6 consecutive columns
% https://en.wikibooks.org/wiki/LaTeX/Tables#Defining_multiple_columns

% @{\hspace{6mm}} replaces the default inter-columns spacing with 6mm of spacing
% https://en.wikibooks.org/wiki/LaTeX/Tables#@_and_!_expressions

% ascenders/descenders ('f' or 'y' for instance) cause \rotate to misalign rows. Use '\strut' to prevent this
% https://tex.stackexchange.com/a/638990/

\[
\setlength{\arraycolsep}{1.5pt} % set column width, compare https://tex.stackexchange.com/a/609405/
\hat{A} = \;\;
\begin{NiceArray}[baseline=4]{ *{8}{c} @{\hspace{2mm}} *{3}{c}}
  \CodeBefore [create-cell-nodes]
    \begin{tikzpicture}
    \node [highlight = (1-1) (4-4)] { } ;
    %\node [highlight = (5-5) (5-5)] { } ;
    \node [highlight = (7-7) (7-7)] { } ;
    \end{tikzpicture}
  \Body
  % 1
  3 & 2 & \Cdots & 5 & 7 & \Cdots & 8 & & &
    \Block[borders={bottom,top,right,left,tikz=solid}]{1-1}{} \text{sector 1} &
    \Block[borders={bottom,top,right,left,tikz=solid}]{4-1}{} \text{country 1}
  \\
  % 2
  1 & 2 & \Cdots & 3 & 1 & \Cdots & 9 & & &
    \Block[borders={bottom,top,right,left,tikz=solid}]{1-1}{} \text{sector 2} & \text{country 1}
  \\
  % 3
  \Vdots & \Vdots & \Ddots & \Vdots & \Vdots & \Ddots & \Vdots & & &
    \Block[borders={bottom,top,right,left,tikz=solid}]{1-1}{} \vdots & \Vdots
  \\
  % 4
  9 & 4 & \Cdots & 1 & 2 & \Cdots & 3 & & &
    \Block[borders={bottom,top,right,left,tikz=solid}]{1-1}{} \text{sector n} & \text{country 1}
    \\
  % 5
  6 & 2 & \Cdots & 2 & 7 & \Cdots & 1 & & &
    \Block[borders={top,right,left,tikz=solid}]{1-1}{} \text{sector 1} & 
    \Block[borders={top,right,left,tikz=solid}]{1-1}{} \text{country 2}
  \\
  % 6
  \Vdots & \Vdots & \Ddots & \Vdots & \Vdots & \Ddots & \Vdots & & &
    \Block[borders={left,right,tikz=dashed}]{1-1}{} \vdots &
    \Block[borders={left,right,tikz=dashed}]{1-1}{} \Vdots
  \\
  % 7    
  3 & 2 & \Cdots & 1 & 5 & \Cdots & 3 & & &
    \Block[borders={bottom,right,left,tikz=solid}]{1-1}{} \text{sector n} &
    \Block[borders={bottom,right,left,tikz=solid}]{1-1}{} \text{country m}
  % empty line and lower end of matrix
  \\[-8pt]
  &&&&&&&&&&
  \\
  % 8
  \RowStyle[cell-space-limits = 1pt, nb-rows = 2]{\rotate}
  \Block[borders={bottom,top,right,left,tikz=solid}]{1-1}{} \text{sector 1 \strut} &
  \Block[borders={bottom,top,right,left,tikz=solid}]{1-1}{} \text{sector 2 \strut} &
  \Block[borders={bottom,top,right,left,tikz=solid}]{1-1}{} \vdots &
  \Block[borders={bottom,top,right,left,tikz=solid}]{1-1}{} \text{sector n \strut} &
  \Block[borders={bottom,top,left,tikz=solid}]{1-1}{} \text{sector 1 \strut} &
  \Block[borders={bottom,top,tikz=dashed}]{1-1}{} \vdots &
  \Block[borders={bottom,top,right,tikz=solid}]{1-1}{} \text{sector n \strut} &
  & & &
  \\
  % 9
  \Block[borders={bottom,top,right,left,tikz=solid}]{1-4}{} \text{country 1} &
  \text{country 1} & \Cdots & \text{country 1} &
  \Block[borders={bottom,top,left,tikz=solid}]{1-1}{} \text{country 2} &
  \Block[borders={bottom,top,tikz=dashed}]{1-1}{} \Cdots &
  \Block[borders={bottom,top,right,tikz=solid}]{1-1}{} \text{country m} & & & &
  \\
  % end of matrix
  \CodeAfter\SubMatrix[{1-1}{7-7}]
  \end{NiceArray}
\]

\end{document}

在此处输入图片描述

相关内容