3

The columns environment, combined with tabular and verbatim seems to create a huge vertical offset to the text, which I don't know how to get rid of:

\documentclass[12pt]{beamer}
\usetheme{Madrid}

\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{verbatim, booktabs}

\begin{document}

\begin{frame}{Irgendeine Überschrift}
Etwas sinnloser Text, der länger als eine Zeile werden soll und deshalb noch ein paar Wörter braucht.
\begin{columns}[T]
\begin{column}{0.485\textwidth}
Blabla1
\end{column}

\begin{column}{0.485\textwidth}
Blabla2
\end{column}
\end{columns}
\end{frame}

\begin{frame}[fragile]{Beispiel für eine Tabelle}
Etwas sinnloser Text, der länger als eine Zeile werden soll und deshalb noch ein paar Wörter braucht.
\begin{columns}[T]
\begin{column}{0.485\textwidth}
\begin{table}
\caption{Chemische Elemente}
\begin{tabular}{rlr}
\toprule
OZ & Element & MZ \\
\midrule
1 & H & 1 \\
2 & He & 4 \\
3 & Li & 7 \\
4 & Be & 9 \\
5 & B & 11 \\
\bottomrule
\end{tabular}
\end{table}
\end{column}

\begin{column}{0.485\textwidth}
\begin{verbatim}
\begin{tabular}{rlr}
\toprule
OZ & Element & MZ \\
\midrule
1 & H & 1 \\
2 & He & 4 \\
3 & Li & 7 \\
4 & Be & 9 \\
5 & B & 11 \\
\bottomrule
\end{tabular}
\end{verbatim}
\end{column}
\end{columns}
\end{frame}

\end{document}

bco1

Without the table environment, the vertical alignment is even worse! bco2

Also, the text inside the columns is not properly horizontally aligned to the text before. Although this has been adressed before, there was no real solution as to which value to use for the column widths.

Do you have any suggestions how to suppress the vertical offset between text and columns, and ideally have the columns also horizontally aligned to the text?

  • 1
    Both verbatim and the table environment uses internally a list (table as it calls center). Cancelling spaces added by lists can be a complete pain, even more as \addvspace is involved. Additionally you are using a \caption (which inserts a space above), this doesn't make it easier. I would simply use \vspace{-1.5\baselineskip} before the columns to adjust the space. – Ulrike Fischer Mar 29 '17 at 16:52
4

You can suppress the space above verbatim by adding \preto{\@verbatim}{\topsep=0pt \partopsep=0pt} after loading etoolbox library. Also there naturally is some default space above captions (about 10pt), you can control this space by adding some suitable value like: \setlength{\abovecaptionskip}{-.5\baselineskip}.

\documentclass[12pt]{beamer}
\usetheme{madrid}    
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{verbatim, booktabs}

\usepackage{etoolbox}
\makeatletter
\preto{\@verbatim}{\topsep=0pt \partopsep=0pt}
\makeatother

\begin{document}

\begin{frame}{Irgendeine Überschrift}
Etwas sinnloser Text, der länger als eine Zeile werden soll und deshalb noch ein paar Wörter braucht.
\begin{columns}[T]
\begin{column}{0.485\textwidth}
Blabla1
\end{column}

\begin{column}{0.485\textwidth}
Blabla2
\end{column}
\end{columns}
\end{frame}

\begin{frame}[fragile]{Beispiel für eine Tabelle}
Etwas sinnloser Text, der länger als eine Zeile werden soll und deshalb noch ein paar Wörter braucht.
\begin{columns}[T]
\begin{column}{0.485\textwidth}
\setlength{\abovecaptionskip}{-.5\baselineskip}
\begin{table}
\caption{Chemische Elemente}
\begin{tabular}{rlr}
\toprule
OZ & Element & MZ \\ \midrule
1  & H  & 1  \\
2  & He & 4  \\
3  & Li & 7  \\
4  & Be & 9  \\
5  & B  & 11 \\   \bottomrule
\end{tabular}
\end{table}
\end{column}
%
\begin{column}{0.485\textwidth}
\begin{verbatim}
\begin{tabular}{rlr}
\toprule
OZ& Element & MZ\\ 
\midrule
1 & H  & 1  \\
2 & He & 4  \\
3 & Li & 7  \\
4 & Be & 9  \\
5 & B  & 11 \\
\bottomrule
\end{tabular}
\end{verbatim}
\end{column}
\end{columns}
\end{frame}

\end{document}

enter image description here

2

(This answer is exclusively about the second frame environment in your posting. I'm not sure what the purpose of the first frame environment is.)

It appears that the columns environment adds a bit of vertical padding between itself and the material (if any) that precedes it. If you really don't want this padding -- which, at any rate, I would not call "huge" -- simply use side-by-side minipage environments (of width 0.5\textwdith).

Incidentally, do note that it's in general quite pointless to use table environments in a beamer document. Don't use 'em.

The horizontal line in the following screenshot (generate by an \hrule instruction) is there merely to illustrate that no vertical padding is inserted if minipage environments are used.

enter image description here

\documentclass[12pt]{beamer}
\usetheme{Madrid}

\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenx}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{verbatim, booktabs}

\begin{document}

\begin{frame}[fragile,t]
\frametitle{Beispiel für eine Tabelle}

Etwas sinnloser Text, der länger als eine Zeile werden 
soll und deshalb noch ein paar Wörter braucht.
\hrule % just to illustrate width of entire textblock
\begin{minipage}[t]{0.5\textwidth}
\raggedright
Chemische Elemente

\begin{tabular}{rlr}
\toprule
OZ & Element & MZ \\
\midrule
1 & H & 1 \\
2 & He & 4 \\
3 & Li & 7 \\
4 & Be & 9 \\
5 & B & 11 \\
\bottomrule
\end{tabular}
\end{minipage}% <--- "%" is important
\begin{minipage}[t]{0.5\textwidth}
\begin{verbatim}
\begin{tabular}{rlr}
\toprule
OZ & Element & MZ \\
\midrule
1 & H & 1  \\
2 & He & 4 \\
3 & Li & 7 \\
4 & Be & 9 \\
5 & B & 11 \\
\bottomrule
\end{tabular}
\end{verbatim}
\end{minipage}
\end{frame}
\end{document}
  • The first frame is mainly there to show that this vertical offset does not occur with pure text inside columns. And that the running text and the text inside columns are not properly horizontally aligned. I know tables are not that convenient for a beamer presentation, but this particular case is intended to show LaTeX novices how to code a table... – rotton Apr 3 '17 at 11:48

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.