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.

This question has been asked before (and in fact I stole the diagram below from that question) but the answers are not sufficient for my needs (at least near as I can tell).

What I want is the following:

Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Aenean quis mi ut elit interdum imperdiet quis non ante.
Sed imperdiet, sapien quis    +------------------------+
viverra rhoncus, tellus dui   |                        |
dictum nisl, at porta purus   |                        |
ipsum ac turpis. Fusce auctor |         FIGURE         |
ullamcorper adipiscing. Nunc  |          HERE          |
non quam ac orci egestas con- |                        |
sequat ut eget quam. Cras     |                        |
blandit condimentum ornare.   +------------------------+
Curabitur aliquam, nulla sit amet iaculis tristique, mi
nulla auctor magna, sit amet imperdiet ante arcu a libero.

However, I do not want the "figure here" bit to start at the top of the paragraph. I've played around with wrapfig and picins and looked at the documentation for floatflt, and haven't really found anything. (wrapfig seems to always put it at the top, floatflt doesn't have any options for that sort of placement, and picins appears to start a new paragraph.)

Is there any way to do it besides render the document without the figure, look where the line break is, force a line break at that point, start a new paragraph, and \noindent? As much as I enjoy doing that sort of thing and think it falls right in line with TeX's philosophy of "don't worry about layout specifics", ideally that wouldn't apply here. Also ideal is if it can figure out how big the figure is, instead of me telling it.

share|improve this question
add comment

3 Answers

up vote 14 down vote accepted

I recommend you take a look at the cutwin package. Here's an MWE (Minimum Working Example) that demonstrates how it might be used in practice:

\documentclass{article}
\usepackage{cutwin,lipsum}
\usepackage[demo]{graphicx}
\opencutright
\begin{document}

% Define contents of "cutout window" before starting
%   the cutout environment. For this MWE, use a
%   "dummy" image (a black rectangle).
\def\windowpagestuff{\flushright 
   \includegraphics[width=2in,height=1in]{DummyFileName}}

% Set the cutout to start after 3 lines of text
%   and to have a height of 8 lines; width of
%   this cutout: 0.5\textwidth .
\begin{cutout}{3}{0.5\textwidth}{0pt}{8}
     \noindent
     \lipsum[1]
\end{cutout}
\end{document}

enter image description here

Note that I've loaded the graphicx package with the demo option, which allows me to load a "dummy" graphics file. In actual practice, one would omit the demo option and load a "real" graphics file.

Addendum If the paragraph in question is located close to a page break, things may become a bit unpredictable. When in doubt, you could "encase" the cutout environment in a pair of \begin{minipage}{\textwidth} and \end{minipage} statements.

share|improve this answer
1  
I used to also use \rule but then discovered that with \usepackage[demo]{graphicx}, you can simply use \includegraphics[width=2in,height=1in]{imageFileName}. Just an FYI. –  Peter Grill Jan 11 '12 at 23:07
    
Great, thanks! It's too bad that (it seems) Latex has no way of doing this without specifying the actual size of stuff. (You might actually be able to do something with putting the window contents into a box and then using settobox and the calc package or something... but I think I'm too lazy.) –  EvanED Jan 11 '12 at 23:10
    
@EvanED: I suspect that once you start playing with cutouts and other non-rectangular paragraph shapes -- while keeping the font size fixed -- there's probably no general method for automating the calculations of the size of the cutout, the size of the image, etc. I suspect it's a case of either too many free parameters (no unique solution) or not enough free parameters (so that the even the existence of a solution might not be fulfilled except as a fluke). –  Mico Jan 12 '12 at 3:11
    
@Mico: It is not a case of too may free parameters: ConTeXt does the calculations in terms of number of lines using \placefigure[right,hanging,3*lines,none]{}{...} –  Aditya Jan 12 '12 at 21:53
    
@Aditya -- I stand corrected. Thanks! –  Mico Jan 13 '12 at 1:03
show 1 more comment

The \parshape primitive of TeX allows you to specify the paragraph shape on a line-by-line basis using an <indent> <width> pair. Why include this approach when Mico already did such a nice and clean approach via cutwin? Well, using \parshape allows you to typeset arbitrary (non-rectilinear) shapes as well, making it useful to understand how it works.

The following example is a crude reproduction of cutwin using \parshape and requires some manual intervention. It won't work well close to page breaks, but the same holds for wrapfig and friends.

enter image description here

\documentclass{article}
\usepackage[demo]{graphicx}% http://ctan.org/pkg/graphicx
% The 'demo' option creates a 150pt x 100pt black rectangle by default
\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam et nunc id sem dictum ullamcorper 
ut vitae augue. Etiam vehicula, dolor sit amet eleifend imperdiet, tortor neque mollis dui, ut 
laoreet neque lectus a metus. Vivamus fermentum, tellus eget cursus mollis, mi orci facilisis lacus, 
vitae aliquet arcu est nec tortor. Integer ut nunc vulputate velit dapibus sodales eget eu nulla. 
Duis mattis tristique justo semper condimentum. Phasellus eu libero odio. Integer interdum turpis in 
metus rhoncus ac tempus tortor fermentum.

% Image inclusion
\newlength{\figwidth}%
\setlength{\figwidth}{\dimexpr\linewidth-150pt-2ex\relax}
\null\hfill\smash{\raisebox{-\dimexpr 9.5\baselineskip+\parskip\relax}%
  {\includegraphics{image}}}\strut \\[-\dimexpr 3\baselineskip+2\parskip\relax]

% Paragraph formatting
\parshape=13 % 13 lines will be adjusted
0pt \linewidth 0pt \linewidth % 2 lines are regular
0pt \figwidth 0pt \figwidth 0pt \figwidth 0pt \figwidth 0pt \figwidth
0pt \figwidth 0pt \figwidth 0pt \figwidth 0pt \figwidth 0pt \figwidth % 10 lines are indented on right
0pt \linewidth % last line resets the paragraph alignment to regular
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam et nunc id sem dictum ullamcorper 
ut vitae augue. Etiam vehicula, dolor sit amet eleifend imperdiet, tortor neque mollis dui, ut 
laoreet neque lectus a metus. Vivamus fermentum, tellus eget cursus mollis, mi orci facilisis lacus, 
vitae aliquet arcu est nec tortor. Integer ut nunc vulputate velit dapibus sodales eget eu nulla. 
Duis mattis tristique justo semper condimentum. Phasellus eu libero odio. Integer interdum turpis in 
metus rhoncus ac tempus tortor fermentum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam et nunc id sem dictum ullamcorper 
ut vitae augue. Etiam vehicula, dolor sit amet eleifend imperdiet, tortor neque mollis dui, ut 
laoreet neque lectus a metus. Vivamus fermentum, tellus eget cursus mollis, mi orci facilisis lacus, 
vitae aliquet arcu est nec tortor. Integer ut nunc vulputate velit dapibus sodales eget eu nulla. 
Duis mattis tristique justo semper condimentum. Phasellus eu libero odio. Integer interdum turpis in 
metus rhoncus ac tempus tortor fermentum.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam et nunc id sem dictum ullamcorper 
ut vitae augue. Etiam vehicula, dolor sit amet eleifend imperdiet, tortor neque mollis dui, ut 
laoreet neque lectus a metus. Vivamus fermentum, tellus eget cursus mollis, mi orci facilisis lacus, 
vitae aliquet arcu est nec tortor. Integer ut nunc vulputate velit dapibus sodales eget eu nulla. 
Duis mattis tristique justo semper condimentum. Phasellus eu libero odio. Integer interdum turpis in 
metus rhoncus ac tempus tortor fermentum.

\end{document}​

\parshape=<n> <i1> <l1> <i2> <l2> ... sets the line indents and line widths for the following <n> lines in a paragraph. If the paragraph continues past <n> lines, it uses the last set <i> <l> pair.

So, in the above MWE, the image is first set, followed by the paragraph:

  • Image: image is typeset flush right and \smashed, and dropped (via \raisebox) into position. A manual calculation of the number of lines depends on the image height. In my example, the image is dropped 9.5\baselineskip+\parskip. The vertical back-skip/correction after setting the image is needed so that prior paragraphs line up.
  • Paragraph: The first two lines (out of 13) is indented 0pt and has a width of \linewidth. The next 10 lines have a width of \figwidth, set to \linewidth-150pt-2ex which leaves a 2ex gap between the paragraph text and image. The last (13th) line resets the paragraph style back to no indent (0pt) and natural width (\linewidth), just like the first two lines.

As mentioned, now it would be possible to modify this approach to accommodate images or shapes that are irregular.

share|improve this answer
    
cutwin also allows "shaped cutouts", but understanding the construction via \parshape might be just as useful. –  Werner Jan 11 '12 at 22:30
    
AFAIS, cutwin has to use \parshape under the hood. –  morbusg Jan 12 '12 at 9:47
    
Many thanks for this great explanation of how to use the TeX "primitive" command \parshape! –  Mico Jan 12 '12 at 14:55
    
@morbusg: That is correct. –  Werner Jan 12 '12 at 15:05
add comment

See also the old but still useful picinpar package from LaTeX 2.09 times:

\documentclass{article}
\usepackage{picinpar}
\usepackage{lipsum}

\begin{document}

\begin{window}[2,r,\rule{4cm}{3cm},]
\lipsum[1]
\end{window}

\end{document}

enter image description here

share|improve this answer
add 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.