矩阵周围有额外的花括号

矩阵周围有额外的花括号

我想要有像这样的矩阵: enter image description here

我知道如何在 tikz 中制作彩色框架,但我对括号有问题。我尝试了以下代码:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools} %do robienia mini macierzy
%           linki w spisie tresci
\usepackage[customcolors]{hf-tikz} % do kolorowych macierzy
\usetikzlibrary{patterns}
\usetikzlibrary{decorations.pathreplacing}



\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture,baseline=(#1.base)]
  \node (#1) {\strut};}

%opening
\title{}
\author{}

\begin{document}
\begin{equation}
  \left[ \begin{array}{cccccc}
    v_{1,1}  &  v_{1,2} & \tikzmark{F1p} v_{1,3}  \tikzmark{F1k} & \tikzmark{F2p} \textcolor{white}{v_{1,4}}  \tikzmark{F2k}&  &   \\
    v_{2,1}  & v_{2,2} & v_{2,3} & & &   \\
    \tikzmark{E1p} v_{3,1}  & v_{3,2} & v_{3,3} & v_{3,4}   & &   \\
     & &  v_{4,3} & v_{4,4} & v_{4,5}  & v_{4,6} \\
    \tikzmark{E1k} & & & v_{5,4} & v_{5,5} & v_{5,6}   \\
    & &  & v_{6,4} & v_{6,5} & v_{6,6} \\
  \end{array}\right]
\end{equation}



\begin{tikzpicture}[overlay, remember picture,decoration={brace,amplitude=2pt}]
\draw[decorate,thick] (F1p.north) -- (F1k.north)
      node [midway,above=5pt] {$F'$};
\draw[decorate,thick] (F2p.north) -- (F2k.north)
      node [midway,above=5pt] {$F''$};

\draw [decorate,thick,xshift=-2pt,yshift=0pt]
(E1p) -- (E1k) node [black,midway,xshift=-0.6cm] 
{\footnotesize $P_1$};
\end{tikzpicture}

\end{document}

但结果如下: enter image description here

我对制作上部支架知之甚少。我应该如何正确制作?

我尝试使用以下代码:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools} %do robienia mini macierzy
%           linki w spisie tresci
\usepackage[customcolors]{hf-tikz} % do kolorowych macierzy
\usetikzlibrary{patterns}
\usetikzlibrary{matrix,decorations.pathreplacing,calc}



\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture,baseline=(#1.base)]
  \node (#1) {\strut};}

%opening
\title{}
\author{}

\pgfkeys{tikz/mymatrixenv/.style={decoration=brace,every left delimiter/.style={xshift=3pt},every right delimiter/.style={xshift=-3pt}}}
\pgfkeys{tikz/mymatrix/.style={matrix of math nodes,left delimiter=[,right delimiter={]},inner sep=2pt,column sep=1em,row sep=0.5em,nodes={inner sep=0pt}}}
\pgfkeys{tikz/mymatrixbrace/.style={decorate,thick}}
\newcommand\mymatrixbraceoffseth{0.5em}
\newcommand\mymatrixbraceoffsetv{0.2em}


\newcommand*\mymatrixbraceright[4][m]{
    \draw[mymatrixbrace] ($(#1.north west)!(#1-#3-1.south west)!(#1.south west)-(\mymatrixbraceoffseth,0)$)
        -- node[left=2pt] {#4} 
        ($(#1.north west)!(#1-#2-1.north west)!(#1.south west)-(\mymatrixbraceoffseth,0)$);
}
\newcommand*\mymatrixbraceleft[4][m]{
    \draw[mymatrixbrace] ($(#1.north east)!(#1-#2-1.north east)!(#1.south east)+(\mymatrixbraceoffseth,0)$)
        -- node[right=2pt] {#4} 
        ($(#1.north east)!(#1-#3-1.south east)!(#1.south east)+(\mymatrixbraceoffseth,0)$);
}
\newcommand*\mymatrixbracetop[4][m]{
    \draw[mymatrixbrace] ($(#1.north west)!(#1-1-#2.north west)!(#1.north east)+(0,\mymatrixbraceoffsetv)$)
        -- node[above=2pt] {#4} 
        ($(#1.north west)!(#1-1-#3.north east)!(#1.north east)+(0,\mymatrixbraceoffsetv)$);
}
\newcommand*\mymatrixbracebottom[4][m]{
    \draw[mymatrixbrace] ($(#1.south west)!(#1-1-#3.south east)!(#1.south east)-(0,\mymatrixbraceoffsetv)$)
        -- node[below=2pt] {#4} 
        ($(#1.south west)!(#1-1-#2.south west)!(#1.south east)-(0,\mymatrixbraceoffsetv)$);
}

\begin{document}



\begin{equation}
\mathbf{X} = 
\begin{tikzpicture}[baseline=0cm,mymatrixenv]
    \matrix [mymatrix,inner sep=4pt,row sep=1em] (m)  
    {
    v_{1,1}  &  v_{1,2} & \tikzmark{F1p} v_{1,3}  \tikzmark{F1k} & \tikzmark{F2p} \textcolor{white}{v_{1,4}}  \tikzmark{F2k}&  &   \\
    v_{2,1}  & v_{2,2} & v_{2,3} & & &   \\
    \tikzmark{E1p} v_{3,1}  & v_{3,2} & v_{3,3} & v_{3,4}   & &   \\
     & &  v_{4,3} & v_{4,4} & v_{4,5}  & v_{4,6} \\
    \tikzmark{E1k} & & & v_{5,4} & v_{5,5} & v_{5,6}   \\
    & &  & v_{6,4} & v_{6,5} & v_{6,6} \\
    };

    % Braces     
    \mymatrixbraceright{1}{3}{$B'$}
    \mymatrixbraceright{4}{6}{$B''$}
%    \mymatrixbracetop{1}{3}{$C'$}
%    \mymatrixbracetop{4}{6}{$C''$}
%    \mymatrixbracebottom{3}{3}{$F'$}
%    \mymatrixbracebottom{4}{4}{$F''$}
\end{tikzpicture}
\end{equation}



\end{document}

但它给出了错误:“包 pgf 错误:没有已知的名为 m-4-1 的形状 \mymatrixbraceright{4}{6}{$B''$}”

将相应行更改为以下后,效果会好得多:

\pgfkeys{tikz/mymatrix/.style={matrix of math nodes, nodes in empty cells, left delimiter=[,right delimiter={]},inner sep=2pt,column sep=1em,row sep=0.5em,nodes={inner sep=0pt}}}

但还是有缝隙。如何消除缝隙或缩小缝隙? enter image description here

答案1

@Milo 的优秀答案的一个(可能更简单的)替代方案是,我给了所有节点一个最小尺寸。

enter image description here

我还\mymatrixbrace<side>稍微改变了命令,这样您就不再需要该calc库了。

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools} %do robienia mini macierzy
%           linki w spisie tresci
\usepackage[customcolors]{hf-tikz} % do kolorowych macierzy
\usetikzlibrary{patterns}
\usetikzlibrary{matrix,decorations.pathreplacing}

%opening
\title{}
\author{}

\pgfkeys{tikz/mymatrixenv/.style={decoration={brace},every left delimiter/.style={xshift=8pt},every right delimiter/.style={xshift=-8pt}}}
\pgfkeys{tikz/mymatrix/.style={matrix of math nodes,nodes in empty cells,left delimiter={[},right delimiter={]},inner sep=1pt,outer sep=1.5pt,column sep=2pt,row sep=2pt,nodes={minimum width=20pt,minimum height=10pt,anchor=center,inner sep=0pt,outer sep=0pt}}}
\pgfkeys{tikz/mymatrixbrace/.style={decorate,thick}}

\newcommand*\mymatrixbraceright[4][m]{
    \draw[mymatrixbrace] (#1.west|-#1-#3-1.south west) -- node[left=2pt] {#4} (#1.west|-#1-#2-1.north west);
}
\newcommand*\mymatrixbraceleft[4][m]{
    \draw[mymatrixbrace] (#1.east|-#1-#2-1.north east) -- node[right=2pt] {#4} (#1.east|-#1-#3-1.south east);
}
\newcommand*\mymatrixbracetop[4][m]{
    \draw[mymatrixbrace] (#1.north-|#1-1-#2.north west) -- node[above=2pt] {#4} (#1.north-|#1-1-#3.north east);
}
\newcommand*\mymatrixbracebottom[4][m]{
    \draw[mymatrixbrace] (#1.south-|#1-1-#2.north east) -- node[below=2pt] {#4} (#1.south-|#1-1-#3.north west);
}

\begin{document}

\begin{equation}
    \mathbf{X} = 
    \begin{tikzpicture}[baseline={-0.5ex},mymatrixenv]
        \matrix [mymatrix,inner sep=4pt] (m)  
        {
        v_{1,1} & v_{1,2} & v_{1,3} &         &         &         \\
        v_{2,1} & v_{2,2} & v_{2,3} &         &         &         \\
        v_{3,1} & v_{3,2} & v_{3,3} & v_{3,4} &         &         \\
                &         & v_{4,3} & v_{4,4} & v_{4,5} & v_{4,6} \\
                &         &         & v_{5,4} & v_{5,5} & v_{5,6} \\
                &         &         & v_{6,4} & v_{6,5} & v_{6,6} \\
        };
    
        % Braces     
        \mymatrixbraceright{1}{3}{$B'$}
        \mymatrixbraceright{4}{6}{$B''$}
        \mymatrixbracetop{1}{3}{$C'$}
        \mymatrixbracetop{4}{6}{$C''$}
        \mymatrixbracebottom{3}{3}{$F'$}
        \mymatrixbracebottom{4}{4}{$F''$}
        \mymatrixbraceleft{3}{3}{$E'$}
        \mymatrixbraceleft{4}{4}{$E''$}
    \end{tikzpicture}
\end{equation}



\end{document}

编辑:\mymatrixbraceleft根据 Daniel H. 的评论进行调整

答案2

更新

这是其中一种方法。步骤列在我下面的原始答案中。并不是说这是最好的方法,当然可以优化步骤,但它适用于这个特定的矩阵。

因为无论如何您都需要在这个矩阵的某些子集周围绘制彩色框,所以您可以使用该fit库来实现这一点,然后使用这些坐标来帮助引导大括号的位置。

enter image description here

\documentclass[margin=0.5cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.pathreplacing,calc,fit}

\pgfkeys{tikz/mymatrixenv/.style={decoration=brace,every left delimiter/.style={xshift=4.7pt},every right delimiter/.style={xshift=-4.7pt}}}
\pgfkeys{tikz/mymatrix/.style={matrix of math nodes, nodes in empty cells, left delimiter=[,right delimiter={]},inner sep=2pt,column sep=1em,row sep=0.5em,nodes={inner sep=0pt}}}
\pgfkeys{tikz/mymatrixbrace/.style={decorate,thick}}

% The hack required for foreach loops in fit. Code from https://tex.stackexchange.com/questions/4751/fitting-a-list-of-points-with-tikz-and-its-foreach?noredirect=1&lq=1
\makeatletter
\def\tikz@lib@fit@scan{%
  \pgfutil@ifnextchar\pgf@stop{\pgfutil@gobble}{%
    \pgfutil@ifnextchar\foreach{\tikz@lib@fit@scan@handle@foreach}{%
      \tikz@scan@one@point\tikz@lib@fit@scan@handle}}}
\def\tikz@lib@fit@scan@handle@foreach\foreach#1in#2#3{%
  \foreach #1 in {#2}
  {\tikz@scan@one@point\tikz@lib@fit@scan@handle@foreach@#3}
  \tikz@lib@fit@scan}
\def\tikz@lib@fit@scan@handle@foreach@#1{%
  \iftikz@shapeborder
    \tikz@lib@fit@adjust{%
      \pgfpointanchor{\tikz@shapeborder@name}{west}}%
    \tikz@lib@fit@adjust{%
      \pgfpointanchor{\tikz@shapeborder@name}{east}}%
    \tikz@lib@fit@adjust{%
      \pgfpointanchor{\tikz@shapeborder@name}{north}}%
    \tikz@lib@fit@adjust{%
      \pgfpointanchor{\tikz@shapeborder@name}{south}}%
  \else
    \tikz@lib@fit@adjust{#1}%
  \fi
  \global\pgf@xa=\pgf@xa
  \global\pgf@ya=\pgf@ya
  \global\pgf@xb=\pgf@xb
  \global\pgf@yb=\pgf@yb}
\makeatletter

\begin{document}


\begin{tikzpicture}[baseline=0cm,mymatrixenv]
    \matrix [mymatrix,outer ysep=0.7pt,inner sep=4pt,row sep=1em] (m)  
    {
    v_{1,1}  &  v_{1,2} &  v_{1,3}  & &  &   \\
    v_{2,1}  & v_{2,2} & v_{2,3} & & &   \\
   v_{3,1}  & v_{3,2} & v_{3,3} & v_{3,4}   & &   \\
     & &  v_{4,3} & v_{4,4} & v_{4,5}  & v_{4,6} \\
    & & & v_{5,4} & v_{5,5} & v_{5,6}   \\
    & &  & v_{6,4} & v_{6,5} & v_{6,6} \\
    };

% Colours
\definecolor{brightpurple}{HTML}{C151EF}

% Fitting - note to get a \foreach loop in these fits requires the hack from https://tex.stackexchange.com/questions/4751/fitting-a-list-of-points-with-tikz-and-its-foreach
\node [fit= \foreach \X in {1,...,3}{(m-\X-1)}
            \foreach \X in {1,...,3}{(m-\X-2)}
            \foreach \X in {1,...,3}{(m-\X-3)}]
            [draw=green, thick,inner sep=2.6pt] (fit-a) {};

\node [fit= \foreach \X in {4,...,6}{(m-\X-4)}
            \foreach \X in {4,...,6}{(m-\X-5)}
            \foreach \X in {4,...,6}{(m-\X-6)}]
            [draw=cyan, thick,inner sep=2.6pt] (fit-b) {};

\node [fit= \foreach \X in {1,...,4}{(m-\X-3)}] [draw=brightpurple,fill=brightpurple,fill opacity=0.1, thick,inner sep=1.8pt] (fit-purple-a) {};
\node [fit= \foreach \X in {3,...,6}{(m-\X-4)}] [draw=brightpurple,fill=brightpurple,fill opacity=0.1, thick,inner sep=1.8pt]  (fit-purple-b) {};       
\node [fit= \foreach \X in {1,...,4}{(m-3-\X)}] [draw=brown,fill=brown,fill opacity=0.1, thick,inner sep=1pt] (fit-brown-a) {};   \node [fit= \foreach \X in {3,...,6}{(m-4-\X)}] [draw=brown,fill=brown,fill opacity=0.1, thick,inner sep=1pt] (fit-brown-b) {}; 
\node [fit = (m-3-3) (m-3-4) (m-4-3) (m-4-4)] [draw=orange,fill=orange,fill opacity=0.1, thick,inner sep=2.6pt] {};

% FINDING VERTICAL MIDPOINT
 \node [fit= \foreach \X in {1,...,3}{
            (m-\X-1)}] (fit-one)  {}; 
 \node [fit= \foreach \X in {4,...,6}{
            (m-\X-6)}] (fit-two)  {}; 
\path (fit-one.south) -- (fit-two.north) coordinate[midway] (X);

% FINDING HORIZONTAL MIDPOINT
 \node [fit= \foreach \X in {1,...,3}{
            (m-1-\X)}] (fit-one)  {}; 
 \node [fit= \foreach \X in {4,...,6}{
            (m-6-\X)}] (fit-two)  {}; 
\path (fit-one.east) -- (fit-two.west) coordinate[midway] (Y);

\newcommand\mymatrixbraceoffseth{0.3em}
\newcommand\mymatrixbraceoffsetv{0.3em}

% LHS BRACES
\draw [mymatrixbrace] ($(m.north west)!(fit-a.south)!(m.south west)-(\mymatrixbraceoffseth,0)$)   -- node[left=2pt] {$B'$}  ($(m.north west)!(fit-a.north)!(m.south west)-(\mymatrixbraceoffseth,0)$);
\draw [mymatrixbrace] ($(m.north west)!(fit-b.south)!(m.south west)-(\mymatrixbraceoffseth,0)$) -- node[left=2pt] {$B''$} ($(m.north west)!(fit-b.north)!(m.south west)-(\mymatrixbraceoffseth,0)$);

% RHS BRACES
\draw [mymatrixbrace]  ($(m.north east)!([yshift=-0.02cm]X)!(m.south east)+(\mymatrixbraceoffseth,0)$)   -- node[right=2pt] {$E''$} ($(m.north east)!(fit-brown-b.south)!(m.south east)+(\mymatrixbraceoffseth,0)$);
 \draw [mymatrixbrace]  ($(m.north east)!(fit-brown-a.north)!(m.south east)+(\mymatrixbraceoffseth,0)$) --node[right=2pt] {$E'$}   ($(m.north east)! ([yshift=+0.02cm]X)!(m.south east)+(\mymatrixbraceoffseth,0)$);

% TOP BRACES       
\draw[mymatrixbrace] ($(m.north west)!([xshift=0.05cm]Y)!(m.north east)+(0,\mymatrixbraceoffsetv)$) -- node[above=2pt] {$C''$}  ($(m.north west)!(fit-b.east)!(m.north east)+(0,\mymatrixbraceoffsetv)$);
\draw[mymatrixbrace] ($(m.north west)!(fit-a.west)!(m.north east)+(0,\mymatrixbraceoffsetv)$)-- node[above=2pt] {$C'$}   ($(m.north west)!([xshift=-0.05cm]Y)!(m.north east)+(0,\mymatrixbraceoffsetv)$);

% BOTTOM BRACES      
\draw[mymatrixbrace] ($(m.south west)!([xshift=-0.05cm]Y)!(m.south east)-(0,\mymatrixbraceoffsetv)$)-- node[below=2pt] {$F'$}  ($(m.south west)!(fit-purple-a.west)!(m.south east)-(0,\mymatrixbraceoffsetv)$);   
\draw[mymatrixbrace] ($(m.south west)!(fit-purple-b.east)!(m.south east)-(0,\mymatrixbraceoffsetv)$) -- node[below=2pt] {$F''$} ($(m.south west)!([xshift=0.05cm]Y)!(m.south east)-(0,\mymatrixbraceoffsetv)$);   

\end{tikzpicture}
\end{document}

原始答案

以下是一个概念证明,用于说明如何消除两个括号之间的间隙。我在所有节点周围画了框来说明边界的位置。上面的示例中下括号B''比上括号短的B'原因是它仅测量第一列单元格的坐标。(这只是自定义命令的限制,\mymatrixbraceright因为它已在 MWE 中定义)。但是看看第一列单元格 (6,1) 的边界框比单元格 (6,6) 小?

我在这里使用的方法是围绕单元格 (1,1)、(2,1) 和 (3,1) 进行拟合,并围绕单元格 (4,6)、(5,6) 和 (6,6) 进行拟合。使用这两个拟合,我可以找到它们之间的中点。这灵感来自自动查找最近的节点,以帮助在 TikZ 矩阵内绘制线条

然后,我可以使用这个中点手动绘制从 (1,1) 顶部到 (X) 的括号。并从 (X) 到 (6,6) 的底部。

enter image description here

\documentclass[margin=0.5cm]{standalone}

\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.pathreplacing,calc,fit}

\pgfkeys{tikz/mymatrixenv/.style={decoration=brace,every left delimiter/.style={xshift=3pt},every right delimiter/.style={xshift=-3pt}}}
\pgfkeys{tikz/mymatrix/.style={matrix of math nodes, nodes in empty cells, left delimiter=[,right delimiter={]},inner sep=2pt,column sep=1em,row sep=0.5em,nodes={inner sep=0pt}}}
\pgfkeys{tikz/mymatrixbrace/.style={decorate,thick}}
\newcommand\mymatrixbraceoffseth{0.5em}
\newcommand\mymatrixbraceoffsetv{0em}


% CODE from https://tex.stackexchange.com/questions/4751/fitting-a-list-of-points-with-tikz-and-its-foreach?noredirect=1&lq=1
\makeatletter
\def\tikz@lib@fit@scan{%
  \pgfutil@ifnextchar\pgf@stop{\pgfutil@gobble}{%
    \pgfutil@ifnextchar\foreach{\tikz@lib@fit@scan@handle@foreach}{%
      \tikz@scan@one@point\tikz@lib@fit@scan@handle}}}
\def\tikz@lib@fit@scan@handle@foreach\foreach#1in#2#3{%
  \foreach #1 in {#2}
  {\tikz@scan@one@point\tikz@lib@fit@scan@handle@foreach@#3}
  \tikz@lib@fit@scan}
\def\tikz@lib@fit@scan@handle@foreach@#1{%
  \iftikz@shapeborder
    \tikz@lib@fit@adjust{%
      \pgfpointanchor{\tikz@shapeborder@name}{west}}%
    \tikz@lib@fit@adjust{%
      \pgfpointanchor{\tikz@shapeborder@name}{east}}%
    \tikz@lib@fit@adjust{%
      \pgfpointanchor{\tikz@shapeborder@name}{north}}%
    \tikz@lib@fit@adjust{%
      \pgfpointanchor{\tikz@shapeborder@name}{south}}%
  \else
    \tikz@lib@fit@adjust{#1}%
  \fi
  \global\pgf@xa=\pgf@xa
  \global\pgf@ya=\pgf@ya
  \global\pgf@xb=\pgf@xb
  \global\pgf@yb=\pgf@yb}
\makeatletter


\begin{document}


\begin{tikzpicture}[baseline=0cm,mymatrixenv]
    \matrix [mymatrix,inner sep=4pt,row sep=1em,draw,nodes={draw}] (m)  
    {
    v_{1,1}  &  v_{1,2} &  v_{1,3}  & &  &   \\
    v_{2,1}  & v_{2,2} & v_{2,3} & & &   \\
   v_{3,1}  & v_{3,2} & v_{3,3} & v_{3,4}   & &   \\
     & &  v_{4,3} & v_{4,4} & v_{4,5}  & v_{4,6} \\
    & & & v_{5,4} & v_{5,5} & v_{5,6}   \\
    & &  & v_{6,4} & v_{6,5} & v_{6,6} \\
    };

 \node [fit= \foreach \X in {1,...,3}{
            (m-\X-1)}] (fit-a) [draw] {}; 
 \node [fit= \foreach \X in {4,...,6}{
            (m-\X-6)}] (fit-b) [draw] {}; 
\path (fit-a.south) -- (fit-b.north) coordinate[midway] (X);

\draw [mymatrixbrace] ($(m.north west)!(X)!(m.south west)-(\mymatrixbraceoffseth,0)$)
        -- node[left=2pt] {$B'$} 
        ($(m.north west)!(m-1-1.north west)!(m.south west)-(\mymatrixbraceoffseth,0)$);

\draw [mymatrixbrace] ($(m.north west)!(m-6-6.south)!(m.south west)-(\mymatrixbraceoffseth,0)$)
        -- node[left=2pt] {$B'$} 
        ($(m.north west)!(X)!(m.south west)-(\mymatrixbraceoffseth,0)$);

\end{tikzpicture}

\end{document}

为了更接近您发布的图像。我建议添加稍微移动 y 坐标。在这里,我在上括号和下括号上(X)使用了。此外,为了使括号到达矩阵括号的末端,而不是从 (1,1) 的北边界和 (6,6) 的南边界绘制它们,我对其进行了更改,使它们从和 从绘制。我还添加了略微增加方括号的长度。您可以根据需要使用这些数字。yshift=0.05cmyshift=-0.05cmm.northm.southouter ysep=0.5pt

enter image description here

\documentclass[margin=0.5cm]{standalone}

\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.pathreplacing,calc,fit}

\pgfkeys{tikz/mymatrixenv/.style={decoration=brace,every left delimiter/.style={xshift=3pt},every right delimiter/.style={xshift=-3pt}}}
\pgfkeys{tikz/mymatrix/.style={matrix of math nodes, nodes in empty cells, left delimiter=[,right delimiter={]},inner sep=2pt,column sep=1em,row sep=0.5em,nodes={inner sep=0pt}}}
\pgfkeys{tikz/mymatrixbrace/.style={decorate,thick}}
\newcommand\mymatrixbraceoffseth{0.5em}
\newcommand\mymatrixbraceoffsetv{0em}


% CODE from https://tex.stackexchange.com/questions/4751/fitting-a-list-of-points-with-tikz-and-its-foreach?noredirect=1&lq=1
\makeatletter
\def\tikz@lib@fit@scan{%
  \pgfutil@ifnextchar\pgf@stop{\pgfutil@gobble}{%
    \pgfutil@ifnextchar\foreach{\tikz@lib@fit@scan@handle@foreach}{%
      \tikz@scan@one@point\tikz@lib@fit@scan@handle}}}
\def\tikz@lib@fit@scan@handle@foreach\foreach#1in#2#3{%
  \foreach #1 in {#2}
  {\tikz@scan@one@point\tikz@lib@fit@scan@handle@foreach@#3}
  \tikz@lib@fit@scan}
\def\tikz@lib@fit@scan@handle@foreach@#1{%
  \iftikz@shapeborder
    \tikz@lib@fit@adjust{%
      \pgfpointanchor{\tikz@shapeborder@name}{west}}%
    \tikz@lib@fit@adjust{%
      \pgfpointanchor{\tikz@shapeborder@name}{east}}%
    \tikz@lib@fit@adjust{%
      \pgfpointanchor{\tikz@shapeborder@name}{north}}%
    \tikz@lib@fit@adjust{%
      \pgfpointanchor{\tikz@shapeborder@name}{south}}%
  \else
    \tikz@lib@fit@adjust{#1}%
  \fi
  \global\pgf@xa=\pgf@xa
  \global\pgf@ya=\pgf@ya
  \global\pgf@xb=\pgf@xb
  \global\pgf@yb=\pgf@yb}
\makeatletter


\begin{document}


\begin{tikzpicture}[baseline=0cm,mymatrixenv]
    \matrix [mymatrix,outer ysep=0.5pt,inner sep=4pt,row sep=1em] (m)  
    {
    v_{1,1}  &  v_{1,2} &  v_{1,3}  & &  &   \\
    v_{2,1}  & v_{2,2} & v_{2,3} & & &   \\
   v_{3,1}  & v_{3,2} & v_{3,3} & v_{3,4}   & &   \\
     & &  v_{4,3} & v_{4,4} & v_{4,5}  & v_{4,6} \\
    & & & v_{5,4} & v_{5,5} & v_{5,6}   \\
    & &  & v_{6,4} & v_{6,5} & v_{6,6} \\
    };

 \node [fit= \foreach \X in {1,...,3}{
            (m-\X-1)}] (fit-a)  {}; 
 \node [fit= \foreach \X in {4,...,6}{
            (m-\X-6)}] (fit-b)  {}; 
\path (fit-a.south) -- (fit-b.north) coordinate[midway] (X);

\draw [mymatrixbrace] ($(m.north west)!([yshift=0.05cm]X)!(m.south west)-(\mymatrixbraceoffseth,0)$)
        -- node[left=2pt] {$B'$} 
        ($(m.north west)!(m.north west)!(m.south west)-(\mymatrixbraceoffseth,0)$);

\draw [mymatrixbrace] ($(m.north west)!(m.south)!(m.south west)-(\mymatrixbraceoffseth,0)$)
        -- node[left=2pt] {$B''$} 
        ($(m.north west)!([yshift=-0.05cm]X)!(m.south west)-(\mymatrixbraceoffseth,0)$);

\end{tikzpicture}

\end{document}

答案3

一个选项包括一些技巧patterns,用于fit突出显示元素并获取外部括号的坐标;我使用辅助节点找到突出显示的框之间的交点来绘制括号,还绘制矩阵的括号并使用、和控制分隔inne xsepinner ysep最后我修改左右分隔符以增加线条粗细。

文章类别结果:

enter image description here

文章类中的 MWE:

% arara: pdflatex: {synctex: yes, action: nonstopmode}
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{lipsum}
\usepackage{mathtools} %do robienia mini macierzy
%           linki w spisie tresci
\usepackage[customcolors]{hf-tikz} % do kolorowych macierzy
\definecolor{mygreen}{HTML}{21EE7D}
\definecolor{mypurple}{HTML}{BB1BFF}
\usetikzlibrary{matrix,fit,backgrounds,patterns,decorations.pathreplacing}

%opening
\title{}
\author{}
%Create a new patern for firefox and adobe reader from https://tex.stackexchange.com/a/219808/154390
\pgfdeclarepatternformonly{north east lines b}{\pgfqpoint{0pt}{0pt}}{\pgfqpoint{20pt}{20pt}}{\pgfqpoint{20pt}{20pt}}%
{
    \pgfsetlinewidth{6pt}
    %Principal line
    \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
    \pgfpathlineto{\pgfqpoint{20pt}{20pt}}
    %Complement line north east
    \pgfpathmoveto{\pgfqpoint{16pt}{-4pt}}
    \pgfpathlineto{\pgfqpoint{24pt}{4pt}}
    %Complement line south west
    \pgfpathmoveto{\pgfqpoint{-4pt}{16pt}}
    \pgfpathlineto{\pgfqpoint{4pt}{24pt}}
    \pgfusepath{stroke}
}
\begin{document}
\lipsum[1-2]
\begin{equation}
    \mathbf{X} = 
    \begin{tikzpicture}[
        %Global config
        baseline=0cm,
        >=latex,
        line width=1pt,
        %Styles
        Brace/.style={
            decorate,
            decoration={
                brace,
                amplitude=2pt,
                raise=-7pt
            }
        },
        Brackets/.style={
            left delimiter={[},
            right delimiter={]}
        },
        every left delimiter/.style={
                xshift=2pt,
                xscale=1.5,
                transform shape
        },
        every right delimiter/.style={
                xshift=-2pt,
                xscale=1.5,
                transform shape
        },
        Matrix/.style={
            matrix of math nodes,
            text height=1.5ex,
            text depth=0.5ex,
            text width=4ex,
            align=center,
            column sep=7pt,
            row sep=7pt,
            nodes in empty cells,
        },
        HLbox/.style={
            rectangle,
            draw,
            line width=1.5pt,
            fill,
            fill opacity=0.1,   
        },
        HLPbox/.style={
            thick,
            pattern=north east lines b,         
        }
        ]

        \matrix[Matrix] at (0,0) (M1){ % Matrix contents  
            v_{1,1}  & v_{1,2} & v_{1,3} &            &            &            \\
            v_{2,1}  & v_{2,2} & v_{2,3} &            &            &            \\
            v_{3,1}  & v_{3,2} & v_{3,3} & v_{3,4} &            &            \\
            &            & v_{4,3} & v_{4,4} & v_{4,5} & v_{4,6} \\
            &            &            & v_{5,4} & v_{5,5} & v_{5,6} \\
            &            &            & v_{6,4} & v_{6,5} & v_{6,6} \\
        };

        %Hightlight elements in background layer
        \begin{scope}[on background layer] 
        \node[HLPbox,pattern color=orange!50,draw=orange,inner sep=2pt,fit=(M1-3-3)(M1-4-4)](F){};
        \node[HLbox,mygreen,inner sep=1pt,fit=(M1-1-1)(M1-3-3)](C1){};
        \node[HLbox,cyan,inner sep=1pt,fit=(M1-4-4)(M1-6-6)](C2){};
        \node[HLbox,brown,inner sep=-3pt,fit=(M1-3-1)(M1-3-4)](E1){};
        \node[HLbox,brown,inner sep=-3pt,fit=(M1-4-3)(M1-4-6)](E2){};
        \node[HLbox,mypurple,inner sep= -1pt,fit=(M1-1-3)(M1-4-3)](F1){};
        \node[HLbox,mypurple,inner sep= -1pt,fit=(M1-3-4)(M1-6-4)](F2){};
        \end{scope}

        %Delimiters
        \node[Brackets,inner xsep=-6pt,inner ysep=0.5pt,fit=(M1)](BM1){};
        % Auxiliar to separate external braces
        \node[inner xsep=10pt,inner ysep=10pt,fit=(M1)](AUX){};

        % Drawing the braces.
        %Above
        \draw[Brace] (AUX.90 -| C1.180) -- (AUX.90 -| C1.0) node[midway,above]{$C'$};
        \draw[Brace] (AUX.90 -| C2.180) -- (AUX.90 -| C2.0) node[midway,above]{$C''$};
        %below
        \draw[Brace] (AUX.270 -| F1.0) -- (AUX.270 -| F1.180) node[midway,below]{$F'$};
        \draw[Brace] (AUX.270 -| F2.0) -- (AUX.270 -| F2.180) node[midway,below]{$F''$};
        %Left
        \draw[Brace] (AUX.180 |- C1.270) -- (AUX.180 |- C1.90) node[midway,left]{$B'$};
        \draw[Brace] (AUX.180 |- C2.270) -- (AUX.180 |- C2.90) node[midway,left]{$B''$};
        %Right
        \draw[Brace] (AUX.0 |- E1.90) -- (AUX.0 |- E1.270) node[midway,right]{$E'$};
        \draw[Brace] (AUX.0 |- E2.90) -- (AUX.0 |- E2.270) node[midway,right]{$E''$};
    \end{tikzpicture}
\end{equation}

\lipsum[3]

\end{document}

独立类中的结果: enter image description here 独立类中的 MWE:

\documentclass[tikz,border=14pt]{standalone}
\definecolor{mygreen}{HTML}{21EE7D}
\definecolor{mypurple}{HTML}{BB1BFF}
\usetikzlibrary{matrix,fit,backgrounds,patterns,decorations.pathreplacing}

%Create a new patern for firefox and adobe reader from https://tex.stackexchange.com/a/219808/154390
\pgfdeclarepatternformonly{north east lines b}{\pgfqpoint{0pt}{0pt}}{\pgfqpoint{20pt}{20pt}}{\pgfqpoint{20pt}{20pt}}%
{
  \pgfsetlinewidth{6pt}
  %Principal line
  \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
  \pgfpathlineto{\pgfqpoint{20pt}{20pt}}
  %Complement line north east
  \pgfpathmoveto{\pgfqpoint{16pt}{-4pt}}
  \pgfpathlineto{\pgfqpoint{24pt}{4pt}}
  %Complement line south west
  \pgfpathmoveto{\pgfqpoint{-4pt}{16pt}}
  \pgfpathlineto{\pgfqpoint{4pt}{24pt}}
  \pgfusepath{stroke}
}
\begin{document}
    \begin{tikzpicture}[
        %Global config
        baseline=0cm,
        >=latex,
        line width=1pt,
        %Styles
        Brace/.style={
            decorate,
            decoration={
                brace,
                amplitude=2pt,
                raise=-7pt
            }
        },
        Brackets/.style={
            left delimiter={[},
            right delimiter={]}
        },
        every left delimiter/.style={
                xshift=2.5pt,
                xscale=1.5,
                transform shape
            },
            every right delimiter/.style={
                xshift=-2.5pt,
                xscale=1.5,
                transform shape
            },
        Matrix/.style={
            matrix of math nodes,
            text height=1.5ex,
            text depth=0.5ex,
            text width=4ex,
            align=center,
            column sep=7pt,
            row sep=7pt,
            nodes in empty cells,
        },
        HLbox/.style={
            rectangle,
            draw,
            line width=1.5pt,
            fill,
            fill opacity=0.1,   
        },
        HLPbox/.style={
            thick,
            pattern=north east lines b,         
        }
    ]

    \matrix[Matrix] at (0,0) (M1){ % Matrix contents  
    v_{1,1}  & v_{1,2} & v_{1,3} &            &            &            \\
    v_{2,1}  & v_{2,2} & v_{2,3} &            &            &            \\
    v_{3,1}  & v_{3,2} & v_{3,3} & v_{3,4} &            &            \\
                &            & v_{4,3} & v_{4,4} & v_{4,5} & v_{4,6} \\
                &            &            & v_{5,4} & v_{5,5} & v_{5,6} \\
                &            &            & v_{6,4} & v_{6,5} & v_{6,6} \\
    };

    %Hightlight elements in background layer
    \begin{scope}[on background layer] 
    \node[HLPbox,pattern color=orange!50,draw=orange,inner sep=2pt,fit=(M1-3-3)(M1-4-4)](F){};
    \node[HLbox,mygreen,inner sep=1pt,fit=(M1-1-1)(M1-3-3)](C1){};
    \node[HLbox,cyan,inner sep=1pt,fit=(M1-4-4)(M1-6-6)](C2){};
    \node[HLbox,brown,inner sep=-3pt,fit=(M1-3-1)(M1-3-4)](E1){};
    \node[HLbox,brown,inner sep=-3pt,fit=(M1-4-3)(M1-4-6)](E2){};
    \node[HLbox,mypurple,inner sep= -1pt,fit=(M1-1-3)(M1-4-3)](F1){};
    \node[HLbox,mypurple,inner sep= -1pt,fit=(M1-3-4)(M1-6-4)](F2){};
    \end{scope}

    %Delimiters
    \node[Brackets,inner xsep=-6pt,inner ysep=0.5pt,fit=(M1)](BM1){};
    % Auxiliar to separate external braces
    \node[inner xsep=10pt,inner ysep=10pt,fit=(M1)](AUX){};

    % Drawing the braces.
    %Above
    \draw[Brace] (AUX.90 -| C1.180) -- (AUX.90 -| C1.0) node[midway,above]{$C'$};
    \draw[Brace] (AUX.90 -| C2.180) -- (AUX.90 -| C2.0) node[midway,above]{$C''$};
    %below
    \draw[Brace] (AUX.270 -| F1.0) -- (AUX.270 -| F1.180) node[midway,below]{$F'$};
    \draw[Brace] (AUX.270 -| F2.0) -- (AUX.270 -| F2.180) node[midway,below]{$F''$};
    %Left
    \draw[Brace] (AUX.180 |- C1.270) -- (AUX.180 |- C1.90) node[midway,left]{$B'$};
    \draw[Brace] (AUX.180 |- C2.270) -- (AUX.180 |- C2.90) node[midway,left]{$B''$};
    %Right
    \draw[Brace] (AUX.0 |- E1.90) -- (AUX.0 |- E1.270) node[midway,right]{$E'$};
    \draw[Brace] (AUX.0 |- E2.90) -- (AUX.0 |- E2.270) node[midway,right]{$E''$};

    \end{tikzpicture}
\end{document}

答案4

这是一个使用 的解决方案matrix of nodes。主要困难在于将括号放置在多行或多列中。为此,我使用了一些自定义技巧,并定义了两个pics,称为leftbraceoverbrace,它们根据行和列索引以及标签放置括号。

结果如下:

enter image description here

代码如下:

\documentclass[svgnames]{article}
\usepackage{tikz}
\usetikzlibrary{matrix,patterns,calc}

\pgfdeclarelayer{bg}    % declare background layer

\newdimen\leftpt
\newdimen\righpt
\tikzset{%
  pics/overbrace/.style args={#1,#2,#3}{%
    % a pic for putting an underbrace under certain columns
    % #1 = left column
    % #2 = right column index
    % #3 = label text
    code = {
       \pgfextractx\leftpt{\pgfpointanchor{M-1-#1}{north west}}  % x-coords of columns
       \pgfextractx\righpt{\pgfpointanchor{M-1-#2}{north east}}
       % draw the delimiter with the correct width
       \node[rectangle, above delimiter={\{}, minimum width=\the\dimexpr\righpt-\leftpt+1pt,
             label={[yshift=2mm]above:$\scriptscriptstyle #3$}]
             at ($ (M-1-#1)!0.5!(M-1-#2)+(0,0.2) $){};
       }
   },
   pics/leftbrace/.style args={#1,#2,#3}{%
   % a pic for putting a brace to the left of certain rows
   % #1 = top row index
   % #2 = bottom row index
   % #3 = label text
   code = {
       \pgfextracty\leftpt{\pgfpointanchor{M-#1-1}{north west}}  % y-coords of columns
       \pgfextracty\righpt{\pgfpointanchor{M-#2-1}{south west}}
       % draw the delimiter with the correct width
       \node[rectangle, left delimiter={\{}, minimum height=\dimexpr\leftpt-\righpt+1pt,
             label={[xshift=-2mm]left:$\scriptscriptstyle #3$}]
             at ($ (M-#1-1)!0.5!(M-#2-1)+(-0.6,0) $){};
       }
   },
}

\begin{document}

\begin{center}
  \pgfdeclarelayer{purple}
  \pgfdeclarelayer{brown}
  \pgfdeclarelayer{orange}
  \pgfsetlayers{purple,brown,orange,main}  % set the order of the layers (main is the standard layer)
  \begin{tikzpicture}[draw/.append style={thick}]
    \matrix (M)[matrix of math nodes, nodes in empty cells,
                left delimiter={[},
                right delimiter={]},
    ]{
         v_{1,1} & v_{1,2} & v_{1,3} &         &         &   \\
         v_{2,1} & v_{2,2} & v_{2,3} &         &         &   \\
         v_{3,1} & v_{3,2} & v_{3,3} & v_{3,4} &         &   \\
                 &         & v_{4,3} & v_{4,4} & v_{4,5} & v_{4,6} \\
                 &         &         & v_{5,4} & v_{5,5} & v_{5,6}   \\
                 &         &         & v_{6,4} & v_{6,5} & v_{6,6} \\
     };
     \pic{leftbrace={1,3,B'}};
     \pic{leftbrace={4,6,B''}};
     \pic{overbrace={1,3,C'}};
     \pic{overbrace={4,6,C''}};
     \node[minimum height=2mm, right delimiter={\}},
           label={[xshift=1mm,yshift=0.6mm]right:$\scriptscriptstyle E'$}] at ($ (M-3-6)+(0.5,0) $){};
     \node[minimum height=2mm, right delimiter={\}},
           label={[xshift=1mm,yshift=0.6mm]right:$\scriptscriptstyle E''$}] at ($ (M-4-6)+(0.5,0) $){};
     \node[minimum width=6mm, below delimiter={\}},
           label={[yshift=-1mm]below:$\scriptscriptstyle F'$}] at ($ (M-6-3)+(0,-0.2) $){};
     \node[minimum width=6mm, below delimiter={\}},
           label={[yshift=-1mm]below:$\scriptscriptstyle F''$}] at ($ (M-6-4)+(0,-0.2) $){};
     \draw[ForestGreen] (M-1-1.north west) rectangle (M-3-3.south east);
     \draw[cyan] (M-4-4.north west) rectangle (M-6-6.south east);
     \begin{pgfonlayer}{purple}    % select the background layer
       \draw[BlueViolet,fill=LightPink,opacity=0.5]
          ($ (0.04,-0.04)+(M-1-3.north west) $) rectangle ($ (-0.04,0.04)+(M-4-3.south east) $);
       \draw[BlueViolet,fill=LightPink,opacity=0.5]
          ($ (0.04,-0.04)+(M-3-4.north west) $) rectangle ($ (-0.04,0.04)+(M-6-4.south east) $);
     \end{pgfonlayer}
     \begin{pgfonlayer}{brown}    % select the background layer
       \draw[FireBrick,fill=Moccasin,opacity=0.5]
         ($ (0.08,-0.08)+(M-3-1.north west) $) rectangle ($ (-0.08,0.08)+(M-3-4.south east) $);
       \draw[FireBrick,fill=Moccasin,opacity=0.5]
         ($ (0.08,-0.08)+(M-4-3.north west) $) rectangle ($ (-0.08,0.08)+(M-4-6.south east) $);
     \end{pgfonlayer}
     \begin{pgfonlayer}{orange}    % select the background layer
       \draw[orange, pattern=north east lines, pattern color=orange, opacity=0.5]
         ($ (0.04,-0.04)+(M-3-3.north west) $) rectangle ($ (-0.04,0.04)+(M-4-4.south east) $);
     \end{pgfonlayer}
  \end{tikzpicture}
\end{center}

\end{document}

相关内容