tikzpicture、范围和矩阵

tikzpicture、范围和矩阵

我正在尝试突出显示矩阵中的特定列。因此,我在节点中绘制矩阵(带有easybmat),并在范围(在背景上)中绘制列的形状。但是,范围向右移动,我不知道为什么。

突出显示应从(第二行,第一列)到(最后一行,第一列)。

\documentclass{article} 
\usepackage{etex} 
\usepackage{easybmat} 
\usepackage[T1]{fontenc} 
\usepackage{lmodern} 
\usepackage{tikz} 
\usetikzlibrary{backgrounds,fit} 

\tikzset{% 
  highlight/.style={rectangle,rounded corners,fill=orange!35,draw,thick,inner sep=2pt} 
} 
\newcommand{\tikzmark}[2]{\tikz[remember picture,baseline=(#1.base),inner sep=0,outer sep=0pt] \node (#1) {#2};} 

\begin{document} 

\begin{tikzpicture}[remember picture] 
  \node (){ 
    $ 
    \left( \begin{BMAT}(r){cccccccc}{cccccccc} 
        a_{1\,1}^{(k)} & a_{1\,2}^{(k)} & \cdots &   &  & & \cdots & 
        a_{1\,n}^{(k)}   \\ 
        \tikzmark{left}{0} & a_{2\,2}^{(k)} &  &  &  & & & 
        a_{2\,n}^{(k)}  \\ 
        \vdots &    & \ddots &  &  &   &&  \vdots \\ 
        &   \vdots  &  & a_{k-1\, k-1}^{(k)} &    & & &  \\ 
        &  &  &  & a_{k\, k}^{(k)}  &    & &  \\ 
        &  &  \cdots &\vdots  &   &  a_{k+1\, k+1}^{(k)}  & &  \\ 
        & &   &   & \vdots & \vdots &\ddots &  \vdots \\ 
        \tikzmark{right}{0} & &  &   &  &  a_{n\, k+1}^{(k)}  & & 
        a_{n\,n}^{(k)}  \\ 
      \end{BMAT} \right) 
    $ 
  }; 
  \begin{scope}[on background layer] 
    \node[highlight,overlay,fit=(left.north west) (right.south east)] {}; 
  \end{scope} 
\end{tikzpicture} 
\end{document}

输出

答案1

一种layer方法。无需将所有内容都包含在一次tikzpicture. 运行中pdflatex两次。

在此处输入图片描述

\documentclass{article} 
\usepackage{etex} 
\usepackage{easybmat} 
\usepackage[T1]{fontenc} 
\usepackage{lmodern} 
\usepackage{tikz} 
\usetikzlibrary{fit}

\tikzset{% 
  highlight/.style={rectangle,rounded corners,fill=orange!35,draw,thick,inner sep=2pt} 
} 
\newcommand{\tikzmark}[2]{\tikz[remember picture,baseline=(#1.base),inner sep=0,outer sep=0pt] \node (#1) {#2};} 

\begin{document} 

\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}


\begin{pgfonlayer}{foreground}
    $ 
    \left( \begin{BMAT}(r){cccccccc}{cccccccc} 
        a_{1\,1}^{(k)} & a_{1\,2}^{(k)} & \cdots &   &    & & \cdots & 
        a_{1\,n}^{(k)}   \\ 
        \tikzmark{left}{0} & a_{2\,2}^{(k)} &  &  &  & & & 
        a_{2\,n}^{(k)}  \\ 
        \vdots &    & \ddots &  &  &   &&  \vdots \\ 
        &   \vdots  &  & a_{k-1\, k-1}^{(k)} &    & & &  \\ 
        &  &  &  & a_{k\, k}^{(k)}  &    & &  \\ 
        &  &  \cdots &\vdots  &   &  a_{k+1\, k+1}^{(k)}  & &  \\ 
        & &   &   & \vdots & \vdots &\ddots &  \vdots \\ 
        \tikzmark{right}{0} & &  &   & &  a_{n\, k+1}^{(k)}  & & 
        a_{n\,n}^{(k)}  \\ 
      \end{BMAT} \right) 
    $ 
\end{pgfonlayer}

\begin{tikzpicture}[inner sep=0pt,thick,remember picture,overlay]
\begin{pgfonlayer}{background}
\node[highlight,fit=(left) (right)] {};
\end{pgfonlayer}
\end{tikzpicture}
\end{document}

答案2

这不是答案,而是我评论的延伸。另请参阅向矩阵添加分隔符的手册。

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[column 2/.style=red]
\matrix [matrix of nodes]
{
8 & 1 & 6 \\
3 & 5 & 7 \\
4 & 9 & 2 \\
};
\end{tikzpicture}
\end{document}

相关内容