1

I am using a right aligned minipage with right aligned content. What I want is its content to look like the normal aligned one in the first minipage. The only difference being the last word I have underlined to be right aligned like it is in the second minipage. What I ask is depicted in the image.

enter image description here

MWE

\documentclass{book}

\usepackage{lipsum}

\begin{document}

\begin{flushright}

\begin{minipage}{0.65\textwidth}

\lipsum[1]

\end{minipage}

\end{flushright}

\vspace{1cm}

\begin{flushright}

\begin{minipage}{0.65\textwidth}

\begin{flushright}

\lipsum[1]

\end{flushright}

\end{minipage}

\end{flushright}

\end{document}
  • see, if the RaggedLeft from package ragged2e is what you looking for: {\RaggedLeft <your text>}. – Zarko Oct 11 '16 at 14:23
  • @Zarko I tried it, and although it is better the hyphenation is not perfect. – Adam Oct 11 '16 at 14:23
  • what is the perfect hyphenation? – Zarko Oct 11 '16 at 14:26
  • @Zarko When you right normal text like in the first minipage I show in the image. Basically what I want is to be like that but the sentence of the last line to start from the right. – Adam Oct 11 '16 at 14:28
  • then you actually ask: how to make last line in text rigged left :-) similar question you can find here (on TeX.SE). – Zarko Oct 11 '16 at 14:32
2

Typeset the text in a box, remove the last line and reinsert it after having removed the glue at its end, preceded by \hfill. The following lastflushright environment behaves like a minipage with bottom alignment. It's not difficult to get also top or center alignment.

\documentclass{book}

\usepackage{lipsum}

\makeatletter
\newenvironment{lastflushright}[1]
 {\leavevmode\vbox\bgroup\@tempdima=#1\relax
  \setbox\@tempboxa\vbox\bgroup\color@begingroup
    \hsize\@tempdima\textwidth\hsize\columnwidth\hsize
    \@parboxrestore
    \@minipagerestore\@setminipage}
 {\@minipagefalse\color@endgroup\egroup
  \setbox\@tempboxa=\vbox{\unvbox\@tempboxa\global\setbox1=\lastbox}
  \box\@tempboxa
  \setbox\@tempboxa=\hbox{\unhbox1\unskip\unskip}
  \nointerlineskip
  \hbox to\@tempdima{\hfill\box\@tempboxa}%
  \egroup
}
\makeatother

\begin{document}

\begin{lastflushright}{0.45\textwidth}
\lipsum[3]
\end{lastflushright}
\begin{minipage}[b]{0.45\textwidth}
\lipsum[3]
\end{minipage}
\end{document}

enter image description here

  • Wow I thought that it would be something simple. Thank you very much though. – Adam Oct 11 '16 at 16:55

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.