Graphics, Figures & TablesLatex beamer, colorbox, size definition

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
mschulme
Posts: 12
Joined: Tue Dec 21, 2010 10:35 pm

Latex beamer, colorbox, size definition

Post by mschulme »

Hi all together,
Latex Beamer does not really want to do what I want it to do. I want beamer to create a colorbox which is centered on the frame (same distance from the left and the right side of the frame) but is not as broad as the whole frame. Here my code:

\documentclass{beamer}

\begin{document}

\begin{frame}[t]

\setbeamercolor{postit}{fg=black,bg=yellow}
\begin{beamercolorbox}[sep=0em,colsep*=5pt,wd=\textwidth,ht=1cm,dp=1cm,ce nter]{postit}
Place me somewhere!
\end{beamercolorbox}

\setbeamercolor{postit}{fg=black,bg=yellow}
\begin{beamercolorbox}[sep=0em,colsep*=0pt,wd=\textwidth,ht=1cm,dp=1cm,ce nter]{postit}
Place me somewhere!
\end{beamercolorbox}

\setbeamercolor{postit}{fg=black,bg=yellow}
\begin{beamercolorbox}[sep=0em,colsep*=-15pt,wd=\textwidth,ht=1cm,dp=1cm,center]{postit}
Place me somewhere!
\end{beamercolorbox}

\end{frame}

\end{document}


I thought that colsep*=-15pt could solve the issue. However, as the lowest box in the sample above shows, this does not really work since this command only shrinks the right colorbox side but not the left side.

Does anyone have an idea for this?

Cheers
Marcus

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Latex beamer, colorbox, size definition

Post by frabjous »

Hmm. I definitely wouldn't try to center the boxes with colsep*. I'm not quite sure why you can't use a center environment there, or \centering, but they don't seem to work either. You could use \hfill's on either side of the box to balance it horizontally. (It seems to require something else on the line, so I put unbreaking spaces ~.

Code: Select all

~\hfill\begin{beamercolorbox}[sep=0em,wd=0.7\textwidth,ht=1cm,dp=1cm,center]{postit}
Place me somewhere!
\end{beamercolorbox}\hfill~
(I put in 0.7\textwidth for the width so it would be easier to see the balancing.)
mschulme
Posts: 12
Joined: Tue Dec 21, 2010 10:35 pm

Re: Latex beamer, colorbox, size definition

Post by mschulme »

This solved one problem ... but create a new one if I want to use this colorbox as the backgound for a table AND if I want to label this table using the caption package.

My example is below. When you look at the output you can see that the labelling with

Table 1 - bla bla bla

is not centered any more and has end. There is only one way I found to avoid this: do NOT use the caption package. Even with \usepackage{caption} only (ie, no parameter specifications) the weired layout error shows up.

But without this caption package I cannot count tables, define the table textfont and color etc.

Do you have any idea? Maybe caption is not the error but the \hfill ? Centering as you pointed out does not work either ...

Thanks
Marcus


\documentclass{beamer}

\usepackage{lmodern}
\usepackage[width=0.75\textwidth,skip=10pt,labelsep=endash,textformat=simple,justification=raggedright,labelformat=simple]{caption}

\setbeamerfont{klein}{size*={6.25}{8.50}}
\setbeamercolor{postit}{fg=black,bg=yellow}
\setbeamerfont{tables_and_figures}{size*={5.25}{7.50}} % for labeling tables and figures

\DeclareCaptionFont{tables_and_figures}{\usebeamerfont{tables_and_figures}}
\captionsetup{font=tables_and_figures,labelfont=tables_and_figures,textfont=tables_and_figures}

\begin{document}

\usebeamerfont{normal}
\begin{frame}

\begin{block}{\bf\usebeamerfont{normal}\textcolor{red}{An example of forward and spot quotes:}}
Table \ref{table-1-100} shows the forward and spot exchange quotes for GBP.
\end{block}

\vspace{0.5cm}

~\hfill
\begin{beamercolorbox}[sep=0em,colsep*=0pt,ht=3.0cm,wd=0.5\textwidth,center]{postit}
\begin{table}[ht]
{\usebeamerfont{klein}
\vspace{0.0cm}
\begin{tabular}{l l l}
{\bf Type} & {\bf Bid} & {\bf Offer} \vspace{0.025cm} \\ \hline
Spot & 2.0558 & 2.0562 \vspace{0.025cm} \\
1-month forward & 2.0547 & 2.0552 \vspace{0.025cm} \\
3-month forward & 2.0526 & 2.0531 \vspace{0.025cm} \\
6-month forward & 2.0483 & 2.0489
\end{tabular}
\vspace{0.0cm}
}
\caption{Exchange Quotes for GBP, July 20, 2007. This is a test of the caption setting for a table.}
\label{table-1-100}
\vspace{-0.4cm} %Moves table and caption southwards !
\end{table}
\end{beamercolorbox}
\hfill~
\end{frame}
\end{document}
Post Reply