21

How can one set full justification within left-justified ({\raggedright [...]}) text?

An example of where I need full justification is here:

\documentclass{memoir}

\begin{document}

Document body.

\begin{thebibliography}{9}
  \SingleSpacing
\bibitem{ABC}
  {\raggedright \hyphenpenalty=10000 \exhyphenpenalty=10000
  Plenty of left-aligned text. Plenty of left-aligned text. Plenty of left-aligned text. Plenty of left-aligned text. Plenty of left-aligned text. Plenty of left-aligned text. Plenty of left-aligned text. Plenty of left-aligned text. Plenty of left-aligned text. Plenty of left-aligned text. Plenty of left-aligned text. Plenty of left-aligned text. Plenty of left-aligned text. Plenty of left-aligned text. Plenty of left-aligned text.
  \begin{list}{\(\bullet\)}
  \item Plenty of left-aligned text. Plenty of left-aligned text. Plenty of left-aligned text. Plenty of left-aligned text. Plenty of left-aligned text. Plenty of left-aligned text. Plenty of left-aligned text. \par
      \emph{Text I would like to be justified. Text I would like to be justified. Text I would like to be justified. Text I would like to be justified. Text I would like to be justified. Text I would like to be justified. Text I would like to be justified. Text I would like to be justified. Text I would like to be justified. Text I would like to be justified. Text I would like to be justified.}
  \end{list}
  }
\end{thebibliography}

\end{document}

It is self-explanatory.

Note: There are probably more minimal examples, but (aside from me needing full justification in this particular context) this one will do for a context where something obvious such as "set a smaller scope for \raggedright doesn't work.

25

use package ragged2e then you have a macro which allows to justify the text:

\usepackage{ragged2e}
....
  {\justifying\emph{Text I would....}\par}

\par is needed to activate the setting

| improve this answer | |
  • In my case I also need \noindent after \justifying, but I understand this is a stylistic matter where people have different tastes. – Lover of Structure Jan 8 '13 at 5:52
  • In my case, it works with {\justifying Text \par} only. – Mike22LFC Jul 13 '16 at 8:13
11

By restoring the meaning of \rightskip and \leftskip, a justified paragraph is also obtained. Wrapping this in a macro called \justified works similar to \raggedleft and \raggedright:

\makeatletter
\newcommand{\justified}{%
  \rightskip\z@skip%
  \leftskip\z@skip}
\makeatother

If you wish to restore a paragraph indent, you can also place it inside the \justified definition. Default would be 20pt.

| improve this answer | |
  • I am sorry, but how can I fully justify (left and right) my whole document? – Diaa Dec 8 '16 at 3:15
  • @DiaaAbidou: Issue \justifying (from ragged2e) at the start of your document. What \documentclass (or setup) do you have that doesn't show this naturally? – Werner Dec 8 '16 at 5:33
  • I am sorry it was my bad, I found it naturally fully justified, but your input was informative to me. Many thanks for your consideration. – Diaa Dec 8 '16 at 5:49
11

You could just wrap the text in a \parbox set to the \linewidth. (I've used the kantlipsum package to show some more realistic text.) One drawback of this solution as noted in the comments is that the resulting \parbox will not break across pages. For some purposes this might be acceptable, but for most applications, Herbert's solution using the ragged2e package is to be preferred.

\documentclass{memoir}
\usepackage{kantlipsum}
\begin{document}

Document body.

\begin{thebibliography}{9}
  \SingleSpacing
\bibitem{ABC}
  {\raggedright \hyphenpenalty=10000 \exhyphenpenalty=10000
  \kant[1]
  \begin{list}{\(\bullet\)}
  \item \kant[1]
      \parbox{\linewidth}{\emph{Text I would like to be justified. Text I would like to be justified. Text I would like to be justified. Text I would like to be justified. Text I would like to be justified. Text I would like to be justified. Text I would like to be justified. Text I would like to be justified. Text I would like to be justified. Text I would like to be justified. Text I would like to be justified.}}
  \end{list}
  }
\end{thebibliography}

\end{document}

output of code

| improve this answer | |
  • 4
    This has a big limitation/feature: the justified block won't be broken across pages. – egreg Jan 7 '13 at 10:25

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.