[Tex/LaTex] Tikzpicture and matrix

matricestikz-pgf

I want use tikzpicture for draw my matrix, U=[matrix], using this code

\begin{align*}
U&=
\begin{tikzpicture}[decoration=brace]
\matrix (m)[matrix of math nodes,left delimiter=[,right delimiter={]},ampersand replacement=\&] {
    \dfrac{2}{N}-1 \& \dfrac{2}{N} \& \cdots \& \dfrac{2}{N} \& \cdots\& \dfrac{2}{N} \\
    \vdots \& \vdots \& \ddots \& \cdots \& \vdots \& \vdots \\
    \,\,\,\,\,\dfrac{2}{N}\,\,\,\, \& \dfrac{2}{N} \& \dfrac{2}{N} \& \dfrac{2}{N}-1 \& \cdots \& \dfrac{2}{N} \\
    \vdots \& \vdots \& \vdots \& \vdots \& \ddots \& \vdots\\
    \dfrac{2}{N} \& \dfrac{2}{N} \& \cdots \& \dfrac{2}{N} \& \cdots  \& \dfrac{2}{N}-1\\
};
    \draw[decorate,transform canvas={xshift=-1.4em},thick] (m-3-1.south west) -- node[left=2pt] {$m$} (m-1-1.north west);
    \draw[decorate,transform canvas={yshift=0.5em},thick] (m-1-1.north west) -- node[above=2pt] {$m$} (m-1-4.north east);
\end{tikzpicture}
\end{align*}

but I can not get align U=. How I will be able to make this?

enter image description here

Best Answer

Simply add the baseline option to tikzpicture; I also did some other modifications to improve your code (in particular, now the braces are perfectly horizontal and vertical):

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,matrix}

\tikzset{ 
table/.style={
  matrix of math nodes,
  row sep=-\pgflinewidth,
  column sep=-\pgflinewidth,
  nodes={rectangle,text width=3em,align=center},
  text depth=1.25ex,
  text height=2.5ex,
  nodes in empty cells,
  left delimiter=[,
  right delimiter={]},
  ampersand replacement=\&
}
}

\begin{document}

\[
U=
\begin{tikzpicture}[baseline,decoration=brace]
\matrix (m) [table] {
    \dfrac{2}{N}-1 \& \dfrac{2}{N} \& \cdots \& \dfrac{2}{N} \& \cdots\& \dfrac{2}{N} \\
    \vdots \& \vdots \& \ddots \& \cdots \& \vdots \& \vdots \\
    \,\,\,\,\,\dfrac{2}{N}\,\,\,\, \& \dfrac{2}{N} \& \dfrac{2}{N} \& \dfrac{2}{N}-1 \& \cdots \& \dfrac{2}{N} \\
    \vdots \& \vdots \& \vdots \& \vdots \& \ddots \& \vdots\\
    \dfrac{2}{N} \& \dfrac{2}{N} \& \cdots \& \dfrac{2}{N} \& \cdots  \& \dfrac{2}{N}-1\\
};
    \draw[decorate,transform canvas={xshift=-1.4em},thick] (m-3-1.south west) -- node[left=2pt] {$m$} (m-1-1.north west);
    \draw[decorate,transform canvas={yshift=0.5em},thick] (m-1-1.north west) -- node[above=2pt] {$m$} (m-1-4.north east);
\end{tikzpicture}
\]

\end{document}

enter image description here

And here's a TikZ-free possibility, using blkarray and bigdelim:

\documentclass{article}
\usepackage{amsmath}
\usepackage{multirow,bigdelim,blkarray}

\newcommand\overmat[3][0pt]{%
  \makebox[0pt][l]{$\smash{\overbrace{\phantom{%
    \begin{matrix}\phantom{\rule{0pt}{#1}}#3\end{matrix}}}^{#2}}$}#3}

\begin{document}

\[
U =
\begin{blockarray}{@{}r[cccccc]}
\\[-1ex]
\ldelim\{{4}{14pt}[$m$] 
 & \overmat[27pt]{\textstyle m}{\dfrac{2}{N}-1 & \dfrac{2}{N} & \cdots & \dfrac{2}{N}\qquad} & \cdots& \dfrac{2}{N} 
\\    & \vdots & \vdots & \ddots & \cdots & \vdots & \vdots 
\\    & \,\,\,\,\,\dfrac{2}{N}\,\,\,\, & \dfrac{2}{N} & \dfrac{2}{N} & \dfrac{2}{N}-1 & \cdots & \dfrac{2}{N} 
\\    & \vdots & \vdots & \vdots & \vdots & \ddots & \vdots
\\    & \dfrac{2}{N} & \dfrac{2}{N} & \cdots & \dfrac{2}{N} & \cdots  & \dfrac{2}{N}-1
\\[2ex]
\end{blockarray}
\]

\end{document}

enter image description here

Related Question