The ragged2e package
Sets ragged text that still hyphenates words (\RaggedRight, \Centering, \RaggedLeft) and returns to justified text with \justifying.
Loading the package
\usepackage{ragged2e}\raggedright, \centering and \raggedleft switch hyphenation off. In a narrow column this leaves lines that are much shorter than the others. The commands of ragged2e have the same names with capital letters and allow hyphenation, so the right edge is more even.
Plain LaTeX has no command that switches back to justified text inside a group. \justifying does that, for example in a \parbox or a table cell inside a ragged document.
Main commands
\RaggedRight | Left-aligned text with hyphenation, until the end of the group. |
\Centering | Centred text with hyphenation. |
\RaggedLeft | Right-aligned text with hyphenation. |
\justifying | Back to justified text. |
\begin{FlushLeft} ... \end{FlushLeft} | Environment forms: FlushLeft, Center, FlushRight and justify. |
>{\RaggedRight}p{4cm} | Ragged-right table column of fixed width; the >{...} syntax needs the array package. |
\usepackage[document]{ragged2e} | Sets the whole document ragged right. |
Complete example
\documentclass{article}
\usepackage{ragged2e}
\usepackage{array}
\begin{document}
\begin{tabular}{l >{\RaggedRight}p{4cm}}
Device & Description \\
\hline
Spectrometer & Measures the wavelength distribution of the incoming light. \\
Thermocouple & Measures temperature differences between two junctions. \\
\end{tabular}
\bigskip
\begin{minipage}{5cm}
\RaggedRight
A narrow column of ragged-right text. A long word such as
internationalization is hyphenated at the end of a line.
\end{minipage}
\end{document}Compiled with pdfLaTeX from TeX Live 2023.
Pitfalls
- With the option
newcommands, the package redefines\raggedright,\centering,\raggedleftand the environmentsflushleft,center,flushrightto the hyphenating versions. - The lower-case
\raggedrightin the last column of a table changes\\, and the next\hlinestops with Misplaced \noalign unless\arraybackslashfollows it.\RaggedRightleaves the row end of a table alone (checked with version 3.6 of the package). - A single short line in
FlushRightgives the warning Underfull \hbox (badness 10000) in paragraph at lines 3--4, because the ragged margin stretches by 2em at most. For one line, use the standardflushrightenvironment.
Related pages
- How-to Center, left-align and right-align text in LaTeX
- How-to Align text in table cells in LaTeX
- How-to Hyphenation in LaTeX
- Package
array