matrixlatexbeamer

Latex/Beamer bmatrix inside an align* environment


I'm having trouble using bmatrix inside an align* environment.

The question has already been asked here three years ago, but no MWE has been provided. No answer was given to the issue, though.

What puzzles me is that depending of HOW MUCH items I put in my bmatrix, the compilation can either works fine or fails.

I'm editing the document within vim and the syntax coloring keeps printing the "\end{bmatrix}" in red, implying a syntax error somewhere (but I can't tell what's wrong with my code...)

The last lines of compilation before failure :

! Extra alignment tab has been changed to \cr. \endtemplate l.12 \end{align*}

Here an example of something that currently compiles :

\documentclass[10pt, aspectratio=169]{beamer}

\usepackage [francais]{babel}
\usepackage [T1]{fontenc}
\usepackage [utf8]{inputenc}

\usetheme{Boadilla}

\usepackage{tikz}
\usetikzlibrary{matrix, fit}
\usetikzlibrary{overlay-beamer-styles}

\usepackage{minted}

\begin{document}


\begin{frame}[fragile]

This seems to work...

\begin{align*}
x &=
\begin{bmatrix}
9 & 8 & 7 & 6
\end{bmatrix}\\
y &= \begin{bmatrix}
0 & 0 & 0 & \cdots & 0 & 1 & 2 & 3
\end{bmatrix}
\end{align*}
\end{frame}

\end{document}

And now, something that DO NOT compile (the only difference are the number of items inside the first bmatrix...)

\documentclass[10pt, aspectratio=169]{beamer}

\usepackage [francais]{babel}
\usepackage [T1]{fontenc}
\usepackage [utf8]{inputenc}

\usetheme{Boadilla}

\usepackage{tikz}
\usetikzlibrary{matrix, fit}
\usetikzlibrary{overlay-beamer-styles}

\usepackage{minted}

\begin{document}


\begin{frame}[fragile]

This does not work !

\begin{align*}
x &=
\begin{bmatrix}
9 & 8 & 7 & 6 & 9 & 8 & 7 & 6 & 9 & 8 & 7 & 6
\end{bmatrix}\\
y &= \begin{bmatrix}
0 & 0 & 0 & \cdots & 0 & 1 & 2 & 3
\end{bmatrix}
\end{align*}
\end{frame}

\end{document}

Thanks a lot for any advice :)

BR

Pierre


Solution

  • This is the same situation as in https://tex.stackexchange.com/a/3521/36296 :

    \documentclass[10pt, aspectratio=169]{beamer}
    
    \usepackage [francais]{babel}
    \usepackage [T1]{fontenc}
    \usepackage [utf8]{inputenc}
    
    \usetheme{Boadilla}
    
    \usepackage{tikz}
    \usetikzlibrary{matrix, fit}
    \usetikzlibrary{overlay-beamer-styles}
    \setcounter{MaxMatrixCols}{20}
    \begin{document}
    
    
    \begin{frame}[fragile]
    
    This does not work !
    
    \begin{align*}
    x &=
    \begin{bmatrix}
    9 & 8 & 7 & 6 & 9 & 8 & 7 & 6 & 9 & 8 & 7 & 6
    \end{bmatrix}\\
    y &= \begin{bmatrix}
    0 & 0 & 0 & \cdots & 0 & 1 & 2 & 3
    \end{bmatrix}
    \end{align*}
    \end{frame}
    
    \end{document}
    

    enter image description here

    Alternatively, you could use the tabularray package for your matrix.