Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to number an equation inside an environment created for customed blocks with equations like those contained in how to adjust the latex beamer block width to the size of its content?. But I receive an error when inserting an \align{} environment. Any suggestions?

share|improve this question
add comment

1 Answer

The errors are my fault with the code. But we should distinguish:

  • the numbering problem;
  • the align problem.

For what concern the numbering problem it could be easily solved: at the moment equations are not numbered due to the call

\opaqueblock<#1>[\wd\mybox]{\[\BODY\]}

Of course, replacing \[\BODY\] with

\opaqueblock<#1>[\wd\mybox]{\begin{equation}\BODY\end{equation}}

is of help, but we still missing the fact that we previously measure the width of $\BODY$ without numbers, so the width of the box is wrong. A workaround is:

\NewEnviron{cdyn}[1]{%
    \sbox{\mybox}{$\BODY \qquad (1)$}%
    \begin{center}
    \begin{dynblock}
    \opaqueblock<#1>[\wd\mybox]{\begin{equation}\BODY\end{equation}}
    \end{dynblock}
    \end{center}
}{}%

A complete example:

\documentclass[t]{beamer}
\usepackage{lmodern}
\usetheme{Madrid}
\usepackage[customcolors,shadow,roundedcorners]{dynblocks}
% setting the block body color
\usebeamercolor{block body}
\definecolor{my block body}{named}{bg}
\setbordercolor{my block body}
\setblockcolor{my block body}

% new enviroment always centered

\usepackage{environ}
\newsavebox\mybox
% new environment cdyn: #1 => overlay specification

\NewEnviron{cdyn}[1]{%
    \sbox{\mybox}{$\BODY \qquad (1)$}%
    \begin{center}
    \begin{dynblock}
    \opaqueblock<#1>[\wd\mybox]{\begin{equation}\BODY\end{equation}}
    \end{dynblock}
    \end{center}
}{}%

\begin{document}

\begin{frame}{Test}
\abovedisplayskip=0pt

\begin{cdyn}{1-}
c^2=a^2+b^2
\end{cdyn}

\begin{cdyn}{2-}
x+y=400
\end{cdyn}

\begin{cdyn}{3-}
\sum_{l _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}+
\sum_{l _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}\label{eq:sum}
\end{cdyn}

\begin{cdyn}{4-}
q_{n+1}=q_n-\Delta_n+\theta_n \qquad \Delta_n=
\begin{cases}
1 \quad q_n>0\\
0 \quad q_n=0
\end{cases}
\end{cdyn}

\only<4->{I'm referring to \eqref{eq:sum}.}

\end{frame}

\end{document}

The result:

enter image description here

For the other problem, inserting an align environment, unfortunately I don't have a solution. Indeed, just changing

\opaqueblock<#1>[\wd\mybox]{\begin{equation}\BODY\end{equation}}

with

\opaqueblock<#1>[\wd\mybox]{\begin{align}\BODY\end{align}}

is not sufficient. Actually, it works with the example provided above, but if you change

\begin{cdyn}{3-}
\sum_{l _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}+
\sum_{l _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}\label{eq:sum}
\end{cdyn}

into

\begin{cdyn}{3-}
\sum_{l _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}\\
\sum_{lu _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}\label{eq:sum}
\end{cdyn}

you will receive these errors

! LaTeX Error: There's no line here to end.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.54 \end{frame}

Your command was ignored.
Type  I <command> <return>  to replace it with another command,
or  <return>  to continue without it.

! Missing $ inserted.
<inserted text> 
                $
l.54 \end{frame}

I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.


! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.54 \end{frame}

Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.

! Missing $ inserted.
<inserted text> 
                $
l.54 \end{frame}

I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.

The problem here is how the box is measured:

\sbox{\mybox}{$\BODY + \qquad (1)$}%

does not work with environments that break the line (I suppose) and I don't know how to push something like that in a box and measure its width. Of course, you could always do it manually:

\begin{center}
\begin{dynblock}
\opaqueblock<3->[0.8\textwidth]{%
\begin{align}
\sum_{l _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}\\
\sum_{lu _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}\label{eq:sum}
\end{align}
}
\end{dynblock}
\end{center}

A mwe for completeness:

\documentclass[t]{beamer}
\usepackage{lmodern}
\usetheme{Madrid}
\usepackage[customcolors,shadow,roundedcorners]{dynblocks}
% setting the block body color
\usebeamercolor{block body}
\definecolor{my block body}{named}{bg}
\setbordercolor{my block body}
\setblockcolor{my block body}

% new enviroment always centered

\usepackage{environ}
\newsavebox\mybox
% new environment cdyn: #1 => overlay specification

\NewEnviron{cdyn}[1]{%
    \sbox{\mybox}{$\BODY \qquad (1)$}%
    \begin{center}
    \begin{dynblock}
    \opaqueblock<#1>[\wd\mybox]{\begin{equation}\BODY\end{equation}}
    \end{dynblock}
    \end{center}
}{}%

\begin{document}

\begin{frame}{Test}
\abovedisplayskip=0pt

\begin{cdyn}{1-}
c^2=a^2+b^2
\end{cdyn}

\begin{cdyn}{2-}
x+y=400
\end{cdyn}

\begin{center}
\begin{dynblock}
\opaqueblock<3->[0.35\textwidth]{%
\begin{align}
\sum_{l _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}\\
\sum_{lu _1+\dots+ l _p=l}\prod^p_{i=1} \binom{n_i}{l _i}\label{eq:sum}
\end{align}
}
\end{dynblock}
\end{center}

\begin{cdyn}{4-}
q_{n+1}=q_n-\Delta_n+\theta_n \qquad \Delta_n=
\begin{cases}
1 \quad q_n>0\\
0 \quad q_n=0
\end{cases}
\end{cdyn}

\only<4->{I'm referring to \eqref{eq:sum}.}

\end{frame}

\end{document}

The result:

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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