Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In a LaTeX beamer document, is there a way to change line spacing only for the main text body - i.e. for everything between \begin{frame} and \end{frame}? In particular if using \linespread and its variants in the preamble the line spacing will also increase in multi-line titles or if the respective beamertheme uses newlines in its layout. I also tried using \linespread within a frame but to no avail.

share|improve this question
2  
Not terribly sure about Beamer, but check out the setspace package. –  Kerrek SB Jul 7 '11 at 15:01
add comment

migrated from stackoverflow.com Sep 30 '11 at 11:29

This question came from our site for professional and enthusiast programmers.

1 Answer

If you have a title on each frame, your generic structure would probably resemble

\begin{frame}
  \frametitle{<title>}
  % <frame content>
\end{frame}

As such, you have the \frametitle command as a hook that you can use to initiate a different line spacing for the remainder of the frame. And, instead of using the traditional \linespread{<factor>} to modify the spacing, use \setstretch{<factor>} from the setspace package. To that end, include the following in your preamble:

\usepackage{setspace}% http://ctan.org/pkg/setspace
\let\oldframetitle\frametitle% Store \frametitle in \oldframetitle
\renewcommand{\frametitle}[1]{%
  \oldframetitle{#1}\setstretch{2}}

This will typeset the regular \frametitle and immediately after it call \setstretch{2} which increases ("doubles") the line spacing for the remainder of the group. Since the frame environment provides the necessary scope boundary, \setstretch only has an effect until \end{frame}. This allows for only the frame content to be typeset under a different line spacing, leaving titles untouched in terms of this stretch factor. Additionally, a natural form of automation by redefinition of the existing commands allow for legible and transferable code.

Here's a minimal example showing this:

enter image description here

\documentclass{beamer}% http://ctan.org/pkg/beamer
\useoutertheme{infolines}
\usetheme{Warsaw}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{setspace}% http://ctan.org/pkg/setspace
\let\oldframetitle\frametitle% Store old \frametitle in \oldframetitle
\renewcommand{\frametitle}[1]{% Redefine \frametitle
  \oldframetitle{#1}\setstretch{2}}
%\setstretch{2} <--- uncomment to see the global effect of \setstretch{2}
\title{Random title}
\subtitle{Random subtitle}
\author{Random Randofsky}
\institute{Random institute, Random City 1000, Randomia}
\date{\today}

\begin{document}
\maketitle

\begin{frame}
  \tableofcontents
\end{frame}

\section{Random section 1}
\begin{frame}
  \frametitle{This frame title is extremely long and spans at least two lines}
  \begin{itemize}
    \item Random stuff Random stuff
    \item \itshape{more random stuff}
    \item Random stuff...
  \end{itemize}
\end{frame}

\section{Random section 2}
\begin{frame}
  \frametitle{Here is another long frame title - this time it spans more than 
    just two lines of the frame; it actually spans three lines}
  \lipsum[4]
\end{frame}

\section{Random section 3}
\begin{frame}
  This frame has no title. So, the contents is not affected by line spacing changes
  \begin{itemize}
    \item Random stuff Random stuff
    \item \itshape{more random stuff}
    \item Random stuff...
  \end{itemize}
\end{frame}


\section{Random section 4}
\begin{frame}
  \frametitle{About this frame}
  \begin{itemize}
    \item Random stuff Random stuff
    \item \itshape{more random stuff}
    \item Random stuff...
  \end{itemize}
\end{frame}

\end{document}

Of course, this relies on the fact that your frame has the structure suggested at the start. So, a frame without a title would be void of any line spacing alterations. Since you didn't mention this in your question, I assume this is not a problem. However, such modifications are always possible, given an alternative/suitable hook.

The lipsum package was merely used to provide filler text on slide 4.

To see the global effect of \setspace{2} on the frame titles, uncomment \setspace{2} in the preamble.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.