3

I created this rather elaborate matrix using the fantastic nicematrix package. However, since the annotation boxes below and to the right of the main matrix are technically all part of one big niceArray, the \hat{A} = \begin{NiceArray} ... places the matrix symbol and the equality sign too low.

How can I manually move/align the equality sign and the lHS of the equation up/down to align perfectly with the submatrix?

enter image description here

MWE:

% 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}

Wasserwaage
  • 233
  • 3
  • 12

1 Answers1

2

Add [baseline=4] and some horizontal space in order to compensate for the bracket. Interesting piece of code, anyway.

% 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}

enter image description here

egreg
  • 1,121,712