4

I have the following matrix:

enter image description here

which is obtained from the following code:

\usetikzlibrary{patterns}
\usetikzlibrary{matrix,decorations.pathreplacing,calc}


%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=8pt,row sep=8pt,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-#2-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);
}


\tikzset{style green/.style={
    set fill color=green!50!lime!60,draw opacity=0.4,
    set border color=green!50!lime!60,fill opacity=0.1,
  },
  style cyan/.style={
    set fill color=cyan!90!blue!60, draw opacity=0.4,
    set border color=blue!70!cyan!30,fill opacity=0.1,
  },
  style orange/.style={
    set fill color=orange!90, draw opacity=0.8,
    set border color=orange!90, fill opacity=0.3,
  },
  style brown/.style={
    set fill color=brown!70!orange!40, draw opacity=0.4,
    set border color=brown, fill opacity=0.3,
  },
  style purple/.style={
    set fill color=violet!90!pink!20, draw opacity=0.5,
    set border color=violet, fill opacity=0.3,    
  },
  kwad/.style={
    above left offset={-0.1,0.23},
    below right offset={0.10,-0.36},
    #1
  },
  pion/.style={
    above left offset={-0.07,0.2},
    below right offset={0.07,-0.32},
    #1
  },
  poz/.style={
    above left offset={-0.03,0.18},
    below right offset={0.03,-0.3},
    #1
  }
}

\[
%    \mathbf{X} = 
    \begin{tikzpicture}[baseline={-0.5ex},mymatrixenv]
        \matrix [mymatrix,inner sep=4pt] (m)  
        {
    \tikzmarkin[kwad=style green]{Prime} v_{1,1}  &  v_{1,2} & \tikzmarkin[pion=style purple]{VL} v_{1,3}   &  \textcolor{white}{v_{1,4}}   &  &  \textcolor{white}{v_{1,6}} \\
    v_{2,1}  & v_{2,2} & v_{2,3} & & &   \\
    \tikzmarkin[poz=style brown]{HL} v_{3,1}  & v_{3,2} & \tikzmarkin[kwad=style orange]{Mix} v_{3,3} \tikzmarkend{Prime} &\tikzmarkin[pion=style purple]{VR} v_{3,4}  \tikzmarkend{HL} & &   \\
    \textcolor{white}{v_{4,1}}    & & \tikzmarkin[poz=style brown]{HR} v_{4,3} \tikzmarkend{VL}& \tikzmarkin[kwad=style cyan]{Bis} v_{4,4} \tikzmarkend{Mix} & v_{4,5}  & v_{4,6} \tikzmarkend{HR}   \\
    & & & v_{5,4} & v_{5,5} & v_{5,6}   \\
    \textcolor{white}{v_{6,1}}  & &  & v_{6,4}  \tikzmarkend{VR} & v_{6,5} & v_{6,6} \tikzmarkend{Bis}  \\    
    };

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

I was trying to change:

\begin{tikzpicture}[baseline={-0.5ex},mymatrixenv]

to

\begin{tikzpicture}[scale=2,baseline={-0.5ex},mymatrixenv]

but without effect.

I also tried this when I import the picture to another document:

\begin{figure}
\centering
\scalebox{2}{
\input{color_matrix3.tikz}
}
\end{figure}

the output was indeed bigger but not centered and latex gave a lot of errors concerning math equations

Martin Scharrer
  • 262,582

1 Answers1

7

Let me start by providing a compilable version of your code. Apart from obvious additions I also guessed some styles from the context, and as any guess my guesses may be wrong. In any case, this is what I got.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns,tikzmark}
\usetikzlibrary{matrix,decorations.pathreplacing,calc}
\usepackage{hf-tikz}


%opening
\title{}
\author{}

\begin{document}

\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=8pt,row sep=8pt,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-#2-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);
}


\tikzset{style green/.style={
    set fill color=green!50!lime!60,draw opacity=0.4,
    set border color=green!50!lime!60,fill opacity=0.1,
  },
  style cyan/.style={
    set fill color=cyan!90!blue!60, draw opacity=0.4,
    set border color=blue!70!cyan!30,fill opacity=0.1,
  },
  style orange/.style={
    set fill color=orange!90, draw opacity=0.8,
    set border color=orange!90, fill opacity=0.3,
  },
  style brown/.style={
    set fill color=brown!70!orange!40, draw opacity=0.4,
    set border color=brown, fill opacity=0.3,
  },
  style purple/.style={
    set fill color=violet!90!pink!20, draw opacity=0.5,
    set border color=violet, fill opacity=0.3,    
  },
  kwad/.style={
    above left offset={-0.1,0.23},
    below right offset={0.10,-0.36},
    #1
  },
  pion/.style={
    above left offset={-0.07,0.2},
    below right offset={0.07,-0.32},
    #1
  },
  poz/.style={
    above left offset={-0.03,0.18},
    below right offset={0.03,-0.3},
    #1
  },set fill color/.code={\pgfkeysalso{fill=#1}},
  set border color/.style={draw=#1}
}

\[
%    \mathbf{X} = 
    \begin{tikzpicture}[baseline={-0.5ex},mymatrixenv]
        \matrix [mymatrix,inner sep=4pt] (m)  
        {
    \tikzmarkin[kwad=style green]{Prime} v_{1,1}  &  v_{1,2} & \tikzmarkin[pion=style purple]{VL} v_{1,3}   &  \textcolor{white}{v_{1,4}}   &  &  \textcolor{white}{v_{1,6}} \\
    v_{2,1}  & v_{2,2} & v_{2,3} & & &   \\
    \tikzmarkin[poz=style brown]{HL} v_{3,1}  & v_{3,2} & \tikzmarkin[kwad=style orange]{Mix} v_{3,3} \tikzmarkend{Prime} &\tikzmarkin[pion=style purple]{VR} v_{3,4}  \tikzmarkend{HL} & &   \\
    \textcolor{white}{v_{4,1}}    & & \tikzmarkin[poz=style brown]{HR} v_{4,3} \tikzmarkend{VL}& \tikzmarkin[kwad=style cyan]{Bis} v_{4,4} \tikzmarkend{Mix} & v_{4,5}  & v_{4,6} \tikzmarkend{HR}   \\
    & & & v_{5,4} & v_{5,5} & v_{5,6}   \\
    \textcolor{white}{v_{6,1}}  & &  & v_{6,4}  \tikzmarkend{VR} & v_{6,5} & v_{6,6} \tikzmarkend{Bis}  \\    
    };

        % 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{document}

enter image description here

As you can see, this does produce a reasonable result, but entirely by accident IMHO. You are nesting tikzpictures. If you were to add something like scale=2, the result will be completely off since some things will be transformed twice. One option to achieve the scaling is to employ adjustbox, as pointed out by Martin Scharrer. I leave it to you or Martin Scharrer to spell this out even more explicitly.

I recommend going another way in which you do not have to nest tikzpictures. This way is IMHO also much more elegant as it does not require any manual adjustments as in the pion style etc. Your matrix is already a matrix of nodes, and there is no need to resort to hf-tikz. You can just use fit instead. Of course, you can shift the contours and adjust their height by playing with xshift, yshift, inner xsep and inner ysep. (I did not clean up your code further e.g. by replacing the \textcolor{white}{...} by their tikz counterparts.) This thing can be scaled just by setting \myscale to the desired value.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.pathreplacing,calc,fit,backgrounds}


%opening
\title{}
\author{}

\begin{document}
\pgfmathsetmacro{\myscale}{2}
\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=8pt,row sep=8pt,nodes={minimum width=20pt,minimum height=10pt,
anchor=center,inner sep=0pt,outer sep=0pt,scale=\myscale,transform shape}}}
\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-#2-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);
}


\tikzset{greenish/.style={
    fill=green!50!lime!60,draw opacity=0.4,
    draw=green!50!lime!60,fill opacity=0.1,
  },
  cyanish/.style={
    fill=cyan!90!blue!60, draw opacity=0.4,
    draw=blue!70!cyan!30,fill opacity=0.1,
  },
  orangeish/.style={
    fill=orange!90, draw opacity=0.8,
    draw=orange!90, fill opacity=0.3,
  },
  brownish/.style={
    fill=brown!70!orange!40, draw opacity=0.4,
    draw=brown, fill opacity=0.3,
  },
  purpleish/.style={
    fill=violet!90!pink!20, draw opacity=0.5,
    draw=violet, fill opacity=0.3,    
  }}


\[
%    \mathbf{X} = 
    \begin{tikzpicture}[baseline={-0.5ex},mymatrixenv]
        \matrix [mymatrix,inner sep=4pt] (m)  
        {
    v_{1,1}  &  v_{1,2} & v_{1,3}   &  \textcolor{white}{v_{1,4}}   &  &  \textcolor{white}{v_{1,6}} \\
    v_{2,1}  & v_{2,2} & v_{2,3} & & &   \\
    v_{3,1}  & v_{3,2} &  v_{3,3} & v_{3,4} & &   \\
    \textcolor{white}{v_{4,1}}    & &  v_{4,3} &  v_{4,4}  & v_{4,5}  & v_{4,6}   \\
    & & & v_{5,4} & v_{5,5} & v_{5,6}   \\
    \textcolor{white}{v_{6,1}}  & &  & v_{6,4}  & v_{6,5} & v_{6,6}   \\    
    };

    \begin{scope}[on background layer,rounded corners]
     \node [fit=(m-1-1) (m-3-3),greenish,inner xsep=1.5pt,inner ysep=2.5pt]{};
     \node [fit=(m-1-3) (m-4-3),purpleish,inner xsep=0.5pt,inner ysep=3.5pt]{};
     \node [fit=(m-3-1) (m-3-4),brownish,inner xsep=0.5pt,inner ysep=1.5pt]{};
     \node [fit=(m-3-3) (m-4-4),orangeish]{};
     \node [fit=(m-3-4) (m-6-5),purpleish,inner xsep=0.5pt,inner ysep=3.5pt,yshift=1pt]{};
     \node [fit=(m-4-3) (m-4-6),brownish]{};
     \node [fit=(m-4-4) (m-6-6),cyanish,inner xsep=1.5pt,inner ysep=0.5pt,xshift=-1pt]{};
    \end{scope}

        % Braces     
    \begin{scope}[every node/.append style={scale=\myscale,transform
    shape},very thick]
        \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{scope} 
\end{tikzpicture}
\]
\end{document}

enter image description here

  • thank you! Do you know how to make borders of colorful regions ticker (as on my picture)? – Filip Parker Dec 30 '18 at 22:58
  • 1
    @FilipParker Sure. Just replace \begin{scope}[on background layer,rounded corners] by \begin{scope}[on background layer,rounded corners,every node/.append style={line width=2pt}]. –  Dec 30 '18 at 23:15
  • I am trying to understand your code. Is it true that the macro named \mymatrixbraceright places braces on the left and \mymatrixbraceleft places braces on the right??? – TeX Apprentice Dec 16 '22 at 19:59