在 multicols 環境中對齊文字。 \raggedright 不起作用

在 multicols 環境中對齊文字。 \raggedright 不起作用

我一直在嘗試在 multicols 環境中左對齊一些合理的文本,但沒有成功。我嘗試在我能想到的每個地方輸入 \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。

相關內容