Curly braces adjustment in tikz?

I am using help from this answer for my writing without much understanding of Tikz package. I need to do following adjustment in the above diagram:

1. downward movement of curly braces
2. A small gap between the curly braces

Any help would be appreciated.

\documentclass[11pt,twoside,a4paper]{article}
\usepackage{braket,amsmath,amssymb}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning}

\begin{document}
\begin{equation}
Q=\begin{tikzpicture}[baseline=(m-3-1.base)]
\matrix [matrix of math nodes,left delimiter=(,right delimiter=),row sep=0.5cm,column sep=0.5cm] (m) {
1&2&3&4&3&4 \\
1&2&3&4&3&4 \\
1&2&3&4&3&4 \\
1&2&3&4&3&4 \\
1&2&3&4&3&4 \\
1&2&3&4&3&4 \\};

\draw[solid] ($0.5*(m-1-2.north east)+0.5*(m-1-3.north west)$) --
($0.5*(m-6-3.south east)+0.5*(m-6-2.south west)$);
\draw[solid] ($0.5*(m-1-4.north east)+0.5*(m-1-5.north west)$) --
($0.5*(m-6-5.south east)+0.5*(m-6-4.south west)$);

\draw[solid] ($0.5*(m-2-1.south west)+0.5*(m-3-1.north west)$) --
($0.5*(m-2-6.south east)+0.5*(m-3-6.north east)$);

\draw[solid] ($0.5*(m-4-1.south west)+0.5*(m-5-1.north west)$) --
($0.5*(m-4-6.south east)+0.5*(m-5-6.north east)$);

\node[above=10pt of m-1-1] (top-1) {$q_s$};
\node[above=10pt of m-1-2] (top-2) {$p_s$};
\node[above=10pt of m-1-3] (top-3) {$q_{m_1}$};
\node[above=10pt of m-1-4] (top-4) {$p_{m_1}$};
\node[above=10pt of m-1-5] (top-5) {$q_{m_2}$};
\node[above=10pt of m-1-6] (top-6) {$p_{m_2}$};

\node[rectangle,above delimiter=\{] (del-top-1) at ($0.5*(top-1.south) +0.5*(top-2.south)$) {\tikz{\path (top-1.south west) rectangle (top-2.north east);}};
\node[above=10pt] at (del-top-1.north) {System};

\node[rectangle,above delimiter=\{] (del-top-2) at ($0.5*(top-3.south) +0.5*(top-4.south)$) {\tikz{\path (top-3.south west) rectangle (top-4.north east);}};
\node[above=10pt] at (del-top-2.north) {Meter 1};

\node[rectangle,above delimiter=\{] (del-top-3) at ($0.5*(top-5.south) +0.5*(top-6.south)$) {\tikz{\path (top-5.south west) rectangle (top-6.north east);}};
\node[above=10pt] at (del-top-3.north) {Meter 2};

\node[right=12pt of m-1-6] (left-1) {$q_s$};
\node[right=12pt of m-2-6] (left-1) {$p_s$};
\node[right=12pt of m-3-6] (left-1) {$q_{m_1}$};
\node[right=12pt of m-4-6] (left-1) {$p_{m_1}$};
\node[right=12pt of m-5-6] (left-1) {$q_{m_2}$};
\node[right=12pt of m-6-6] (left-1) {$p_{m_2}$};

\end{tikzpicture}
\end{equation}

\end{document}

Since you are already loading decorations.pathreplacing, you could use it to draw the braces. I moved them down and added a small gap between them. I also used scopes with text width and text depth to make things a bit more symmetric.

\documentclass[11pt,twoside,a4paper]{article}
\usepackage{braket,amsmath,amssymb}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning}

\begin{document}
\begin{equation}
Q=\begin{tikzpicture}[baseline=(m-3-1.base)]
\matrix [matrix of math nodes,left delimiter=(,right delimiter=),row sep=0.5cm,column sep=0.5cm] (m) {
1&2&3&4&3&4 \\
1&2&3&4&3&4 \\
1&2&3&4&3&4 \\
1&2&3&4&3&4 \\
1&2&3&4&3&4 \\
1&2&3&4&3&4 \\};

\draw[solid] ($0.5*(m-1-2.north east)+0.5*(m-1-3.north west)$) --
($0.5*(m-6-3.south east)+0.5*(m-6-2.south west)$);
\draw[solid] ($0.5*(m-1-4.north east)+0.5*(m-1-5.north west)$) --
($0.5*(m-6-5.south east)+0.5*(m-6-4.south west)$);

\draw[solid] ($0.5*(m-2-1.south west)+0.5*(m-3-1.north west)$) --
($0.5*(m-2-6.south east)+0.5*(m-3-6.north east)$);

\draw[solid] ($0.5*(m-4-1.south west)+0.5*(m-5-1.north west)$) --
($0.5*(m-4-6.south east)+0.5*(m-5-6.north east)$);

\begin{scope}[nodes={text width=1.1em,align=center}]
\node[above=10pt of m-1-1] (top-1) {$q_s$};
\node[above=10pt of m-1-2] (top-2) {$p_s$};
\node[above=10pt of m-1-3] (top-3) {$q_{m_1}$};
\node[above=10pt of m-1-4] (top-4) {$p_{m_1}$};
\node[above=10pt of m-1-5] (top-5) {$q_{m_2}$};
\node[above=10pt of m-1-6] (top-6) {$p_{m_2}$};
\end{scope}

\coordinate[above=3pt of top-1] (aux);
\begin{scope}[nodes={text depth=0.25ex}]
\draw[thick,decorate,decoration=brace] (top-1.west|-aux) -- (top-2.east|-aux)
node[midway,above=0.1ex] {System};
\draw[thick,decorate,decoration=brace] (top-3.west|-aux) -- (top-4.east|-aux)
node[midway,above=0.1ex] {Meter 1};
\draw[thick,decorate,decoration=brace] (top-5.west|-aux) -- (top-6.east|-aux)
node[midway,above=0.1ex] {Meter 2};
\end{scope}

\node[right=12pt of m-1-6] (left-1) {$q_s$};
\node[right=12pt of m-2-6] (left-1) {$p_s$};
\node[right=12pt of m-3-6] (left-1) {$q_{m_1}$};
\node[right=12pt of m-4-6] (left-1) {$p_{m_1}$};
\node[right=12pt of m-5-6] (left-1) {$q_{m_2}$};
\node[right=12pt of m-6-6] (left-1) {$p_{m_2}$};
\end{tikzpicture}
\end{equation}
\end{document} This is really just for fun, which is why this is a community wiki. It does not really bring advantages in this case, but in general this might. (The thing that is a conceivable improvement to my above answer is that the baseline is arguably better. I do not want to update my above answer for reasons several more experienced users can guess.) The things this answer is about are the possibilities to

1. draw the dividing lines with a style;
2. fill the matrix programmatically.

This may pay off if you have a much larger matrix.

\documentclass[11pt,twoside,a4paper]{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning}
\tikzset{my matrix dividers/.style={execute at end matrix={
\pgfmathtruncatemacro{\Xmax}{\the\pgfmatrixcurrentcolumn/2-1}
\pgfmathtruncatemacro{\Ymax}{\the\pgfmatrixcurrentrow/2-1}
\foreach \XX in {1,...,\Xmax}
{\draw ($(\tikzmatrixname-1-\the\numexpr2*\XX\relax.north east)!0.5! (\tikzmatrixname-1-\the\numexpr2*\XX+1\relax.north west)$) coordinate(aux) --
($(\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\numexpr2*\XX\relax.south east)!0.5! (\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\numexpr2*\XX+1\relax.south west)$);}
\foreach \YY in {1,...,\Ymax}
{\draw ($(\tikzmatrixname-\the\numexpr2*\YY\relax-1.south west)!0.5! (\tikzmatrixname-\the\numexpr2*\YY+1\relax-1.north west)$) coordinate(aux) --
($(\tikzmatrixname-\the\numexpr2*\YY\relax-\the\pgfmatrixcurrentcolumn.south east)!0.5! (\tikzmatrixname-\the\numexpr2*\YY+1\relax-\the\pgfmatrixcurrentcolumn.north east)$);}
}}}
\begin{document}
\begin{equation}
Q=\begin{tikzpicture}[baseline=(X.base)]
\matrix [matrix of nodes,nodes in empty cells,left delimiter=(,right delimiter=),row
sep=0.5cm,column sep=0.5cm,
cells={execute at begin node={%
\ifnum\the\pgfmatrixcurrentcolumn<5
$\the\pgfmatrixcurrentcolumn$%
\else
$\the\numexpr\pgfmatrixcurrentcolumn-2$%
\fi
}},my matrix dividers] (m) {
&&&&& \\
&&&&& \\
&&&&& \\
&&&&& \\
&&&&& \\
&&&&& \\};
\node (X) at (m) {\phantom{X}};

\begin{scope}[nodes={text width=1.1em,align=center}]
\node[above=10pt of m-1-1] (top-1) {$q_s$};
\node[above=10pt of m-1-2] (top-2) {$p_s$};
\node[above=10pt of m-1-3] (top-3) {$q_{m_1}$};
\node[above=10pt of m-1-4] (top-4) {$p_{m_1}$};
\node[above=10pt of m-1-5] (top-5) {$q_{m_2}$};
\node[above=10pt of m-1-6] (top-6) {$p_{m_2}$};
\end{scope}

\coordinate[above=3pt of top-1] (aux);
\begin{scope}[nodes={text depth=0.25ex}]
\draw[thick,decorate,decoration=brace] (top-1.west|-aux) -- (top-2.east|-aux)
node[midway,above=0.1ex] {System};
\draw[thick,decorate,decoration=brace] (top-3.west|-aux) -- (top-4.east|-aux)
node[midway,above=0.1ex] {Meter 1};
\draw[thick,decorate,decoration=brace] (top-5.west|-aux) -- (top-6.east|-aux)
node[midway,above=0.1ex] {Meter 2};
\end{scope}

\node[right=12pt of m-1-6] (left-1) {$q_s$};
\node[right=12pt of m-2-6] (left-1) {$p_s$};
\node[right=12pt of m-3-6] (left-1) {$q_{m_1}$};
\node[right=12pt of m-4-6] (left-1) {$p_{m_1}$};
\node[right=12pt of m-5-6] (left-1) {$q_{m_2}$};
\node[right=12pt of m-6-6] (left-1) {$p_{m_2}$};
\end{tikzpicture}
\end{equation}
\end{document} Ok, now i understand. You wanted to place the braces that are above the matrix closer to System texts, etc. and making sure that these braces do not overlap each other.

The problem you have is the rectangle you placed inside the nodes:

\node[rectangle,draw,fill= blue!30,opacity=.5,text opacity=1,above delimiter=\{]
(del-top-1) at ($0.5*(top-1.south) +0.5*(top-2.south)$)
{\tikz{\path (top-1.south west) rectangle (top-2.north east);}};% This rectangle creates the problem

This produces a very large rectangle colored in blue in this screenshot: It is much easier to use the fit library to do the same thing.

\node[rectangle,above delimiter=\{,fit=(top-1) (top-2)] (del-top-1) {};
\node[above=10pt] at (del-top-1.north) {System};

And to make the braces smaller, just place the inner sep=0pt option.

\node[above=10pt of m-1-1,inner sep=0pt] (top-1) {$q_s$};
\node[above=10pt of m-1-2,inner sep=0pt] (top-2) {$p_s$};
\node[above=10pt of m-1-3,inner sep=0pt] (top-3) {$q_{m_1}$};
\node[above=10pt of m-1-4,inner sep=0pt] (top-4) {$p_{m_1}$};
\node[above=10pt of m-1-5,inner sep=0pt] (top-5) {$q_{m_2}$};
\node[above=10pt of m-1-6,inner sep=0pt] (top-6) {$p_{m_2}$};

By using the label option, you avoid naming nodes del-top-1, etc and solve the alignment problem with anchor=mid.

Then we get: \documentclass[11pt,twoside,a4paper]{article}
\usepackage{braket,amsmath,amssymb}
\usepackage{tikz}
\usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning,fit}

\begin{document}
\begin{equation}
Q=\begin{tikzpicture}[baseline=(m-3-1.base) ]
\matrix [matrix of math nodes,left delimiter=(,right delimiter=),row sep=0.5cm,column sep=0.5cm
] (m) {
1&2&3&4&3&4 \\
1&2&3&4&3&4 \\
1&2&3&4&3&4 \\
1&2&3&4&3&4 \\
1&2&3&4&3&4 \\
1&2&3&4&3&4 \\};

\draw[solid] ($0.5*(m-1-2.north east)+0.5*(m-1-3.north west)$) --
($0.5*(m-6-3.south east)+0.5*(m-6-2.south west)$);
\draw[solid] ($0.5*(m-1-4.north east)+0.5*(m-1-5.north west)$) --
($0.5*(m-6-5.south east)+0.5*(m-6-4.south west)$);

\draw[solid] ($0.5*(m-2-1.south west)+0.5*(m-3-1.north west)$) --
($0.5*(m-2-6.south east)+0.5*(m-3-6.north east)$);

\draw[solid] ($0.5*(m-4-1.south west)+0.5*(m-5-1.north west)$) --
($0.5*(m-4-6.south east)+0.5*(m-5-6.north east)$);

\node[above=10pt of m-1-1,inner sep=0pt] (top-1) {$q_s$};
\node[above=10pt of m-1-2,inner sep=0pt] (top-2) {$p_s$};
\node[above=10pt of m-1-3,inner sep=0pt] (top-3) {$q_{m_1}$};
\node[above=10pt of m-1-4,inner sep=0pt] (top-4) {$p_{m_1}$};
\node[above=10pt of m-1-5,inner sep=0pt] (top-5) {$q_{m_2}$};
\node[above=10pt of m-1-6,inner sep=0pt] (top-6) {$p_{m_2}$};

%---------------- Use of the label option ---------------%
\node[rectangle,inner sep=0pt,above delimiter=\{,fit=(top-1) (top-2),label={[anchor=mid,yshift=15pt]:System}] {};

\node[rectangle,inner sep=0pt,above delimiter=\{,fit=(top-3) (top-4),label={[anchor=mid,yshift=15pt]:Meter 1}] {};

\node[rectangle,inner sep=0pt,above delimiter=\{,fit=(top-5) (top-6),label={[anchor=mid,yshift=15pt]:Meter 2}] {};
%---------------------------------------------------------

\node[right=12pt of m-1-6] (left-1) {$q_s$};
\node[right=12pt of m-2-6] (left-1) {$p_s$};
\node[right=12pt of m-3-6] (left-1) {$q_{m_1}$};
\node[right=12pt of m-4-6] (left-1) {$p_{m_1}$};
\node[right=12pt of m-5-6] (left-1) {$q_{m_2}$};
\node[right=12pt of m-6-6] (left-1) {$p_{m_2}$};

\end{tikzpicture}
\end{equation}

\end{document}
• Sorry, I was not clear enough. I needed as per @marmot answer. Anyway, thanks for the effort. – Mark Robinson Jul 6 at 6:11
• You wanted to place the braces that are above the matrix closer to System texts, etc. and making sure that these braces do not overlap each other. Is that it? – AndréC Jul 6 at 7:00
• I just updated my answer, is that okay with you now? – AndréC Jul 6 at 7:34
• Thanks for the clear explanation. – Mark Robinson Jul 6 at 14:10
• @MarkRobinson For my opinion I believe, compared to me, that there has been a great deal of effort. I vote +1 for AndréC – Sebastiano Jul 6 at 16:13