7
\usepackage{setspace}
\doublespacing

I used above two lines to change the spacing in my document. This changes the spacing of the entire document.

My requirement is to change the line spacing in paragraphs only. I want to leave the verse and table environments as they are. I just want to change the paragraphs. I did not put paragraphs in any environment. Do I need to do that as well?

lockstep
  • 250,273
Aku
  • 11,026
  • Are you actually referring to the table environment (a float environment) or do you mean tabular (producing the actual table)? If the latter is the case, please edit your question accordingly. You can use backticks ``` to mark your inline code as I did in my edit. And perhaps you could change the title to something more specific, e.g. "Change line spacing for normal text, but not in tabular/table or verse". – doncherry Aug 20 '11 at 12:43

3 Answers3

9
\documentclass{article}

\usepackage{etoolbox}
\usepackage[doublespacing]{setspace}

\AtBeginEnvironment{verse}{\singlespacing}
\AtBeginEnvironment{tabular}{\singlespacing}

\usepackage{lipsum}% just for blindtext

\begin{document}

\lipsum[1]

\begin{verse}
  \lipsum[1]
\end{verse}

\lipsum[1]

\begin{tabular}{p{10cm}}
  \lipsum[1]
\end{tabular}

\lipsum[1]

\end{document}

This patches the verse and tabular environment to use a \singlespacing at their beginning. The table environment isn't affected by [doublespacing] and thus doesn't need any patching, but you probably want to use tabular.

screenshot of the output

doncherry
  • 54,637
  • 1
    If the tabular isn't wrapped in the table environment (which it probably isn't for Aku's document) this won't work, and you'll have to patch the tabular environment in the same way you did the verse environment. – Alan Munn Aug 20 '11 at 12:30
  • @Alan: Ah, thanks, that answer the question I just asked on your answer :). I'll edit my answer. – doncherry Aug 20 '11 at 12:31
  • I am very new to TeX, this is the error I am getting ! Undefined control sequence. l.6 \AtBeginEnvironment {verse}{\singlespacing} – Aku Aug 20 '11 at 13:55
  • @Aku: Did you put \usepackage{etoolbox} in your preamble? etoolbox is the package that provides the environment-patching command. – doncherry Aug 20 '11 at 14:09
  • @Aku: Actually, if you used exactly what you wrote in your comment here, then there's an unnecessary space in between \AtBeginEnvironment and {verse}{\singlespacing} that might cause the error. Remove this space and try again. – doncherry Aug 20 '11 at 14:15
  • I copied the code from here and ran it, did not modify anything and I am getting the above mentioned error. There is not space between \AtBegin Environment and {verse}{\singlespacing}. the spacing appeared in my comment was accidental. – Aku Aug 20 '11 at 15:19
  • @Aku: Is etoolbox installed on your system? What LaTeX distribution are you using? It didn't work when you just copied my entire example and compiled it? (btw: you can (and should) use backticks ``` to mark your inline code in comments as well.) – doncherry Aug 20 '11 at 15:34
  • I am using texlive-2011, I don't know how to check if certain package is installed or not. – Aku Aug 20 '11 at 16:05
  • @Aku: Try to compile \documentclass{article}\usepackage{etoolbox}\begin{document}Foo\end{document}. Any error messages? – doncherry Aug 20 '11 at 16:46
5

To locally change the line spacing in your document, use the environments singlespace, onehalfspace and doublespace provided by the setspace package. So, for instance:

\documentclass{article}

\usepackage{setspace}
\doublespacing

...

\begin{document}

...

\begin{singlespace}
  ...
\end{singlespace}

...

\end{document}
mhp
  • 8,692
  • I have a book more than 1000 pages long. Paragraphs comes alternatively after a verse and table. Paragraphs is essentially explanation of verse. Is there any easier way to do this? – Aku Aug 20 '11 at 12:06
  • Using the \preto or \appto macro provided by the etoolbox package, you can easily redefine \verse and \endverse to include \singlespace and \endsinglespace, respectively. Of course, you can also do this for other environments that shouldn't be typeset with \doublespacing. – mhp Aug 20 '11 at 12:25
  • Or even better (as suggested in the answer of @doncherry): Use the \AtBeginEnvironment macro of the etoolbox package. – mhp Aug 20 '11 at 12:32
4

You can redefine the verse and tabular environments to make them single spaced:

\let\oldtabular\tabular
\let\endoldtabular\endtabular
\renewenvironment{tabular}
   {\bgroup\singlespacing\oldtabular}%
   {\endoldtabular\egroup}
\let\oldverse\verse
\let\endoldverse\endverse
\renewenvironment{verse}
   {\bgroup\singlespacing\oldverse}%
   {\endoldverse\egroup}
Alan Munn
  • 218,180