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 am trying to define a dialog environment while using the lettrine package. My problem are the spaces between the dialogs. There is no problem when a dialog consists of more than two lines. But paragraphs with one line are problematic since the number of lines given in lettrine is two.

Is it possible to count the lines in a paragraph and determine the space between the paragraphs with respect to the number of lines?

\documentclass{minimal}
\usepackage{graphicx}
\usepackage{lettrine}
\usepackage{needspace}
\usepackage{lipsum}

\newenvironment{dialog}
{\lettrine[lines=2,nindent=3pt,findent=3pt,image=true,loversize=0.7,lraise=-0.2]{myimage.eps}{}}
{\par}


\begin{document}

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

\begin{dialog}
  Just one line.
\end{dialog}

\begin{dialog}
  \lipsum[2]
\end{dialog}

\end{document}
share|improve this question
add comment

1 Answer

Try to insert e.g. this

{\par\ifnum\prevgraf<2 \leavevmode\null\par\fi}

instead of just {\par} in the definition of the "ending" of the dialog environment.

Edit: I corrected your ME to make it a MWE;).

Edit 2: note that this simple solution will break if the dialog environment contains more than one paragraph and the last one has less than two lines. To work in such a case, one would probably need to redefine \par, which is definitely not something for the faint-of-heart.

share|improve this answer
1  
Probably \ifnum\prevgraf<2 would be better. –  egreg Feb 26 '12 at 20:04
    
Change to \usepackage[demo]{graphicx}, then you can compile without the image. –  Peter Grill Feb 26 '12 at 20:04
    
@PeterGrill: the fake image might be too big then. –  mbork Feb 26 '12 at 20:04
    
@egreg: theoretically yes, practically it won't matter too much;). But I corrected this anyway. –  mbork Feb 26 '12 at 20:05
    
It worked! mbork, thank you very much for quick response. –  Emrah Akyar Feb 26 '12 at 20:06
show 1 more 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.