我一直试图在多列环境中将一些对齐文本左对齐,但没有成功。我几乎在每个能想到的地方都尝试输入 \raggedright 和 \RaggedRight。我还看到了用户 lockstep 的回答,推荐了这行代码:
\usepackage{ragged2e}
\usepackage{etoolbox}
\AtBeginEnvironment{multicols}{\RaggedRight}
我也尝试过用这个,但是没有用
以下是一些显示此问题的示例代码:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multicol}
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage{ragged2e}
\usepackage{etoolbox}
\AtBeginEnvironment{multicols}{\RaggedRight}
\title{multicol alignment}
\author{Jonas}
\date{May 2022}
\begin{document}
\begin{multicols}{2}
\blindtext
\columnbreak
\centering
\includegraphics[width=0.45\textheight]{image.png}
\end{multicols}
\end{document}
这只会产生以下输出,其中文本仍然对齐并且不左对齐:
答案1
multicol
从这个简化的例子中可以看出,这个问题与
\documentclass{article}
\begin{document}
\raggedright
aaa bbb ccc one two three January February March
aaa bbb ccc one two three January February March
aaa bbb ccc one two three January February March
aaa bbb ccc one two three January February March
aaa bbb ccc one two three January February March
aaa bbb ccc one two three January February March
aaa bbb ccc one two three January February March
aaa bbb ccc one two three January February March
\bigskip
aaa bbb ccc one two three January February March
aaa bbb ccc one two three January February March
aaa bbb ccc one two three January February March
aaa bbb ccc one two three January February March
aaa bbb ccc one two three January February March
aaa bbb ccc one two three January February March
aaa bbb ccc one two three January February March
\centering
XXX
\end{document}
换行发生在段落末尾,此时设置生效。因此,此处,第一个段落设置为右侧参差不齐,但\centering
其发布时间早于第二个段落(正式)结束,因此设置为居中,尽管它出现在 之前\centering
。
如果在发布之前以空白行结束段落\centering
,那么它将变得参差不齐,并且居中仅适用于以下 XXX。