Featured Book

LaTeX Beginners Guide

Who is online

In total there are 3 users online :: 0 registered, 0 hidden and 3 guests (based on users active over the past 5 minutes)
Most users ever online was 1327 on Tue Nov 05, 2013 7:11 pm

Users browsing this forum: No registered users and 3 guests

Partner Sites

Beamer: Block width?

beamerblocksAdd tags Information and discussion about specific document classes and how to create your own document classes.

Beamer: Block width?

Postby pebo on Mon Aug 25th, 2008

Hello,
what's the best way to draw a block with some contents, as with the block environment, that does not span over the whole slide's width?
Currently I use a single column with a specified width, but I find it a little long:
Code: Select all  •  Open in writeLaTeX
\begin{columns}
\column{7em}
\begin{block}{Title}Text
\end{block}
\end{columns
}

Any hint is appreciated :)
pebo
 
Posts: 3
Joined: Thu Aug 14th, 2008

Re: Beamer: Block width?

Postby Stefan_K on Tue Aug 26th, 2008

Hi Pebo,

you could define your own block environment with an optional parameter for its width. Have a look at this example:
Code: Select all  •  Open in writeLaTeX
\documentclass{beamer}
\usetheme{Warsaw}
\usepackage[english]{babel}
\title{Variable block demo}
\author{Stefan Kottwitz}

\newenvironment<>{varblock
}[2][\textwidth]{%
  \setlength{\textwidth}{#1}
  \begin{actionenv
}#3%
    \def\insertblocktitle{#2}%
    \par%
    \usebeamertemplate{block begin}}
  {\par%
    \usebeamertemplate{block end}%
  \end{actionenv}}

\begin{document}

\begin{frame}
\begin{block}{Standard}
  Normal block
\end{block}
\begin{varblock}[4cm]{New block}
  Variable width, here 4cm
\end{varblock}
\begin{varblock}{New block}
  If no width was given, \textbackslash textwidth will be used
\end{varblock}
\end{frame}

\end{document
}

Stefan
LaTeX Community Administrator
User avatar
Stefan_K
Site Admin
 
Posts: 6643
Joined: Mon Mar 10th, 2008
Location: Hamburg, Germany

Re: Beamer: Block width?

Postby mathfeel on Mon Jun 29th, 2009

Stefan_K wrote:Hi Pebo,

you could define your own block environment with an optional parameter for its width. Have a look at this example:
Code: Select all  •  Open in writeLaTeX
\documentclass{beamer}
\usetheme{Warsaw}
\usepackage[english]{babel}
\title{Variable block demo}
\author{Stefan Kottwitz}

\newenvironment<>{varblock
}[2][\textwidth]{%
  \setlength{\textwidth}{#1}
  \begin{actionenv
}#3%
    \def\insertblocktitle{#2}%
    \par%
    \usebeamertemplate{block begin}}
  {\par%
    \usebeamertemplate{block end}%
  \end{actionenv}}

\begin{document}

\begin{frame}
\begin{block}{Standard}
  Normal block
\end{block}
\begin{varblock}[4cm]{New block}
  Variable width, here 4cm
\end{varblock}
\begin{varblock}{New block}
  If no width was given, \textbackslash textwidth will be used
\end{varblock}
\end{frame}

\end{document
}

Stefan

Been looking for this. Thanks. One thing: the resized block is not centered (The box is left-aligned). How do I center the box?
mathfeel
 
Posts: 11
Joined: Fri Jun 13th, 2008

Re: Beamer: Block width?

Postby Stefan_K on Mon Jun 29th, 2009

You could center the box by using a center environment and a minipage environment, if needed:
Code: Select all  •  Open in writeLaTeX
\begin{center}
  \begin{minipage}{4cm}
    \begin{varblock}[4cm]{title}
      text
    \end{varblock}
  \end{minipage}
\end{center
}

Stefan
LaTeX Community Administrator
User avatar
Stefan_K
Site Admin
 
Posts: 6643
Joined: Mon Mar 10th, 2008
Location: Hamburg, Germany

Re: Beamer: Block width?

Postby mathfeel on Mon Jun 29th, 2009

Yes, but this would defeat the purpose of reusing code. Suppose I want some new environment called "cvarbox", I cannot just stick the \begin{center} and \begin{minipage} into the \newenvironment<>, can I?

I am not familiar with TeX, so I am not sure how to do this. Thanks.

[EDIT]:GOT IT. Simply inserting center/minipage in the newenvironment definition worked.
mathfeel
 
Posts: 11
Joined: Fri Jun 13th, 2008

Re: Beamer: Block width?

Postby fabriciomarques1 on Wed Mar 9th, 2011

Hi,
I achieve what you were trying to do by changing the Stefan's code as:
Code: Select all  •  Open in writeLaTeX
   
\newenvironment<>{varblock}[2][\textwidth]{
    \begin{center}
      \begin{minipage}{#1}
        \setlength{\textwidth}{#1}
          \begin{actionenv}#3
            \def\insertblocktitle{#2}
            \par
            \usebeamertemplate{block begin}}
  {\par
      \usebeamertemplate{block end}
    \end{actionenv}
  \end{minipage}
\end{center}
}
Fabricio
User avatar
fabriciomarques1
 
Posts: 1
Joined: Wed Mar 9th, 2011
Location: São Paulo, Brazil

Re: Beamer: Block width?

Postby tom75 on Fri Jan 2nd, 2015

Hi Stefan,

can you please explain me the environment

Code: Select all  •  Open in writeLaTeX
\begin{actionenv}#3%
\end{actionenv}


you used in your code? I neither understand the explanation in the TikZ documentation nor do I see any difference if I use your code without those two lines.

Additionally, is it possible to limit the width of the block automatically to the size of (a longer) text (with some \\ in it)?

Tom
tom75
 
Posts: 5
Joined: Sat Dec 27th, 2014

Re: Beamer: Block width?

Postby Stefan_K on Sun Jan 4th, 2015

Hi Tom,

it's described in the beamer manual, if you follow the link it's in 9.6.3 Action Specifications. And full text search gives examples of use.

Regarding automatically choosen width, perhaps it's possible using the varwidth package.

Stefan
LaTeX Community Administrator
User avatar
Stefan_K
Site Admin
 
Posts: 6643
Joined: Mon Mar 10th, 2008
Location: Hamburg, Germany

Re: Beamer: Block width?

Postby tom75 on Thu Jan 8th, 2015

Hi Stefan,

thanks, I think I understood \newenvironement<> a litte bit better.

There are still two thinks I'm not sure about:

Why do you have to use \def\insertblocktitle{#2}? I read that one shouldn't use \def but \renewcommand{\insertblocktitle}{#2}.

And I'm not sure why I have to use the \par commands for a new paragraph. The output is the same without them.

Regarding automatically choosen width, perhaps it's possible using the varwidth package.


Ok, I'll try this.

Tom
tom75
 
Posts: 5
Joined: Sat Dec 27th, 2014

Re: Beamer: Block width?

Postby Stefan_K on Thu Jan 8th, 2015

Hi Tom,

I took it from the original block environment code which is:

Code: Select all  •  Open in writeLaTeX
\newenvironment<>{block}[1]{%
  \begin{actionenv}#2%
    \def\insertblocktitle{#1}%
    \par%
    \usebeamertemplate{block begin}}
  {\par%
    \usebeamertemplate{block end}%
  \end{actionenv}}


Based on this I created the modified variable environment above. So the only reason for me was to use the same code for consistency.

Yes, LaTeX users should use \renewcommand which is higher level and safer. Package programmers use \def because it's faster. For user code, safety is more important than speed.

Stefan
LaTeX Community Administrator
User avatar
Stefan_K
Site Admin
 
Posts: 6643
Joined: Mon Mar 10th, 2008
Location: Hamburg, Germany

Next

Topic Tags

beamerblocks

Return to Document Classes

Who is online

Users browsing this forum: No registered users and 3 guests