# Combining centering with \narrowragged

Package varwidth defines the command \narrowragged that allows us to have narrow paragraphs. It makes all the lines, including the last one, to have approximately the same length:

\documentclass{article}
\usepackage{varwidth}

\begin{document}
Quisque ullamcorper placerat ipsum. Cras nibh. Morbi vel justo vitae lacus
tincidunt ultrices. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In
hac habitasse platea dictumst.

\narrowragged{
Quisque ullamcorper placerat ipsum. Cras nibh. Morbi vel justo vitae lacus
tincidunt ultrices. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In
hac habitasse platea dictumst.
}
\end{document}


How can I get the same result, but in addition have every line centered, similarly to the effect of \centering?

• do you want the narrow paragraph centered as a paragraph, or every line centered? (your comment on the answer by @HarishKumar implies the latter.) – barbara beeton Apr 7 '15 at 13:01
• Every line centered, like the effect of \centering. The update to the accepted solution does just that. – Desik Apr 7 '15 at 13:42
• okay -- the "global" centering is only in your comment; for maximum visibility, it should be in the answer itself, with a visual. i'll ask @HarishKumar to add it. – barbara beeton Apr 7 '15 at 15:28

## 2 Answers

Add this to your preamble

\makeatletter
\renewcommand\narrowragged{\leftskip \z@ plus .25\hsize\rightskip \z@ plus .25\hsize
\@rightskip\rightskip \parfillskip\z@ plus .15\hsize
\sloppy }
\makeatother


Code:

\documentclass{article}
\usepackage{varwidth}

\makeatletter
\renewcommand\narrowragged{\leftskip \z@ plus .25\hsize\rightskip \z@ plus .25\hsize
\@rightskip\rightskip \parfillskip\z@ plus .15\hsize
\sloppy }
\makeatother

\begin{document}
Quisque ullamcorper placerat ipsum. Cras nibh. Morbi vel justo vitae lacus
tincidunt ultrices. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In
hac habitasse platea dictumst.

\narrowragged
Quisque ullamcorper placerat ipsum. Cras nibh. Morbi vel justo vitae lacus
tincidunt ultrices. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In
hac habitasse platea dictumst.

\end{document}


With a new command like

\makeatletter
\newcommand\narrowcenter{\leftskip \z@ plus .25\hsize\rightskip \z@ plus .25\hsize
\@rightskip\rightskip \parfillskip\z@ \sloppy }
\makeatother


You get centering of individual lines

• That's exactly what i needed. Here is a slightly improved version, that also centers the last line: \makeatletter \newcommand\narrowcenter{\leftskip \z@ plus .25\hsize\rightskip \z@ plus .25\hsize  \@rightskip\rightskip \parfillskip\z@  \sloppy } \makeatother – Desik Apr 7 '15 at 11:35
• Harish -- can you please add the code from the comment to your answer, with a visual? the question was edited to say that every line should be centered in the narrowed region. – barbara beeton Apr 7 '15 at 15:30
• @DenisBogdanas -- the change you proposed still doesn't center the first line of the narrowed paragraph -- it doesn't account for the \parindent. what exactly do you want to happen in that situation? – barbara beeton Apr 7 '15 at 16:15
• @barbarabeeton: Adding a \noindent before the paragraph will do that. I pasted just the command definition. – Desik Apr 7 '15 at 17:25
• @DenisBogdanas -- i know how to make this work as you describe, but i'm thinking of new latex users who are looking for answers here. if an answer isn't clear, then that user often asks a new (and usually unnecessary) question. what i'm striving for is answers that are complete, that a new user can make use of immediately, without further questions. – barbara beeton Apr 7 '15 at 18:51

\narrowragged does not take an argument, as used in the question the {} do nothing and the command would affect the rest of the document.

Here you want to use varwidth

\documentclass{article}
\usepackage{varwidth}

\begin{document}
Quisque ullamcorper placerat ipsum. Cras nibh. Morbi vel justo vitae lacus
tincidunt ultrices. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In
hac habitasse platea dictumst.

\begin{center}
\begin{varwidth}{\textwidth}
\narrowragged
Quisque ullamcorper placerat ipsum. Cras nibh. Morbi vel justo vitae lacus
tincidunt ultrices. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In
hac habitasse platea dictumst.
\end{varwidth}
\end{center}

\end{document}