Search code examples
matrixlatexcurly-bracestikz

How can I draw a curly brace under my matrix to describe my columns using Nicematrix and TikZ?


I want to draw 2 braces under my matrix to indicate that the vectors a are different from the vectors x and explain why. Nevertheless, my current attempt just draws the brace in the middle of my matrice... Does someones has an idea, please? I try to add a snippet here, my code is also here: https://www.overleaf.com/read/nnkpkdrwphmd

Thank you so much for your help!

\documentclass{article}
\usepackage{nicematrix}
\usepackage{tikz}
\usepackage[utf8]{inputenc}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usetikzlibrary{patterns}
\usetikzlibrary{matrix,decorations.pathreplacing}
\usetikzlibrary{decorations.pathreplacing,calligraphy}

\title{Fairness}
\author{someone}
\date{May 2021}

\begin{document}

\maketitle

\section{Introduction}

\NiceMatrixOptions{code-for-first-row = \color{red},
    code-for-first-col = \color{blue},
    code-for-last-row = \color{green},
    code-for-last-col = \color{magenta}}

$\begin{pNiceMatrix}%
[margin,
first-row,
first-col,
%code-for-first-row = \mathbf{\alph{jCol}} ,
%code-for-first-col = \mathbf{\arabic{iRow}} ,
nullify-dots,
xdots/line-style=loosely dotted,
code-after = {\begin{tikzpicture}[decoration={calligraphic brace, mirror, amplitude=6pt,raise=2pt}]
                \draw[decorate,thick] (0-1.south south) -- (1-3.south east);
                node[midway,under=1.5ex]{$\scriptstyle\mathcal{A}_N^i$};
                \end{tikzpicture}}
]
&        1             & 2           & \Cdots    & k         & k+1          & k+2          & \Cdots  & m          \\
1        & a_{(1,1)}   & a_{(1,2)}   & \Cdots    & a_{(1,k)} & x_{(1,k+1)}  & x_{(1,k+2)}  & \Cdots  & x_{(1,m)}  \\
2        & a_{(2,1)}   & a_{(2,2)}   & \Cdots    & a_{(2,k)} & x_{(2,k+1)}  & x_{(2,k+2)}  & \Cdots  & x_{(2,m)}  \\
3        & a_{(3,1)}   & a_{(3,2)}   & \Cdots    & a_{(3,k)} & x_{(3,k+1)}  & x_{(3,k+2)}  & \Cdots  & x_{(3,m)}  \\
\Vdots   & \Vdots      & \Ddots      & \Cdots    & \Vdots    & \Vdots       & \Ddots       & \Cdots  & \Vdots     \\
&        &             & \Cdots      &           &           &              & \Cdots       &         &            \\
n        & a_{(n,1)}   & a_{(n,2)}   & \Cdots    & a_{(n,k)} & x_{(n,k+1)}  & x_{(n,k+2)}  & \Cdots  & x_{(n,m)}
%\CodeAfter \SubMatrix{\{}{1-1}{3-1}{.}[left-xshift=0.5em]
\end{pNiceMatrix}$

\end{document}

Solution

    • you can't use keys like under without defining them

    • south south is not a valid anchor point

    • you can only use the coordinates of non-empty cells


    \documentclass{article}
    \usepackage{nicematrix}
    \usepackage{tikz}
    \usepackage[utf8]{inputenc}
    
    \usepackage{amsmath}
    \usepackage{amssymb}
    \usepackage{amsthm}
    \usetikzlibrary{patterns}
    \usetikzlibrary{matrix,decorations.pathreplacing}
    \usetikzlibrary{decorations.pathreplacing,calligraphy}
    
    \title{Fairness}
    \author{someone}
    \date{May 2021}
    
    \begin{document}
    
    \maketitle
    
    \section{Introduction}
    
    \NiceMatrixOptions{code-for-first-row = \color{red},
        code-for-first-col = \color{blue},
        code-for-last-row = \color{green},
        code-for-last-col = \color{magenta}}
    
    $\begin{pNiceMatrix}%
    [margin,
    name=mymatrix,
    first-row,
    first-col,
    %code-for-first-row = \mathbf{\alph{jCol}} ,
    %code-for-first-col = \mathbf{\arabic{iRow}} ,
    nullify-dots,
    xdots/line-style=loosely dotted,
    code-after = {\begin{tikzpicture}[decoration={calligraphic brace, mirror, amplitude=6pt,raise=2pt}]
                    \draw[decorate,thick] (mymatrix-6-1.south west) -- (mymatrix-6-4.south east) node[midway,yshift=-2em]{a};
                    \draw[decorate,thick] (mymatrix-6-5.south west) -- (mymatrix-6-8.south east) node[midway,yshift=-2em]{x};
                    \end{tikzpicture}}
    ]
    &        1             & 2           & \Cdots    & k         & k+1          & k+2          & \Cdots  & m          \\
    1        & a_{(1,1)}   & a_{(1,2)}   & \Cdots    & a_{(1,k)} & x_{(1,k+1)}  & x_{(1,k+2)}  & \Cdots  & x_{(1,m)}  \\
    2        & a_{(2,1)}   & a_{(2,2)}   & \Cdots    & a_{(2,k)} & x_{(2,k+1)}  & x_{(2,k+2)}  & \Cdots  & x_{(2,m)}  \\
    3        & a_{(3,1)}   & a_{(3,2)}   & \Cdots    & a_{(3,k)} & x_{(3,k+1)}  & x_{(3,k+2)}  & \Cdots  & x_{(3,m)}  \\
    \Vdots   & \Vdots      & \Ddots      & \Cdots    & \Vdots    & \Vdots       & \Ddots       & \Cdots  & \Vdots     \\
    &        &             & \Cdots      &           &           &              & \Cdots       &         &            \\
    n        & a_{(n,1)}   & a_{(n,2)}   & \Cdots    & a_{(n,k)} & x_{(n,k+1)}  & x_{(n,k+2)}  & \Cdots  & x_{(n,m)}
    %\CodeAfter \SubMatrix{\{}{1-1}{3-1}{.}[left-xshift=0.5em]
    \end{pNiceMatrix}$
    
    \end{document}
    

    enter image description here