2

How can I modify the code below to get the text centered over the matrix columns with 1s instead of aligned to the left edge of the columns.

Below is the MWE code and output.

\documentclass{article}

\usepackage{amsmath}

% command for overbrace in matrix
\newcommand\bovermat[2]{%
  \makebox[0pt][l]{$\smash{\overbrace{\phantom{%
    \begin{matrix}#2\end{matrix}}}^{#1}}$}#2}

\begin{document}

\begin{equation}
   \left[ {\begin{array}{ccccccccc}
   0 & \cdots & 0
   & \bovermat{\text{columns }q_1,\ldots,q_\ell}{1 & \cdots & 1} 
   & 0 & \cdots & 0\\
   0 & \cdots & 0 & 1 & \cdots & 1 & 0 & \cdots & 0\\
   \vdots & & \vdots & \vdots & & \vdots & & & \vdots \\
   0 & \cdots & 0 & 1 & \cdots & 1 & 0 & \cdots & 0\\
  \end{array} } \right]
\end{equation}

\end{document}

MWE output

  • 1
    Try to remove the & that precedes the \bovermat and put it inside the \bovermat. Like this: \bovermat{\text{columns }q_1,\ldots,q_\ell}{& 1 & \cdots & 1}. – Phelype Oleinik Jan 19 '18 at 18:37
2

You can also use blkarray, it has more flexibility.

\documentclass{article}
\usepackage{blkarray}
\usepackage{amsmath}

\begin{document}

\[
\begin{blockarray}{ccccccccc}
& & & & \makebox[0pt]{$\overbrace{\rule{4em}{0pt}}^{\text{columns }q_1,\ldots,q_\ell}$} & & & & \\
\begin{block}{[ccccccccc]}
   0    & \cdots &   0    &   1    & \cdots &   1    & 0 & \cdots &   0    \\
   0    & \cdots &   0    &   1    & \cdots &   1    & 0 & \cdots &   0    \\
 \vdots &        & \vdots & \vdots &        & \vdots &   &        & \vdots \\
   0    & \cdots &   0    &   1    & \cdots &   1    & 0 & \cdots &   0    \\
\end{block}
\end{blockarray}
\]

\end{document}

enter image description here

0

As suggested in the comments section by Phelype Oleinik, the solution is to remove the & that precedes the \bovermat and to put it inside the second argument to \bovermat.

\documentclass{article}

\usepackage{amsmath}

% command for overbrace in matrix
\newcommand\bovermat[2]{%
  \makebox[0pt][l]{$\smash{\overbrace{\phantom{%
    \begin{matrix}#2\end{matrix}}}^{#1}}$}#2}

\begin{document}

\begin{equation}   \left[ {\begin{array}{ccccccccc}
   0 & \cdots & 0
   \bovermat{ \text{columns }q_1,\ldots,q_\ell}{& 1 & \cdots & 1} 
   & 0 & \cdots & 0\\
   0 & \cdots & 0 & 1 & \cdots & 1 & 0 & \cdots & 0\\
   \vdots & & \vdots & \vdots & & \vdots & & & \vdots \\
   0 & \cdots & 0 & 1 & \cdots & 1 & 0 & \cdots & 0\\
  \end{array} } \right]

\end{equation}

\end{document}

MWE corrected

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.