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.

How can I use lettrine at the start of a paragraph used in the wrapfigure environment.

Consider the following code:

\documentclass{article}

\RequirePackage[demo]{graphicx}
\usepackage{lettrine}
\usepackage{wrapfig}
\newcounter{cnt}\setcounter{cnt}{0}
\def\t{\stepcounter{cnt}\thecnt. cat sat on the mat. }



\begin{document}
    \begin{wrapfigure}{r}{0.3\textwidth}
        \vspace{1ex}
        \includegraphics[width=\linewidth,height=1in]{image}
    \end{wrapfigure}
    \lettrine{T}{he cat sat} \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t
\end{document}

Which yields the following result, I have shifted the image down so that the problem is made more apparent, ie, wrapfig is ignored.

Image

NOTE: David Carlisle has provided a pretty good answer so far, however, the following anomalies occur with the output, specifically, an update was made to David's original code to allow the modified lettrine (wflettrine{...}) to take the optional arguments in order to control the letter height etc, however, by default, the following output is returned if the optional argument lines=5 is now parsed.

wflettrine5

The above was achieved with the code command:

\wflettrine[lines=5]{T}{he cat sat}

And it is clear to see under the red-highlighted region, that the drop-cap letter is not taking up the whole space, strangely enough, the same behavior was observed on my machine with the default computer-modern font, under a normal use of lettrine.

By changing the font to Helvetica, via the use of the following in the preamble:

\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}

And executing the same command, yields the following output.

wflettrine_helvet

And it is clear that the previous problem is resolved (by the correct drop-cap usage under the green highlighted section), however, this has pushed the wrapfig component to the right, as can be seen under the red-highlighted section.

It appears as though the wrapfig has been pushed to the right by what appears to be the same amount as the width of the dropcap letter 'T'.

share|improve this question
    
Both \lettrine and wrapfig try setting a \parshape. The specification made by \lettrine comes second, so it wins. –  egreg Jun 18 '13 at 8:52
    
Scissor paper rock. –  Nicholas Hamilton Jun 18 '13 at 8:58
1  
Probably \lettrine should examine the current \parshape and modify it, rather than specifying a new one. As things stand it doesn't seem straightforward to modify how \lettrine works. –  egreg Jun 18 '13 at 9:01
add comment

1 Answer

up vote 14 down vote accepted
+150

enter image description here

\documentclass{article}

\RequirePackage[demo]{graphicx}
\usepackage{helvet}\renewcommand{\familydefault}{\sfdefault}
\usepackage{lettrine}
\usepackage{wrapfig}
\newcounter{cnt}\setcounter{cnt}{0}
\def\t{\stepcounter{cnt}\thecnt. cat sat on the mat. }


\newdimen\tttaa
\newdimen\tttbb

\renewcommand\thepage{\the\numexpr(\value{page}+1)/2\relax}

\makeatletter
\def\merge@ps{\afterassignment\merge@ps@\tttbb}

\def\merge@ps@{\afterassignment\merge@ps@@\tttaa}


\def\merge@ps@@{%
\afterassignment\reset@WF@ps\dimen@\WF@ps\valign
%\showthe\count@
\ifnum\count@>\@ne
\advance\count@\m@ne
\expandafter\merge@ps
\fi
}


\def\reset@WF@ps{\afterassignment\reset@WF@ps@\dimen@ii}

\def\reset@WF@ps@#1\valign{%
\edef\new@wf@ps{\new@wf@ps
  \the\dimexpr\dimen@+\tttbb\relax\space
  \the\dimexpr\dimen@ii-\tttbb\relax\space}%
 \def\WF@ps{#1}}


\newcommand\wflettrine[3][]{%
  \setbox\tw@\hbox{\lettrine[#1]{#2}{#3}\global\let\gtmp\L@parshape}%
  \afterassignment\wf@getoffset\count@\gtmp\hoffset
  \setbox\WF@box\hbox{\kern-\dimen@\box\WF@box\kern\dimen@}%
  \noindent\box\tw@
    \def\new@wf@ps{}%
    \afterassignment\merge@ps\count@\gtmp
    \edef\WF@ps{\new@wf@ps\space\WF@ps}%
    \@@parshape\c@WF@wrappedlines\WF@ps\z@\columnwidth}


\def\wf@getoffset{\afterassignment\wf@get@ffset\dimen@}
\def\wf@get@ffset#1\hoffset{}

\makeatother

\begin{document}
%%%%%%%%%%%%%%

    \begin{wrapfigure}{r}{0.3\textwidth}
        \vspace{1ex}
        \includegraphics[width=\linewidth,height=1in]{image}
    \end{wrapfigure}
    \wflettrine[lines=5]{T}{he cat sat}
    \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t
    \t\t\t\t\t\t\t\t\t


%%%%%%%%%%%%%%

    \begin{wrapfigure}{r}{0.3\textwidth}
        \vspace{1ex}
        \includegraphics[width=\linewidth,height=1in]{image}
    \end{wrapfigure}
    \wflettrine{T}{he cat sat}
    \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t
    \t\t\t\t\t\t\t\t\t


%%%%%%%%%%%%%%%%%%%%%%%
    \lettrine[lines=5]{T}{he cat sat}
    \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t
    \t\t\t\t\t\t\t\t\t


%%%%%%%%%%%%%%%%%%%%%%%

    \begin{wrapfigure}{r}{0.3\textwidth}
        \vspace{1ex}
        \includegraphics[width=\linewidth,height=1in]{image}
    \end{wrapfigure}
    The cat sat
    \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t
    \t\t\t\t\t\t\t\t\t


\end{document}
share|improve this answer
    
Thanks David, this is exactly what I want, however, the wflettrine command doesn't take the optional arguments ie \wflettrine[lines=4]{W}{ord}. Passing the extra argument on isn't difficult, the lines get changed, but the dropcap letter doesn't, so which part of your above code controls the actual dropcap letter? –  Nicholas Hamilton Jun 29 '13 at 1:32
    
@ADP I didn't know it had an optional arg:-) fixed. –  David Carlisle Jun 30 '13 at 15:22
    
What you have done (the new edit), is what I did, however, you will notice that whilst the number of lines increases, the size of the drop-cap letter does not. If you use the command \wflettrine[lines=5]{T}{he cat sat} you will see what I mean. Strange thing is, the same behaviour occurs under normal wrapfig using computermodern font, so, try with helvetica font (ie put in pramble \usepackage{helvet}\renewcommand{\familydefault}{\sfdefault}), the letter size changes correctly, but, the wrapfig spacing is put out... –  Nicholas Hamilton Jul 1 '13 at 1:03
    
Please see my updated question, which should clarify better. –  Nicholas Hamilton Jul 1 '13 at 1:23
    
@ADP OK I see, that'll be fixable. Will look later. –  David Carlisle Jul 1 '13 at 8:36
show 3 more comments

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.