3

I'm using following code and I would like to make the color of the background correspond to that of the beamer style. I tried the command background:=\mpcolor{block body example.bg}; but it does not work.

\documentclass[10pt]{beamer}
\usepackage{xcolor,luamplib}
\usetheme{Boadilla}
\begin{document}
\begin{frame}
\begin{exampleblock}{}\centering\leavevmode
\begin{mplibcode}
input mptrees;
beginfig(1)
dirtree:=-90;
typeprob:=2;
% background:=\mpcolor{block body example.bg};
draw tree[1][1](1.25cm,5cm)("P","$\frac{1}{2}$","F","$\frac{1}{2}$");
draw tree[2][1](1.25cm,1.5cm)("R","$\frac{1}{5}$","B","$\frac{1}{5}$","N","$\frac{3}{5}$");
draw tree[2][2](1.25cm,1.5cm)("R","$\frac{1}{5}$","B","$\frac{1}{5}$","N","$\frac{3}{5}$");
endfig;
\end{mplibcode}
\end{exampleblock}
\end{frame}
\end{document}

beamer-luamplib

  • AFAIK, you have to fetch this color in the sources, convert it and pass it to metapost. – sztruks Oct 8 at 11:15
  • Yes, but for example the background:=\mpcolor{red} doesn't work. – MB4E Oct 8 at 17:36
2

As the \mpcolor command has been designed to be used after withcolor operator, it will not work in a simple assignment situation such as background. However, xcolor package provides a quite useful command, \extractcolorspecs, which we can use in the OP's example as follows:

\documentclass[10pt]{beamer}
\usepackage{luamplib}
\usetheme{Boadilla}
\begin{document}
\mplibforcehmode
\begin{frame}
  \begin{exampleblock}{}\centering
    \extractcolorspecs{block body example.bg}\modelcmd\colorcmd
    \begin{mplibcode}
      input mptrees;
      beginfig(1)
      dirtree:=-90;
      typeprob:=2;
      background:=(\colorcmd);
      draw tree[1][1](1.25cm,5cm)("P","$\frac{1}{2}$","F","$\frac{1}{2}$");
      draw tree[2][1](1.25cm,1.5cm)("R","$\frac{1}{5}$","B","$\frac{1}{5}$","N","$\frac{3}{5}$");
      draw tree[2][2](1.25cm,1.5cm)("R","$\frac{1}{5}$","B","$\frac{1}{5}$","N","$\frac{3}{5}$");
      endfig;
    \end{mplibcode}
  \end{exampleblock}
\end{frame}
\end{document}

At line 8, \modelcmd gets to be rgb; \colorcmd gets to be 0.9,0.95,0.9 (xcolor manual 2.13). So, the latter can be made into a metapost color expression when put in parentheses.

1

With TikZ, we can put more nodes along the path. I think similar things can be done with Metapost, or it's better moving to TikZ ^^

enter image description here

\documentclass{beamer}
\usepackage{tikz}
\usetheme{Boadilla}
\begin{document}
\begin{frame}
\begin{exampleblock}{}\centering\leavevmode
\begin{tikzpicture}[yscale=2,xscale=1.5,font=\sffamily]
\path
(0,0)    coordinate (O)
(-2,-1)  node (F) {F} 
+(0,-1)  node (B1) {B}
+(-1,-1) node (N1) {N}
+(1,-1)  node (R1) {R}
(2,-1)   node (P) {P}
+(0,-1)  node (B2) {B}
+(-1,-1) node (N2) {N}
+(1,-1)  node (R2) {R};

\path 
(O)--(F) node[pos=.6] (OF) {$\frac{1}{2}$}
(O)--(P) node[pos=.6] (OP) {$\frac{1}{2}$}
(F.south)--(N1) node[pos=.6] (FN1) {$\frac{3}{5}$}
(F.south)--(B1) node[pos=.6] (FB1) {$\frac{1}{5}$}
(F.south)--(R1) node[pos=.6] (FR1) {$\frac{1}{5}$}
(P.south)--(N2) node[pos=.6] (PN2) {$\frac{3}{5}$}
(P.south)--(B2) node[pos=.6] (PB2) {$\frac{1}{5}$}
(P.south)--(R2) node[pos=.6] (PR2) {$\frac{1}{5}$}; 

\draw 
(O)--(OF) (OF)--(F) 
(O)--(OP) (OP)--(P)
(F.south)--(FB1) (FB1)--(B1) 
(F.south)--(FN1) (FN1)--(N1) 
(F.south)--(FR1) (FR1)--(R1)
(P.south)--(PB2) (PB2)--(B2)
(P.south)--(PN2) (PN2)--(N2)
(P.south)--(PR2) (PR2)--(R2);
\end{tikzpicture}
\end{exampleblock}
\end{frame}
\end{document}

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.