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:
\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.
The setspace
package provides the means the change the line spacing in a very consistent (and easy) way trough environments or by a switch. Here's a small example:
\documentclass{article}
\usepackage{setspace}% http://ctan.org/pkg/setspace
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\begin{document}
\lipsum[1]
\begin{doublespacing}
\lipsum[1]
\end{doublespacing}
\lipsum[1]
\end{document}
Note that there is some hidden information in the above example. Since LaTeX sets text on a paragraph basis, you need to ensure that you initiate a paragraph break (through an empty line or an explicit \par
) in order for the line-spacing to take effect. This is implicitly done by the lipsum
package's \lipsum
command above.
Switches should be grouped to limit the scope using something like
%...
\begingroup\onehalfspacing
% some paragraph text
% (maybe end with \par)
\endgroup
%...
Switches and environment provided by setspace
are
singlespacing
onehalfspacing
and
doublespacing
.
However, the more general \setstretch{<num>}
macro is the required interface for doing more general line-space setting.
setspace
provides the interface with elements like \baselineskip
and \linespread
. See Why is the \linespread
factor as it is? for a general discussion on the choice of <num>
.
Barbara mentioned the option of having an "equally wide" gap above/below the increased line spacing paragraph. The reason why it's not is because the \baselineskip
is paragraph-based. So, the paragraph following the change has a different (smaller) \baselineskip
, and is therefore visually closer. A naive approach to correct for this is given below using some "fudging":
\documentclass{article}
\usepackage{setspace}% http://ctan.org/pkg/setspace
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\newlength{\fudgeheight}
\newcommand{\fudgestrut}{\leavevmode\rule{0pt}{\fudgeheight}}
\begin{document}
\lipsum[1]
\begin{doublespacing}
\lipsum[1]\global\setlength{\fudgeheight}{\baselineskip}
\end{doublespacing}
\fudgestrut\lipsum[1]
\end{document}
The idea here is to insert a vertical strut - \fudgestrut
- using the increased \baselineskip
within the first line of the paragraph following the line spacing change. I'm sure this process can be automated somewhat, but the use-case doesn't warrant such investigation.
Best Answer
Like @Bernard said in his comment: First import
setspace
, and then use\setstretch{1.5}
before your main part and everything works fine. Thank you!