2

While I have given up with beamer tcolorbox inside align, I have realized my mwe theme is not working to box an align equation either: The beamerthememwe.sty:

\mode<presentation>
\usepackage[customcolors,shade]{hf-tikz}
\usetikzlibrary{arrows,shadows,petri,decorations.markings,shapes}
\RequirePackage[most]{tcolorbox}
\definecolor{dcol}{HTML}{3F51B5}
\usecolortheme[named=dcol]{structure}
\usepackage[]{biblatex}
\tcbuselibrary{theorems}

\tcbset{%
  left=6mm, right=6mm, top=6mm, bottom=6mm, middle=4mm,
}

\tcbset{%
  outerlayer/.style={%
    enhanced, sharpish corners=all, colbacktitle=dcol, coltitle=white, coltext=dcol, left=1mm,
    right=6mm, top=1mm, bottom=1mm, middle=4mm, toptitle=1mm, bottomtitle=1mm,
    % fuzzy shadow={0mm}{0.9mm}{0.6mm}{0.2mm}{black}, % top
    % fuzzy shadow={0mm}{-0.6mm}{-0.1mm}{0.2mm}{black}, % bottomSmall
    % fuzzy shadow={0mm}{-0.2mm}{-0.2mm}{0.2mm}{black}, % bottomBig
    title filled, boxrule=0mm, %
    segmentation code={\path[draw=BGrey](segmentation.west) -- (segmentation.east);}
  },
  innerlayer/.style={outerlayer,
    noparskip, breakable, colback=dcol, coltitle=black, coltext=white, 
    fonttitle={\bfseries \scshape}, 
  bottomtitle=1mm}
}

\newtcolorbox{card}[1][]{%
  outerlayer,
  title=#1,
}

\newtcolorbox{hlcard}[1][]{%
  innerlayer,hbox,
  #1
}

and a minimal mwe:

\documentclass[10pt,xcolor=dvipsnames,xcolor=table]{beamer}
\usetheme{mwe}
\usepackage[]{biblatex}
% \usepackage{roboto}

\begin{document}
\begin{frame}\frametitle{Hello}
  \begin{card}
    \begin{hlcard}[ams align*]
        F&=ma\\
        E&=mc^{2}
    \end{hlcard}
  \end{card}
\end{frame}
\end{document}

which is giving error:

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

? X
No pages of output.

This error is gone if I don't use my theme and simply do:

\documentclass[10pt,xcolor=dvipsnames,xcolor=table]{beamer}
\usetheme{mwe}
\usepackage[]{biblatex}
% \usepackage{roboto}

\begin{document}
\begin{frame}\frametitle{Hello}
  % \begin{card}
    % \begin{hlcard}[ams align*]
  \begin{tcolorbox}[ams align*]
    F&=ma\\
    E&=mc^{2}
  \end{tcolorbox}
    % \end{hlcard}
  % \end{card}
\end{frame}
\end{document}

So, there must be something I am missing in the card and hlcard definition, but I am unable to find it over the weekend.

I will be grateful if you show me some light.

UPDATE The only clue I have is that hbox is the culprit. I am using hbox in hlcard to make the tcolorbox wrap the text/equation only, not the complete textwidth.

NB: hlcard is working fine to cover a single inline equation.

3
  • hbox will give an error as align* needs to be in vertical mode. Why do you need the hbox? Oct 9, 2017 at 7:51
  • @AndrewSwann: I am using hbox just to make tcolorbox to be around the text. Without hbox, it is occupying full textwidth. So, I will be happy to leave hbox for something else, which makes the tcolorbox just wide enough to cover the actual text.
    – BaRud
    Oct 9, 2017 at 8:01
  • Use e.g. aligned for the math instead of align. $\begin{aligned}...\end{aligned}$. Oct 9, 2017 at 8:09

2 Answers 2

2

What you need is support for the aligned environment from amsmath which may be used in any math mode, rather than just a display. Combining tcolorbox's code for the math option with an aligned the following settings will provide an ams aligned option to your boxes:

\tcbset{ams aligned upper/.style={before upper=$\displaystyle\aligned,
  after upper=\endaligned$},
ams aligned lower/.style={before lower=$\displaystyle\aligned,
  after lower=\endaligned$},
ams aligned/.style={ams aligned upper,ams aligned lower}}

Sample output

\documentclass[10pt,xcolor=dvipsnames,xcolor=table]{beamer}

\mode<presentation>
\usepackage[customcolors,shade]{hf-tikz}
\usetikzlibrary{arrows,shadows,petri,decorations.markings,shapes}
\RequirePackage[most]{tcolorbox}
\definecolor{dcol}{HTML}{3F51B5}
\usecolortheme[named=dcol]{structure}
\usepackage[]{biblatex}
\tcbuselibrary{theorems}

\tcbset{%
  left=6mm, right=6mm, top=6mm, bottom=6mm, middle=4mm,
}

\tcbset{%
  outerlayer/.style={%
    enhanced, sharpish corners=all, colbacktitle=dcol, coltitle=white, coltext=dcol, left=1mm,
    right=6mm, top=1mm, bottom=1mm, middle=4mm, toptitle=1mm, bottomtitle=1mm,
    % fuzzy shadow={0mm}{0.9mm}{0.6mm}{0.2mm}{black}, % top
    % fuzzy shadow={0mm}{-0.6mm}{-0.1mm}{0.2mm}{black}, % bottomSmall
    % fuzzy shadow={0mm}{-0.2mm}{-0.2mm}{0.2mm}{black}, % bottomBig
    title filled, boxrule=0mm, %
    segmentation code={\path[draw=BGrey](segmentation.west) -- (segmentation.east);}
  },
  innerlayer/.style={outerlayer,
    noparskip, breakable, colback=dcol, coltitle=black, coltext=white,
    fonttitle={\bfseries \scshape},
  bottomtitle=1mm}
}

\newtcolorbox{card}[1][]{%
  outerlayer,
  title=#1,
}

\newtcolorbox{hlcard}[1][]{%
  innerlayer,hbox,
  #1
}

\tcbset{ams aligned upper/.style={before upper=$\displaystyle\aligned,
  after upper=\endaligned$},
ams aligned lower/.style={before lower=$\displaystyle\aligned,
  after lower=\endaligned$},
ams aligned/.style={ams aligned upper,ams aligned lower}}

\begin{document}
\begin{frame}\frametitle{Hello}
  \begin{card}
    \begin{hlcard}[ams aligned]
        F&=ma\\
        E&=mc^{2}
    \end{hlcard}
  \end{card}
\end{frame}
\end{document}
1

If I'm not wrong, it's not possible to use \hbox (or \tcbox) with multiline maths expressions. What you can do is to use an empheq environment colored with a \tcbox definition. something like:

\documentclass[10pt,xcolor=dvipsnames,xcolor=table]{beamer}
\usetheme{mwe}
\usepackage{empheq}
\usepackage[]{biblatex}
% \usepackage{roboto}

\renewtcbox{hlcard}{%
    outerlayer,
   colback=dcol, 
   coltitle=black, 
   coltext=white, 
   fonttitle={\bfseries \scshape}, 
    bottomtitle=1mm,
    nobeforeafter,
    }

\begin{document}
\begin{frame}\frametitle{Hello}
  \begin{empheq}[box=\hlcard]{align*}
    F&=ma\\
    E&=mc^{2}
  \end{empheq}
\end{frame}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .