在下面的 MWE 中,我想将文本居中。但我希望每个段落的文本都与上一段在同一行开始。因此使用 \center 不是一种选择。如何做到这一点?
\documentclass{report}
\begin{document}
\chapter{chaptername}
This text I want to have centered\\
And this this sentence should start on the same line as the previous one.
\end{document}
答案1
我猜您正在寻找varwidth
;\raggedright
如果它不是您想要的内部文本,请删除pcenter
。
\documentclass{report}
\usepackage{varwidth}
\usepackage{lipsum}% for context
\newenvironment{pcenter}
{\begin{center}\begin{varwidth}{\textwidth}\raggedright}
{\end{varwidth}\end{center}}
\begin{document}
\chapter{chaptername}
\lipsum[2]
\begin{pcenter}
This text I want to have centered
And this this sentence should start on the same line as the previous one.
\end{pcenter}
\lipsum[3]
\end{document}