6

I'd like to put some right-aligned text on the first line of my paragraph, and have the rest of the text wrap around it, like this:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed      {right-aligned text}
do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat...

How can I achieve this?

1
  • 1
    Do you mean kind of like a wrapfig?
    – cmhughes
    Commented Oct 6, 2011 at 21:23

2 Answers 2

6

Use the wrapfig package:

\documentclass[12pt]{article}
\usepackage[showframe]{geometry}% http://ctan.org/pkg/geometry
\usepackage{wrapfig}% http://ctan.org/pkg/wrapfig
\usepackage{xparse}% http://ctan.org/pkg/xparse
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\begin{document}
\NewDocumentCommand{\rtext}{O{1} O{5em} m}{%
  \begin{wrapfigure}[#1]{r}[0pt]{#2}%
    \begin{minipage}{#2}\raggedleft#3\end{minipage}%
  \end{wrapfigure}%
}
\rtext[5][50pt]{Here is some right-aligned text}%
\lipsum[1]
\end{document}​

enter image description here

The above code provides \rtext[<lines>][<width>]{<stuff>} that typesets <stuff> right-aligned (actually \raggedleft) in <lines> lines of width <width> (the default is 1 line with width 5em, although this can be changed). Both <lines> and <width> are optional arguments.

geometry was used with the option showframe to show the alignment of the text. lipsum provided dummy text, while xparse provides an easy means for specifying mixed optional/mandatory arguments (and defaults).

3
  • Thanks! Is there a way to make it automatically adjust the width to fit its contents?
    – jtbandes
    Commented Oct 7, 2011 at 2:05
  • Also, what's the point of the minipage? It seems to work without it.
    – jtbandes
    Commented Oct 7, 2011 at 2:24
  • 1
    You could try to use the varwidth package to adjust the width automatically based on the contents. The minipage was just to provide a box to put stuff in; I wasn't sure how much content you wanted in the {right-aligned text}.
    – Werner
    Commented Oct 7, 2011 at 7:45
0

Also see both answers to Float right aligned text around a text snippet in first line of a paragraph. Wrapfig does not work well with enumerate and itemize while \parshape and birectional layout (e.g. \luatextextdir and \beginR) can both handle this case as well.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .