0

My question is similar to Adding right aligned text to a list item?. The important difference is that my items span multiple lines.

  • The right-aligned text itself never spans more than 1 line.
  • The right-aligned text must be at the end of the first line of the item.
  • The space between the end of the first line and the start of the right-aligned text must be larger than a specified minimum distance x.
  • The lines after the first line of the item must be allowed to go beyond the first line.
  • In the code, the contents of the item text must not be interrupted by the contents of the right-aligned text.

I could not satisfy the final condition. Here is what I produced:

The desired result.

Here is my code:

\begin{itemize}
    \item
        This item spans two lines.
        This item spans two lines.
        This item
        \hfill \textit{Some right-aligned text.} \\
        spans two lines.
        This item spans two lines.
        This item spans two lines.
        This item spans two lines.
\end{itemize}

My failure to satisfy the no-interruption condition is problematic because whenever I change the contents of the item text, I need to remove the right-aligned text, change the item text, then figure out where to reinsert the right-aligned text by means of tedious trial and error. There has to be a better way.

I'm open to any solutions that produce the same visual results and satisfy the no-interruption condition, even if they are somewhat unorthodox. However, I'd think there has to be a simple way to do this.

Another way to solve this issue would be to have a tabular environment wherein the contents of a cell are allowed to overflow. Does anyone know how to make the contents of a tabular cell overflow off the right side?

Thanks in advance!

1 Answer 1

1

This uses \quad as the "minimum distance x" (easily replaced with alternative \hspace but not \hfill). It uses \hangindent to provide a gap, and \llap to overlay the space provided.

\documentclass{article}
\newsavebox{\tempbox}
\begin{document}
\savebox{\tempbox}{\quad\textit{Some right-aligned text.}}% measuer width
\begin{itemize}
    \item\parbox[t]{\linewidth}{%
      \hangindent=-\wd\tempbox
      \hangafter=-1
        This item spans two lines.
        This item spans two lines.
        This item spans two lines.
        This item spans two lines.
        This item spans two lines.
        This item spans two lines.}\llap{\usebox\tempbox}
\end{itemize}
\end{document}

This version uses vertical overlap and no \parbox so text will break across pages.

\documentclass{article}
%\usepackage{showframe}% alignment tool
\newsavebox{\tempboxa}
\newsavebox{\tempboxb}
\begin{document}
%\noindent\rule{\textwidth}{43\baselineskip}% check page breaking

\savebox{\tempboxa}{\quad\textit{Some right-aligned text.}}% measuer width
\begin{itemize}
    \item\strut\makebox[\linewidth][r]{\usebox\tempboxa}%
      \setbox\tempboxb=\vbox{\hsize=\textwidth
        \leftskip=\csname @totalleftmargin\endcsname
        \hangindent=-\wd\tempboxa
        \hangafter=-1
        \strut
        This item spans two lines.
        This item spans two lines.
        This item spans two lines.
        This item spans two lines.
        This item spans two lines.
        This item spans two lines.
      \strut}\par\vskip-\baselineskip
      \unvbox\tempboxb
\end{itemize}
\end{document}

You must log in to answer this question.

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