2

The following MWE produces four paragraphs:

  1. left-aligned and justified, with a hanging indent
  2. left-aligned, with a hanging indent
  3. right-aligned, with a "hanging indent" on the left side
  4. right-aligned, with the desired "hanging indent"

The question is: how can I, in the easiest way possible, produce the 4th paragraph?

\documentclass{article}
\begin{document}

\hangindent=3cm \noindent Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

\begin{flushleft}
    \hangindent=3cm Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{flushleft}

\begin{flushright}
    \hangindent=3cm Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{flushright}

\begin{flushright}
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor\\
    incididunt ut labore et dolore magna aliqua. Ut enim ad minim \hspace{3cm}~\\
    veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip \hspace{3cm}~\\
    ex ea commodo consequat. Duis aute irure dolor in reprehenderit in \hspace{3cm}~\\
    voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur \hspace{3cm}~\\
    sint occaecat cupidatat non proident, sunt in culpa qui officia \hspace{3cm}~\\
    deserunt mollit anim id est laborum.\hspace{3cm}~
\end{flushright}
\end{document}

mwe

3

It would be possible to use a (negative) \hangindent:

\documentclass{article}

\newenvironment{flushrighthang}[1][3cm]{\begin{flushright}\hangindent-#1}
    {\end{flushright}}

\begin{document}

\begin{flushrighthang}
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
 \end{flushrighthang}

\begin{flushrighthang}[6cm]
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
\end{flushrighthang}


\end{document}

flushright with hanging indentation

4
  • Interestingly, the only place that The TeXbook mentions negative values for \hangindent is in the answer to exercise 14.23. Thirty-five years after I first read The TeXbook, I finally noticed that part. My own solution for the exercise when I did it back then was to use \parshape and I didn't look in the back of the book for the solution because mine worked. – Don Hosek Feb 21 at 18:10
  • 1
    @DonHosek Oddly enough, I just had to use this in a project recently and had to dig around in The TeXbook to check my memory. As an aside, in working on this, I also tried to make the first line of the paragraph exactly \textwidth in length, with the remainder of the paragraph left-rag and with hanging indentation -- I know the OP did not expect that, I was just curious. So far, I have not found the right incantation... – sgmoye Feb 21 at 20:16
  • Damnit, you've made me lose a bunch of time trying to do that first line thing. By the way, I remember your Fontographer book (assuming I'm remembering the right Fontographer book). I don't remember if I ever actually owned it but I remember looking at a copy in the Costa Mesa Barnes & Noble and seeing my name in the index (unless I'm getting decades old memories completely messed up). – Don Hosek Feb 22 at 0:45
  • @DonHosek Indeed. Annoying, isn't it, that what seems as if it would be a relatively straightforward thing to do should prove so elusive -- spent an inordinate amount of time on it myself. Yes, that's me. The book seems so antediluvian now... – sgmoye Feb 22 at 11:12
4

You'll want to wrap this up in a \newenvironment but this will do the trick:

 \newlength{\shortline}
 \setlength{\shortline}{\textwidth}
 \addtolength{\shortline}{-3cm}
 \begin{flushright}
       \parshape 2 0pt \textwidth 0pt \shortline  Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed 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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
   \end{flushright}
3

Similar to Don's answer, however the environment accepts several paragraphs all with the specified shape.

\documentclass{article}

\newenvironment{almostflushright}[1]
 {% #1 is the amount of hanging
  \par\addvspace{\topsep}
  \raggedleft
  \everypar{\parshape 2 0pt \columnwidth 0pt \dimexpr\columnwidth - #1\relax}
 }
 {\par\addvspace{\topsep}}

\begin{document}

\noindent\hfill\makebox[3cm][s]{\hrulefill}\par % check the indent

\begin{almostflushright}{3cm}
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed 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. Duis aute irure dolor in reprehenderit in
    voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
    sint occaecat cupidatat non proident, sunt in culpa qui officia
    deserunt mollit anim id est laborum.

    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
    incididunt ut labore et dolore magna aliqua. Ut enim ad minim
    veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
\end{almostflushright}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.