如果文本必须换行,是否有可能平衡行数\parbox
?
\documentclass[a4paper]{scrartcl}
\usepackage{polyglossia}
\setmainlanguage{english}
\begin{document}
\parbox{35mm}{\centering This is text}
\parbox{35mm}{\centering This is some more text}
\end{document}
输出:
This is text
This is some more
Text
虽然我希望
This is text
This is some
more Text
答案1
使用 ragged2e 和\Centering
:
\documentclass[a4paper]{scrartcl}
\usepackage{polyglossia}
\usepackage{ragged2e}
\setmainlanguage{english}
\begin{document}
\parbox{35mm}{\centering This is some more text}
\parbox{35mm}{\Centering This is some more text}
\end{document}
答案2
虽然这很粗糙而且缓慢,但是它可以完成您想要的操作。
\documentclass{article}
\parskip=3ex
\newcommand{\centerbox}[2]% #1 = max width, #2 = contents
{\begingroup% save registers
\dimendef\height=0
\dimendef\width=1
\dimendef\test=2
\settoheight{\height}{\parbox{#1}{\centering #2}}%
\width=#1\relax
\loop
\advance\width by -1em
\settoheight{\test}{\parbox{\width}{\centering #2}}%
\ifdim\test=\height\repeat
\advance\width by 1em
\makebox[#1][c]{\parbox{\width}{\centering #2}}%
\endgroup}
\begin{document}
\parbox{30mm}{\centering This is some more text}
\centerbox{30mm}{This is some more text}
\end{document}