修复 blkarray 中的括号

修复 blkarray 中的括号

在下面给出的代码中,我希望\blkarray矩阵中的括号与公式 (1) 中给出的原始矩阵的括号相匹配。

在此处输入图片描述

问题是,当我使用时\blkarray,括号太短,看起来不像原始矩阵那样优雅。可以解决这个问题吗?谢谢。

以下是由成本加运费

\documentclass[11pt]{book}

\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{xcolor}
\definecolor{ocre}{RGB}{0,173,239}

\usepackage{blkarray}

\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
  \hskip -\arraycolsep
  \let\@ifnextchar\new@ifnextchar
  \array{#1}}
\makeatother

\usepackage{tikz}

\usetikzlibrary{arrows,matrix,positioning,fit,arrows.meta,}
\tikzset{%
  highlight/.style={rectangle,rounded corners,fill=ocre!50,draw,
    fill opacity=0.5,thick,inner sep=0pt}
}
\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,
  baseline=(#1.base)] \node (#1) {#2};}
%
\newcommand{\Highlight}[1][submatrix]{%
    \tikz[overlay,remember picture]{
    \node[highlight,fit=(left.north west) (right.south east)] (#1) {};}
}
\newcommand{\mytikzmark}[2]{\tikz[overlay,remember picture, baseline=(#1.base)] \node (#1) {#2};}
\begin{document}

Original Matrix:

\begin{equation}
\begin{bmatrix}[cccc|c]
  1 & 0 & -1 & 0 & 0 \\
  0 & 1 & 2 & 0 & 0 \\
  0 & 0 & 0 & 1 & 0
\end{bmatrix}\\
\end{equation}

Updated Matrix:

\begin{equation}
  \begin{blockarray}{ccccc}
    x_{1} & x_{2} & x_{3} & x_{4} &  \\
    \begin{block}{[cccc|c]}
      1 & 0 & \mytikzmark{left}{-1} & 0 & 0 \\
      0 & 1 & 2 & 0 & 0 \\
      0 & 0 & \mytikzmark{right}{0} & 1 & 0 \\
    \end{block}
  \end{blockarray}
  \Highlight[new1]
\end{equation}
\tikz[remember picture,overlay]{%
  \draw [LaTeX-] (new1.south) ++(0,-2.5pt) [out=-90,in=160] to ++(5mm,-10mm) node [right, xshift=-2.5mm, font=\itshape, text=red, align=center] {free\\variable};
}

\end{document} 

答案1

您可以\bbordermatrix使用\bordermatrix 使用方括号 [ ] 代替圆括号 ( )

\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{etoolbox}

\usetikzlibrary{arrows,matrix,positioning,fit,arrows.meta,}

\definecolor{ocre}{RGB}{0,173,239}

\tikzset{%
  highlight/.style={rectangle,rounded corners,fill=ocre!50,draw,
    fill opacity=0.5,thick,inner sep=0pt}
}
\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,
  baseline=(#1.base)] \node (#1) {#2};}
%
\newcommand{\Highlight}[1][submatrix]{%
    \tikz[overlay,remember picture]{
    \node[highlight,fit=(left.north west) (right.south east)] (#1) {};}
}
\newcommand{\mytikzmark}[2]{\tikz[overlay,remember picture, baseline=(#1.base)] \node (#1) {#2};}

\let\bbordermatrix\bordermatrix
\patchcmd{\bbordermatrix}{8.75}{4.75}{}{}
\patchcmd{\bbordermatrix}{\left(}{\left[}{}{}
\patchcmd{\bbordermatrix}{\right)}{\right]}{}{}

\newcommand{\wall}[2]{%
  \smash{%
    \vrule height \dimexpr\ht\strutbox+#1 depth \dimexpr\dp\strutbox+#2\relax
  }%
}

\begin{document}
\begin{equation}
\bbordermatrix{
 & x_{1} & x_{2} & x_{3}                 & x_{4} &                 &   \cr
 & 1     & 0     & \mytikzmark{left}{-1} & 0     & \wall{0pt}{3pt} & 0 \cr
 & 0     & 1     & 2                     & 0     & \wall{3pt}{3pt} & 0 \cr
 & 0     & 0     & \mytikzmark{right}{0} & 1     & \wall{3pt}{0pt} & 0 \cr
}
\Highlight[new1]
\end{equation}
\tikz[remember picture,overlay]{%
  \draw [LaTeX-] (new1.south) ++(0,-2.5pt) [out=-90,in=160] to ++(5mm,-10mm) node [right, xshift=-2.5mm, font=\itshape, text=red, align=center] {free\\variable};
}

\end{document}

在此处输入图片描述

答案2

这非常接近于重新询问同样的问题,但如果您想突出显示第一个数组而不是第二个数组中的某一列,只需将标记放在那里即可。

在此处输入图片描述

或者 egreg 想要我这样做

在此处输入图片描述

\documentclass[11pt]{book}


\documentclass[11pt]{book}

\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{xcolor}
\definecolor{ocre}{RGB}{0,173,239}

\usepackage{blkarray}

\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
  \hskip -\arraycolsep
  \let\@ifnextchar\new@ifnextchar
  \array{#1}}
\makeatother

\usepackage{tikz}

\usetikzlibrary{arrows,matrix,positioning,fit,arrows.meta,}
\tikzset{%
  highlight/.style={rectangle,rounded corners,fill=ocre!50,draw,
    fill opacity=0.5,thick,inner sep=0pt}
}
\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,
  baseline=(#1.base)] \node (#1) {#2};}
%
\newcommand{\Highlight}[1][submatrix]{%
    \tikz[overlay,remember picture]{
    \node[highlight,fit=(left.north west) (right.south east)] (#1) {};}
}
\newcommand{\mytikzmark}[2]{\tikz[overlay,remember picture, baseline=(#1.base)] \node (#1) {#2};}
\begin{document}

Original Matrix:



\bigskip
\begin{equation}
\begin{bmatrix}[cccc|c]
\noalign{\vskip-1.5\normalbaselineskip}
  x_{1} & x_{2} & x_{3} &\multicolumn{1}{c}{ x_{4}} &  \\
\noalign{\vskip.5\normalbaselineskip}
  1 & 0 & \mytikzmark{left}{-1} & 0 & 0 \\
  0 & 1 & 2 & 0 & 0 \\
  0 & 0 & \mytikzmark{right}{0} & 1 & 0
\end{bmatrix}\\
\end{equation}

  \Highlight[new1]

\tikz[remember picture,overlay]{%
  \draw [LaTeX-] (new1.south) ++(0,-2.5pt) [out=-90,in=160] to ++(5mm,-10mm) node [right, xshift=-2.5mm, font=\itshape, text=red, align=center] {free\\variable};
}

\end{document} 

答案3

使用,您将得到与和相同的括号。环境有一个键{bNiceArray},可以在矩阵上方添加一行标签。nicematrix{array}{bmatrix}{bNiceArray}first-row

\documentclass[11pt]{book}
\usepackage{xcolor}
\definecolor{ocre}{RGB}{0,173,239}

\usepackage{nicematrix}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows.meta}

\begin{document}

Original Matrix:

\begin{equation}
\left[\begin{array}{@{}cccc|c@{}}
  1 & 0 & -1 & 0 & 0 \\
  0 & 1 & 2 & 0 & 0 \\
  0 & 0 & 0 & 1 & 0
\end{array}\right]
\end{equation}

Updated Matrix:

\begin{equation}
\begin{bNiceArray}{cccc|c}[first-row]
  x_1 & x_2 & x_3 & x_4 \\
    1 & 0 & \Block[draw,fill=ocre!50,rounded-corners]{3-1}{}
            -1 & 0 & 0 \\
    0 & 1 & 2 & 0 & 0 \\
    0 & 0 & 0 & 1 & 0 \\
\CodeAfter
  \tikz \draw [LaTeX-] (3-3.south) ++(0,-4.5pt) [out=-90,in=160] to ++(5mm,-10mm) 
          node [right, xshift=-2.5mm, font=\itshape, text=red, align=center] {free\\variable};
\end{bNiceArray}
\end{equation}

\end{document} 

上述代码的输出

相关内容