6

I have a matrix containing the values 0 and 1. The first column contains n_1 values of 1 and the rest is 0. The second column begins with n_1 values of 0, n_2 values of 1 and then 0 for the rest. I want to make { outside my matrix, to write n_1, n_2, etc., but I want the bracket { to expand over several lines. How can I do that?

\documentclass[11pt]{memoir}
\usepackage{amsmath}
\begin{document}

\begin{align}
\begin{pmatrix} 
1           &           0       &       0       &   \cdots      & 0     &     0     \\    
\vdots      &       \vdots      &       \vdots  &               & \vdots & \vdots \\        
 1          &           0       &       0       & \cdots    &0  & 0     \\
0           &           1       &       0       &   \cdots      &0& 0   \\
\vdots      &       \vdots      &       \vdots  &           &\vdots& \vdots \\
0           &           1       &       0       &   \cdots      &0& 0   \\
\vdots & \vdots & \vdots & & \vdots &\vdots \\
0           &           0       &       0       &   \cdots      &0& 1   \\
\vdots      &       \vdots      &       \vdots  &           &\vdots& \vdots \\
0           &           0       &       0       &   \cdots      &0& 1   \\
\end{pmatrix}
\end{align}
\end{document}

Enter image description here

Enter image description here

  • I would like to have the { expand over three rows, and not a text to every row. Is that possible? – Camilla Jul 2 '15 at 11:19
  • @LaRiFaRi none of those actually show what the OP is after. She's looking for braces spanning the four subparts of the matric in the Image I've just added. None of the examples you link to actually show this. I think we need some tikz – daleif Jul 2 '15 at 11:28
  • I don't think that this is a duplicate because the OP wants a bracket to cover several rows of the matrix and this isn't done any of the linked to posts, although as LaRiFaRi says, blkarray will help – Andrew Jul 2 '15 at 11:29
  • @Camilla, maybe you draw a little picture of what you want. I think, this explains more than all the words. Thanks. – LaRiFaRi Jul 2 '15 at 11:37
  • 3
    I made a little drawing of what I want - I hope it helps explaining the problem. – Camilla Jul 2 '15 at 11:52
6

A hackish solution: In the bottom row of the submatrix (or third, sixth, and last row of the matrix), \vadjust puts stuff after that row.

Then the brace is drawn using an invisible matrix of three rows to get the right height of the brace (\vphantom). This is put into a \vbox to 0pt to avoid increasing the line skip between the insertion via \vadjust. Also the brace is moved to the left (\llap{...\kern.5em}).

\documentclass[11pt]{memoir}
\usepackage{amsmath}

\begin{document}
\begin{align}
  \newcommand*{\AddLeft}[1]{%
    \vadjust{%
      \vbox to 0pt{%
        \vss
        \llap{$%
          n_{#1}\left\{
            \vphantom{
              \begin{matrix}1\\\vdots\\0\end{matrix}
            }
          \right.\kern-\nulldelimiterspace
          \kern0.5em
        $}%
        \kern0pt
      }%
    }%  
  }
  \begin{pmatrix}
    1      & 0      & 0      & \cdots & 0      & 0      \\
    \vdots & \vdots & \vdots &        & \vdots & \vdots \\
    \AddLeft{1}
    1      & 0      & 0      & \cdots & 0      & 0      \\
    0      & 1      & 0      & \cdots & 0      & 0      \\
    \vdots & \vdots & \vdots &        & \vdots & \vdots \\
    \AddLeft{2}
    0      & 1      & 0      & \cdots & 0      & 0      \\
    \vdots & \vdots & \vdots &        & \vdots & \vdots \\
    0      & 0      & 0      & \cdots & 0      & 1      \\
    \vdots & \vdots & \vdots &        & \vdots & \vdots \\
    \AddLeft{p}
    0      & 0      & 0      & \cdots & 0      & 1      \\
  \end{pmatrix}
\end{align}
\end{document}

Result

3

Here is a solution hacked together using tikz

\documentclass[11pt]{memoir}
\usepackage{amsmath}

\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathreplacing}
\newcommand\REM[2]{\tikz[remember picture,inner sep=0pt] \node (#1) {#2};}


\begin{document}

\begin{align}
\begin{pmatrix} 
\REM{A}{1}           &           0       &       0       &   \cdots      & 0     &     0     \\    
\vdots      &       \vdots      &       \vdots  &               & \vdots & \vdots \\        
 \REM{B}{1}          &           0       &       0       & \cdots    &0  & 0     \\
\REM{C}{0}           &           1       &       0       &   \cdots      &0& 0   \\
\vdots      &       \vdots      &       \vdots  &           &\vdots& \vdots \\
\REM{D}{0}          &           1       &       0       &   \cdots      &0& 0   \\
\vdots & \vdots & \vdots & & \vdots &\vdots \\
\REM{E}{0}           &           0       &       0       &   \cdots      &0& 1   \\
\vdots      &       \vdots      &       \vdots  &           &\vdots& \vdots \\
\REM{F}{0}           &           0       &       0       &   \cdots      &0& 1   \\
\end{pmatrix}
\begin{tikzpicture}[remember picture,overlay]
  \draw[decorate,decoration={brace,mirror}] 
  ($(A)+(-1,0)$) -- ($(B)+(-1,0)$)
  node[midway,left=2pt] {$n_1$} ;
  \draw[decorate,decoration={brace,mirror}] 
  ($(C)+(-1,0)$) -- ($(D)+(-1,0)$)
  node[midway,left=2pt] {$n_2$} ;
  \draw[decorate,decoration={brace,mirror}] 
  ($(E)+(-1,0)$) -- ($(F)+(-1,0)$)
  node[midway,left=2pt] {$n_p$} ;
\end{tikzpicture}
\end{align}
\end{document}

enter image description here

3

Don't use confusing ellipses, for example, the last 1 of your n_2 block turns into zero after the ellipses. Actually, if you can, always avoid ellipses. Your matrix has a very distinguished structured and make it obvious to your readers. They can construct the matrix when they know the rule. But they can't read the rule from the construction easily.

Here is one option:

\documentclass{article}
\usepackage{,amsfonts,mathtools,bm}
\DeclarePairedDelimiter{\diagfences}{(}{)}
\newcommand{\diag}{\operatorname{diag}\diagfences}

\begin{document}
Let $\bm{1}_{n_i}$ be the vector with all entries are equal to $1$. Then $M$ is defined as
\[
M = \diag{\bm{1}_{n_1},\bm{1}_{n_2},\cdots,\bm{1}_{n_p}}.
\]
\end{document}

enter image description here

  • oops I forgot to add ...with all entries are equal to $1$ with length $n_i$... – percusse Jul 2 '15 at 12:53
  • That is a nice way of writing it! I think I will use that :) – Camilla Jul 2 '15 at 14:07
2

For a one off display, here's a hack that exploits the fact that the braces should be as high as a three line matrix.

\documentclass[11pt]{memoir}
\usepackage{amsmath}

\newcommand{\nrow}[1]{%
  \relax
  \vcenter to 0pt{%
    \vss
    \kern-1.5ex
    \llap{$#1\left\{\vphantom{\begin{matrix}0\\\vdots\\0\end{matrix}}\right.\kern.75em$}%
    \vss
  }%
}

\begin{document}
\begin{center}
XXXXXXXXXXXXXXX
\end{center}
\begin{equation}
\hphantom{n_p\kern.75em}
\begin{pmatrix}
  1      & 0      & 0      & \cdots & 0      & 0      \\
  \nrow{n_1}\vdots & \vdots & \vdots &        & \vdots & \vdots \\
  1      & 0      & 0      & \cdots & 0      & 0      \\
  0      & 1      & 0      & \cdots & 0      & 0      \\
  \nrow{n_2}\vdots & \vdots & \vdots &        & \vdots & \vdots \\
  0      & 1      & 0      & \cdots & 0      & 0      \\
  \vdots & \vdots & \vdots &        & \vdots & \vdots \\
  0      & 0      & 0      & \cdots & 0      & 1      \\
  \nrow{n_p}\vdots & \vdots & \vdots &        & \vdots & \vdots \\
  0      & 0      & 0      & \cdots & 0      & 1      \\
  \end{pmatrix}
\end{equation}
\end{document}

The string of X's is just to show good centering.

enter image description here

  • @HeikoOberdiek Yes, I did. I took your example as a model and forgot to do a correct “copy”. – egreg Jul 2 '15 at 21:57
1

Make a matrix to put the braces etc in:

\documentclass[11pt]{memoir}
\usepackage{amsmath}
\begin{document}
    \begin{align*}
% % %
        \begin{matrix}
            n_1 = \left\{\begin{matrix}\\\\\\\end{matrix}\right.    \\
            n_2 = \left\{\begin{matrix}\\\\\\\end{matrix}\right.    \\
                                                                    \\[3ex]
            n_p =\left\{\begin{matrix}\\\\\\\end{matrix}\right.
        \end{matrix}
% % %
        \begin{pmatrix}
        1       & 0      & 0       & \cdots  & 0       & 0      \\
        \vdots  & \vdots & \vdots  &         & \vdots  & \vdots \\
         1      & 0      & 0       & \cdots  & 0       & 0      \\
        0       & 1      & 0       & \cdots  & 0       & 0      \\
        \vdots  & \vdots & \vdots  &         & \vdots  & \vdots \\
        0       & 1      & 0       & \cdots  & 0       & 0      \\
        \vdots  & \vdots & \vdots  &         & \vdots  & \vdots \\
        0       & 0      & 0       & \cdots  & 0       & 1      \\
        \vdots  & \vdots & \vdots  &         & \vdots  & \vdots \\
        0       & 0      & 0       & \cdots  & 0       & 1      \\
        \end{pmatrix}
    \end{align*}
\end{document}

enter image description here

  • The n2 part should be a little lower. – Heiko Oberdiek Jul 2 '15 at 21:57
  • then specify ...\right. \\[4.5ex] at the end of the n1 line – Elements in Space Jul 3 '15 at 7:19

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.