I would like to define a nice beamer
block environment with the following properties
a) it is always centered on the slide (horizontally)
b) it is only slightly longer than its content
The aim is to put an equation inside the block and use the block as a highlighter for this equation. So in short, I want a block environment that adjusts its width to the content it contains. Does anybody know a solution?
This would be an example of what I want to achieve automatically:
\documentclass[slidestop]{beamer}
\usetheme{Madrid}
\begin{document}
\begin{frame}{Test}
\abovedisplayskip=0pt
\begin{center}
\begin{minipage}{0.2\textwidth}
\begin{block}{}
\begin{gather*}
c^2=a^2+b^2
\end{gather*}
\end{block}
\end{minipage}
\end{center}
\end{frame}
\end{document}
The environment should work similar like this manual hack with the improvement that the 0.2\textwidth
is adjusted nicely according to the actual width of the formula.
Edit:
I am searching for a nice realization of the following workaround:
\documentclass[slidestop]{beamer}
\usetheme{Madrid}
\usepackage{calc}
\newcommand{\gatherblock}[1]{%
\vspace*{-5pt}
\begin{center}
\begin{minipage}{\widthof{$#1$}}
\begin{block}{}
\abovedisplayskip=0pt
\vspace*{-1pt}
\begin{gather*}
#1
\end{gather*}
\end{block}
\end{minipage}
\end{center}}
\begin{document}
\begin{frame}{Test}
\gatherblock{c^2=a^2+b^2}
\end{frame}
Best Answer
If your aim is to highlight equations without having to care about its width you could use other approaches rather than blocks.
I propose here two methods:
the first is an adaptation of Peter's answer A \boxed alternative with minimal spacing?
a solution based on
hf-tikz
.Solution with minimal spacing
This method needs the
tikzmark
library: it could be find at http://bazaar.launchpad.net/~tex-sx/tex-sx/development/files, then download the filestikzmark.dtx
andtikzmark_example.pdf
. Once put in a temporary directory compile with pdflatex, then install is as a package.The code:
After two compilation runs, the result is:
Solution with hf-tikz
The previous solution is completely automatic, but could have some problems. Suppose to box:
You will end up with:
This because of one cannot say:
That's the reason why a semi-automatic package like
hf-tikz
IMHO provides a good alternative: markers fit pretty well the dimensions automatically, but when needed the user could shift and extend as he needs the highlighted area.An example that shows how to highlight some equations with overlay specifications:
Also in this case two compilation runs are necessary; then the result is:
If instead you want to use blocks, there could be another solution, but is not automatic. Moreover, in contrast with hf-tikz where the overlay specification is just used to show or not the highlighting, here the equation is inside a block, so the overlay specifications show or not the equation with the block together.
Code:
The result:
Using the
dynblocks
andenviron
packages, allows to compute automatically the width of the formula.Here is the key point:
in which first I compute the width of the formula and then this width is passed to the
\opaqueblock
command.The complete code:
The result: