# Beamer: Imitating a beamer block - problem with the width

This is a follow up on my last question. I want a text block with (text width and outer shape) the same width as a beamer block but it doesn't work. The default definitioin of a beamer block is here. They use something like \begin{beamercolorbox}[colsep*=.75ex]{block title}. But if I use this the box is not properly centered anymore.

\documentclass{beamer}
\usetheme{Berlin}

\usepackage{tikz}

\begin{document}

% as expected

\begin{frame}{Test}

\begin{block}{Test}
Test
\end{block}

\tikzstyle{myBox} = [draw=none, fill=green,
rectangle,inner sep=10pt,align=left,minimum width=\textwidth,text width=0.8\textwidth]

\begin{centering}
\begin{tikzpicture}
\end{tikzpicture}%
\end{centering}

%
\begin{block}{Test}
Test
\end{block}

\end{frame}

\end{document}


My aim is to imitate the lower part of the beamer block. I use a tikz picture because I want to change transparency and other stuff.

I would like to avoid using additional packages. Is there a way to do it with TikZ? Maybe a beamercolorbox?

Here is two solutions using TikZ and using the fact that a block uses an horizontal extra margin of .75ex on each side.

# 1st solution

Here, I enlarge the text width via a columns environment then I insert your tikzpicture using \textwidth.

\documentclass{beamer}
\usetheme{Berlin}
\usepackage{tikz}
\begin{document}
% First solution
\tikzset{myBox/.style={draw=none,fill=green,rectangle,inner sep=10pt,
align=left,minimum width=\textwidth,text width=0.8\textwidth}}
\begin{frame}{Test}
\begin{block}{Test}
Test
\end{block}
\pgfmathsetmacro\myw{\textwidth+1.5ex}
\begin{columns}
\column{\myw pt}
\begin{tikzpicture}
skdjksdjksjdksjdksjdksjdksa fjdjf dkfjdkfjdkfj
kdjfkdfjkdsjfkdjf};
\end{tikzpicture}%
\end{columns}
\begin{block}{Test}
Test
\end{block}
\end{frame}
\end{document}
\documentclass{beamer}
\usetheme{Berlin}
\usepackage{tikz}


# 2nd solution

Here, I use trim left and trim right to enlarge the tikzpicture beyond \textwidth and I anchor the node on the west.

\documentclass{beamer}
\usetheme{Berlin}
\usepackage{tikz}
\begin{document}
% Second solution
\tikzset{
myPict/.style={trim left=.75ex,trim right=.75ex},
myBox2/.style={line width=0,anchor=west,draw=none,fill=green,
rectangle,inner sep=10pt,align=left,minimum width=\textwidth+1.5ex,
text width=0.8*(\textwidth+1.5ex)},
}
\begin{frame}{Test2}
\begin{block}{Test2}
Test2
\end{block}
\begin{tikzpicture}[myPict]
skdjksdjksjdksjdksjdksjdksa fjdjf dkfjdkfjdkfj kdjfkdfjkdsjfkdjf};
\end{tikzpicture}
\begin{block}{Test2}
Test2
\end{block}
\end{frame}
\end{document}


Next fragment is copied from beameruserguide:

This means that colored boxes are wider than \textwidth. Therefore, when you uses \textwidth inside TikZ box declaration, you are fixing its total width, not its exterior one.

If you want to use special boxes inside beamer I'd suggest using tcolorbox. A possible solution for your example looks like

\documentclass{beamer}
\usetheme{Berlin}

\usepackage{tikz}
\usepackage[skins,breakable]{tcolorbox}

\usepackage{lipsum}

\begin{document}

\begin{frame}{Test}

\begin{block}{Test}
\end{block}

\begin{centering}
\begin{tcolorbox}[enhanced, arc = 0pt, frame hidden, left=1pt, right=1pt, oversize, colback=green]
\end{tcolorbox}%
\end{centering}

%
\begin{block}{Test}
Test
\end{block}

\end{frame}

\end{document}


• Thanks! How did you figure out the exact values for the width you need? I was hoping to be able to use TikZ because I want to use the opactiy key (transparency). Is this supported by tcolorbox? – Dr. Manuel Kuehner Mar 10 '14 at 7:16
• @ManuelKuehner: The values were obtained by trial and error. I couldn't find to many information about used enlargement for colourful blocks. And when found it didn't worked as expected. tcolorbox is based on TiKZ and supports transparencies, shadows, figures in background, etc. Take a look at its documentation. – Ignasi Mar 10 '14 at 9:22
• I added a request because I do not want to an additional package if possible. If there is no way then I will accept the answer. – Dr. Manuel Kuehner Mar 11 '14 at 7:47
• @ManuelKuehner: beamercolorbox environment is defined in beamerbasecolor.tex. If you look there will see how this kind of boxes also adjust margins around them. This code is not enough easy for me to understand it completely and help you to solve the problem. – Ignasi Mar 12 '14 at 20:18
• Thanks - I understand. The same applies for me :). Maybe someone has an idea. – Dr. Manuel Kuehner Mar 12 '14 at 20:31