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.

I defined a keynote macro to insert key ideas in my document using varwidth. The document is in \doublespacing and I have defined \singlespacing inside my macro. However, the correct spacing is achieved only for long sentences and not for short text like here. Variable spacing

\documentclass{standalone}
\usepackage{setspace,varwidth,lipsum}

\newcommand{\keynote}[1]{%
    \begin{varwidth}{4cm}%
      {\singlespacing \narrowragged #1}%
    \end{varwidth}%
}

\begin{document}
  \doublespacing
  \hspace{1cm} \keynote{\lipsum[2]}
  \hspace{1cm} \keynote{This note explaining a key idea should go to at least two lines.} \hspace{1cm}
\end{document}
share|improve this question

2 Answers 2

up vote 5 down vote accepted

You have to terminate the paragraph, or it will be done when the change in line spacing has already been forgotten because of the }; but since \end{varwidth} ends the paragraph anyway and you're in an environment that forms a group, you can just say

\newcommand{\keynote}[1]{%
   \begin{varwidth}{4cm}
   \singlespacing \narrowragged #1
   \end{varwidth}%
}

Why the example had that peculiarity? Because \lipsum[2] has a \par command inside it. If you used \lipsum*[2], that doesn't issue \par you'd have seen the same problem.

Now you know why: in

\begin{varwidth}{4cm}
{\singlespacing\narrowragged some text to be single spaced}
\end{varwidth}

the paragraph "some text to be single spaced" will be built when the } has already undone the \singlespacing\narrowragged setting. Without the inner braces it's OK.

share|improve this answer
    
wonderful. I played around with \par and different environments, and it is beautiful...just shows me how much more there is to understand. –  devendra Jan 9 '13 at 10:35

Use the spacing environment of the 'setspace' package.

\documentclass{standalone}
\usepackage{setspace,varwidth,lipsum}

\newcommand{\keynote}[1]{%
    \begin{varwidth}{4cm}%
      \begin{spacing}{1}
        {\narrowragged #1}%
      \end{spacing}
    \end{varwidth}%
}

\begin{document}
 \doublespacing
  \hspace{1cm} \keynote{\lipsum[2]} \hspace{1cm} \keynote{This note
    explaining a key idea should go to at least two lines.}
  \hspace{1cm}
\end{document}
share|improve this answer
    
Thank you for the answer. Any idea why \singlespacing won't work? –  devendra Jan 9 '13 at 9:24
    
I don't know really. Please if you like the answer mark it as accepted by clicking the ok symbol. –  zunbeltz Jan 9 '13 at 9:50
    
thanks. I think its only fair to wait for any other answers. Otherwise, I will accept yours by tomorrow. –  devendra Jan 9 '13 at 9:54

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.