[Tex/LaTex] Centered-justified style

horizontal alignment

Is there a text style that is centered and places words on lines in such a way that it looks justified on the left and right sides? I'm not looking for a fixed justified text, but kind of boxing whose width will adapt depending on the words to place.

The idea to to prevent single words to be put on a new line, but rather to take more words from the previous line to make it look more justified.

Here is an example to make it clearer. I have a macro that does this:

% opening quote
\newcommand{\dvquote}[2]{
  \begin{center}\parbox{110mm}{
    \begin{center}
    \begin{itshape}#1\end{itshape}\\
    ---~\textsc{#2}
    \end{center}
  }\end{center}\vspace{-5mm}}

On some occasions it produces a line with a single word, such as the following:
centered text with single word on last line

This is not very balanced, so I would like something like:
centered text with carriage return

Same amount of lines, but more balanced. It's easy enough to achieve when needed, by adding a manual carriage return, but I'm wondering if there's some kind of automatic style that would achieve this.

Reducing the width of the paragraph to be under 110mm is not an option because I need most quotes to be quite large, and even then, the same problem might happen with just about any fixed width anyway.

In a kind of similar issue (which may have the same solution), I have a box defined by:

% central quote
\usepackage{fancybox}
\newcommand{\dvbox}[1]{
  \begin{center}\doublebox{
    \parbox{10cm}{
      \vspace{3mm}
        \begin{center}
          \parbox{9cm}{\textsc{#1}}
        \end{center}
      \vspace{3mm}
    }
  }\end{center}}

which produces justified output such as:

justified box with two lines

Occasionally though, there is not enough to fill a whole line, so I get:

justified box with one line

which would probably look better centered. Is there a standard approach to fix this?

Best Answer

This is a known problem with LaTeX (and a regression from plain TeX), and the reason for the the ragged2e package. Maybe using the \Centering command (or Center environment) from this package will do what you want. Or just load the package with the [newcommands] option and keep the rest of the document unchanged. You may have to fiddle with the ragged2e parameters to get good results.