将居中与 \narrowragged 结合

将居中与 \narrowragged 结合

varwidth定义了允许我们有窄段落的命令\narrowragged。它使所有行(包括最后一行)的长度大致相同:

\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}

我怎样才能获得相同的结果,但此外还使每一行居中,类似于的效果\centering

答案1

将此添加到你的序言中

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

代码:

\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}

在此处输入图片描述

使用如下新命令

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

你可以将每条线居中

在此处输入图片描述

答案2

\narrowragged不接受参数,正如问题中所用,它{}不执行任何操作,并且命令会影响文档的其余部分。

在这里你想使用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}

相关内容