【问题标题】:How can I draw a curly brace under my matrix to describe my columns using Nicematrix and TikZ?如何使用 Nicematrix 和 TikZ 在我的矩阵下绘制一个花括号来描述我的列?
【发布时间】:2023-08-09 20:13:01
【问题描述】:

我想在我的矩阵下画两个大括号来表示向量 a 与向量 x 不同并解释原因。尽管如此,我目前的尝试只是在我的矩阵中间画了一个大括号......有人有想法吗? 我尝试在这里添加一个sn-p,我的代码也在这里:https://www.overleaf.com/read/nnkpkdrwphmd

非常感谢您的帮助!

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

【问题讨论】:

    标签: matrix latex curly-braces tikz


    【解决方案1】:
    • 你不能在没有定义的情况下使用像under 这样的键

    • south south 不是有效的锚点

    • 只能使用非空单元格的坐标


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

    【讨论】:

      【解决方案2】:

      nicematrix (2021-11-23) 6.4 版提供了\CodeAfter 中可用的命令\UnderBrace\OverBrace 来绘制水平大括号。大括号是 LaTeX 数学模式的标准大括号(而不是 Tikz 的大括号)。

      \documentclass{article}
      \usepackage{nicematrix,tikz}
      
      \begin{document}
      
      $\begin{pNiceMatrix}%
        [ 
          code-for-first-row = \color{red},
          code-for-first-col = \color{blue},
          xdots/line-style=loosely dotted,
          parallelize-diags = false,
          first-row,
          first-col,
          nullify-dots,
        ]
               & 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     &        & \Vdots    & \Vdots      & \Ddots      &        & \Vdots     \\
               &           &            &        &           &             &             &        &            \\
      n        & a_{(n,1)} & a_{(n,2)}  & \Cdots & a_{(n,k)} & x_{(n,k+1)} & x_{(n,k+2)} & \Cdots & x_{(n,m)}  
      \CodeAfter
        \UnderBrace[shorten,yshift=1.5mm]{last-1}{last-4}{\mathrm{a}}
        \UnderBrace[shorten,yshift=1.5mm]{last-5}{last-last}{\mathrm{x}}
      \end{pNiceMatrix}$
      
      \end{document}
      

      nicematrix 一样,您需要进行多次编译。

      【讨论】:

        最近更新 更多