Featured Book

LaTeX Beginners Guide

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest (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 1 guest

Partner Sites

TeXwelt - Fragen und Antworten goLaTeX
TeXblog
TeXnicCenter
TeXample

Beamer: Block width?

Add 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: 6378
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: 6378
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


Return to Document Classes

Who is online

Users browsing this forum: No registered users and 1 guest