50 在`nicematrix`中,如何调整整个矩阵的高度和宽度,同时不影响元素水平、垂直方向居中?

发布于 2025-07-16 17:37:42

如题,希望调整矩阵的高度和内容的位置

  • 希望尽可能变得「方正」、「匀称」
  • 单元格的元素内容希望在「水平」以及「垂直」方向上的「居中」

下面是MWE:

\documentclass{article}
\usepackage{newpxmath}
\usepackage{nicematrix}
\usepackage{xcolor}
\usepackage{tikz}
\setlength{\extrarowheight}{1cm}
% \renewcommand\arraystretch{1.5}
\begin{document}
\[
    \begin{bNiceArray}{c|ccc|c}[cell-space-limits=2pt,margin]
        \CodeBefore
        \cellcolor{green!50}{1-1}
        \cellcolor{green!50}{5-5}
        \cellcolor{yellow!50}{1-5}
        \cellcolor{yellow!50}{5-1}
        \rectanglecolor{gray!50}{1-2}{1-4}
        \rectanglecolor{gray!50}{5-2}{5-4}
        \rectanglecolor{blue!50}{2-1}{4-1}
        \rectanglecolor{blue!50}{2-5}{4-5}
        %右上三角形
        \tikz \fill[red!50] (2-|3) -- (2-|5) -- (4-|5) -- cycle;
        \tikz \fill[orange!50] (3-|2) -- (2-|2) -- (2-|3) -- (4-|5) -- (5-|5) -- (5-|4) -- cycle;
        \tikz \fill[red!50] (3-|2) -- (5-|2) -- (5-|4) -- cycle;
        \Body
        -\dfrac{2N^2+1}{6} & & \dfrac{2\cdot (-1)^j}{-1-x_j} &  & -\dfrac{1}{2}(-1)^N \\
        \hline
        & & & \dfrac{(-1)^{i+j}}{x_i-x_j} &   \\
        -\dfrac{(-1)^{N+i}}{2(1+x_i)} & & \dfrac{-x_j}{2(1-x_j^2)} & &  -\dfrac{(-1)^i}{2(1-x_i)}\\
        & \dfrac{(-1)^{i+j}}{x_i-x_j} & & & \\
        \hline
        \dfrac{1}{2}(-1)^N & & \dfrac{2\cdot (-1)^{N+j}}{1-x_j} & & \dfrac{2N^2+1}{6}  \\
    \end{bNiceArray}
\]
\end{document}

似乎发现使用:

\setlength{\extrarowheight}{1cm}
\renewcommand\arraystretch{1.5}

的控制并不方便,也不优雅....

image.png

查看更多

关注者
0
被浏览
59
Thallo
Thallo 11小时前
这家伙不懒,但还是什么也没写
2 个回答
Sagittarius Rover
Sagittarius Rover 11小时前
我要成为Typst糕手/(ㄒoㄒ)/~~

Final Result:

image.png

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览