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}
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).
wrapfig
?