6

I want to display the structure of a matrix as shown in the image below:

enter image description here

The following code shows the structure of the matrix, without the underbraces:

\documentclass{standalone}

\usepackage{amsmath}

\begin{document}
$\displaystyle
\begin{pmatrix}
  1 & 1 & \ldots & 1 \\
    & 1 & \ldots & 1 & 1 \\
    &   & \ddots & \\
    &   &        & 1 & \ldots & 1
\end{pmatrix}
$
\end{document}

Here is the output:

enter image description here

How do I typeset the desired matrix with underbraces?

6

A solution using a variant of \tikzmark.

Code

\documentclass[border=5pt]{standalone}

\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

\newcommand\tikzmark[2][]{\tikz[remember picture,baseline=(#1.base)]\node[inner sep=0,outer sep=0](#1){#2};}

\begin{document}
$\displaystyle
\begin{pmatrix}
  \tikzmark[1-1]{1} & 1 & \ldots & \tikzmark[1-n]{1} \\[2ex]
    & \tikzmark[2-1]{1} & \ldots & 1 & \tikzmark[2-n]{1} \\[2ex]
    &   & \ddots & \\[2ex]
    &   &        & \tikzmark[n-1]{1} & \ldots & \tikzmark[n-n]{1}
\end{pmatrix}
$
\foreach \i in {1,2,n}
\tikz[remember picture,overlay]\draw[decorate,decoration={brace,amplitude=3pt,mirror}](\i-1.south west)--node[below]{$s$}(\i-n.south east);
\end{document}

Output

enter image description here


Or a full TikZ solution (without using pmatrix)

Code

\documentclass[border=5pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,matrix}

\begin{document}
\begin{tikzpicture}[every left delimiter/.style={xshift=1ex},every right delimiter/.style={xshift=-1ex}]
  \matrix(m)[matrix of math nodes,
    left delimiter=(,
    right delimiter=),
    row sep=2ex
  ]{
    |[name=1-1]|1 & 1             & \ldots & |[name=1-n]|1                          \\
                  & |[name=2-1]|1 & \ldots & 1             & |[name=2-n]|1          \\
                  &               & \ddots &                                        \\
                  &               &        & |[name=n-1]|1 & \ldots & |[name=n-n]|1 \\
  };
  \foreach \i in {1,2,n}
  \draw[decorate,decoration={brace,amplitude=3pt,mirror}](\i-1.south west)--node[below=1pt]{$s$}(\i-n.south east);
\end{tikzpicture}
\end{document}

Output

enter image description here

  • I am using the first solution, but I want to move the underbrace a little bit lower. How do I do this? I tried inserting "below=3pt" but that only moves the "s" lower. – I Like to Code Nov 21 '13 at 15:59
  • 1
    @ILiketoCode: in the definition of \tikzmark, add the option text depth=3pt should do the trick: \node[inner sep=0,outer sep=0,text depth=3pt](#1){#2}; – Herr K. Nov 21 '13 at 16:12
  • Indeed, this shifts the underbrace lower. Thank you. – I Like to Code Nov 21 '13 at 16:26
6

A variation on the other answer of mine to a similar problem in Underbrace in a matrix

\documentclass{standalone}
\usepackage{amsmath,mathtools}

\newcommand{\blockB}[1]{
  \underbrace{\!\!\begin{matrix}1 & \cdots & 1\end{matrix}\!\!}_{#1\mathstrut}
}

\begin{document}
$
  \begin{pmatrix}
  1 & \mathrlap{\blockB{k}} \\
  & 1 & \mathrlap{\blockB{k}} \\
  && 1 & \mathrlap{\blockB{k}} \\
  &&&& \ddots \\
  &&&&& 1 & \blockB{k}
  \end{pmatrix}
$
\end{document}

enter image description here

If you want the brace to span all the block, some more tricks are needed.

\documentclass[border=5]{standalone}
\usepackage{amsmath,mathtools}

\newcommand{\blockC}[1]{
  \,\,\underbrace{\!\!\begin{matrix}1 & 1 & \cdots & 1\end{matrix}\!\!}_{#1\mathstrut}\,\,
}

\begin{document}
$
  \begin{pmatrix}
  \hphantom{1}\mathrlap{\blockC{k}} \\
  & \hphantom{1}\mathrlap{\blockC{k}} \\
  && \hphantom{1}\mathrlap{\blockC{k}} &\hphantom{1} \\
  &&&& \ddots \\
  &&&&& \blockC{k}
  \end{pmatrix}
$
\end{document}

I use some \hphantom{1} to ensure correct alignment: they give some width to the cells.

enter image description here

  • Should't the brace start under the first 1? – Tom Bombadil Nov 20 '13 at 22:04
  • @TomBombadil Oh, you're right! – egreg Nov 20 '13 at 22:05
  • Or you change k to k-1 ;) – Tom Bombadil Nov 20 '13 at 22:07
6

Here is a quick take on what might be possible if you're not really interested in generalization:

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\newcommand{\mydots}[1]{\makebox[0pt][l]{$\underbrace{1\ 1\ \cdots\ 1}_{#1}$}}
\begin{document}
\[
  \begin{pmatrix}
    \mydots{s} & \\
    & \hspace*{3em}\mydots{s} & \\
    & & \hspace*{3em}\ddots & \\
    & & & \mydots{s} & \hspace{3em}
  \end{pmatrix}
\]
\end{document}

The idea is to set the construction (the \underbrace structure) with a right overlap (not really necessary) and space appropriately.

2

I would use a shorthand to clean up the notation a little

\documentclass{article}
\usepackage{mathtools,bbm}%Use your favorite font for bboard number


\begin{document}
\noindent
If someone defines $\mathbbm{1}$ as all-ones vector,
\[
  \begin{pmatrix}
  1 & \mathbbm{1}^T_k \\
  & 1 & \mathbbm{1}^T_k \\
  && 1 &  \mathbbm{1}^T_k \\
  &&& \ddots & \ddots \\
  &&&& 1 & \mathbbm{1}^T_k
  \end{pmatrix}
\]
\end{document}

enter image description here

If you decide to load TikZ then there is no excuse for using those \...dots family. They have been used in the absence of graphics tools. Now you have the monster onboard, I would suggest not being conservative and using that monster efficiently.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.