如何将文本右对齐而不添加额外的垂直间距?

如何将文本右对齐而不添加额外的垂直间距?

我只是想将一个段落向右对齐。但是,当我尝试使用flushright环境时,该环境上方会添加额外的垂直空间:

\documentclass[final]{book}
\begin{document}

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Possimus ut voluptatem at voluptatibus omnis ratione tenetur. A, voluptates. Enim beatae suscipit nesciunt sunt voluptatem, sit blanditiis nobis accusamus vitae nisi tempora odit eius molestias laborum obcaecati maiores optio placeat aut temporibus alias omnis porro minus ex! Illum dolores, explicabo assumenda?

\begin{flushright}
This text should be aligned to right side with no vertical space above it.
\end{flushright}

Some regular text which should not be affected by above commands.

\end{document}

另一方面,当我尝试使用时\raggedleft,此段落之前没有添加垂直空间,但所有后续段落也右对齐(这不是我想要的):

\documentclass[final]{book}
\begin{document}

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Possimus ut voluptatem at voluptatibus omnis ratione tenetur. A, voluptates. Enim beatae suscipit nesciunt sunt voluptatem, sit blanditiis nobis accusamus vitae nisi tempora odit eius molestias laborum obcaecati maiores optio placeat aut temporibus alias omnis porro minus ex! Illum dolores, explicabo assumenda?

\raggedleft This text should be aligned to right side with no vertical space above it.

Some regular text which should not be affected by above commands.

\end{document}

我不确定使用后如何才能将文本取消对齐为默认(对齐)\raggedleft

有没有办法将文本右对齐,而不会添加额外的垂直空间或影响对齐后的所有文本?

答案1

尝试

{\raggedleft text\dots \par}

如果您希望段落右对齐。

\documentclass{article}

\begin{document}
  Right-aligned wants \verb|\raggedleft|:\par
  {\raggedleft text \par}
  Left-aligned wants \verb|\raggedright|:\par
  {\raggedright text \par}
\end{document}

左 - 右 右 - 左

答案2

您可以将其保留\raggedright在一个组中,只需确保段落的末尾位于该组中即可:

 {\raggedright text..... \par}

相关内容