我正在尝试创建小页面(或任何类型的框),其宽度为0.5\textwidth
或\textwidth
取决于其内容的大小。我希望较小的小页面(带有0.5\textwidth
)彼此相邻,较长的页面应自动在下一行换行。
在此示例中,我尝试做的事情被分解为:
\documentclass{article}
\begin{document}
\section*{Section}
\begin{minipage}{0.49\textwidth}
Minipage with small contents
\end{minipage}
\hfill{}
\begin{minipage}{0.49\textwidth}
Minipage with small contents
\end{minipage}
\hfill{}
\begin{minipage}{0.49\textwidth}
Minipage with small contents
\end{minipage}
\hfill{}
\begin{minipage}{\textwidth}
Minipage with a lot of very very long content which should overflow in the next line because it is not able to fit into the previous line.
\end{minipage}
\hfill{}
\end{document}
结果如下,最后一个较长的小页面应位于第三个小页面的下一行,而在长小页面所在的位置留出空白:
(我正在.tex
用一些程序代码生成文件,所以顺序并不重要,小页面是先向下排序然后向左排序还是先向下、向左、向下、向左排序,...都没关系,因为我可以轻松更改代码。)
如果可能的话,我还希望较长的迷你页面之前的迷你页面\textwidth
也能增加其大小,但这不是这个问题的主要部分。
我对 LaTex 还很陌生,如果有任何预定义环境或比 minipages 更好的选择,请随时告诉我。
在此先非常感谢您的帮助。
答案1
OP 的 MWE 的主要变化:
使用
%
在minipage
s 之间以避免出现杂散空格。用于
\hfill\allowbreak
允许换行。无需缩小
minipage
至.49\textwidth
。minipage
将s 与对齐方式对齐[b]
。\strut
在每个行结束之前应用minipage
以获得适当的行距。
妇女权利委员会:
\documentclass{article}
\usepackage[showframe,pass]{geometry}
\begin{document}
\section*{Section}
\begin{minipage}[b]{0.5\textwidth}
Minipage with small contents
\strut\end{minipage}%
\hfill\allowbreak%
\begin{minipage}[b]{0.5\textwidth}
Minipage with small contents
\strut\end{minipage}%
\hfill\allowbreak%
\begin{minipage}[b]{0.5\textwidth}
Minipage with small contents
\strut\end{minipage}%
\hfill\allowbreak%
\begin{minipage}[b]{\textwidth}
Minipage with a lot of very very long content which should overflow in the next line because it is not able to fit into the previous line.
\strut\end{minipage}%
\hfill\allowbreak%
\begin{minipage}[b]{0.5\textwidth}
Minipage with small contents
\strut\end{minipage}%
\hfill\allowbreak%
\begin{minipage}[b]{0.5\textwidth}
Minipage with small contents
\strut\end{minipage}%
\hfill\allowbreak%
\begin{minipage}[b]{0.5\textwidth}
Minipage with small contents
\strut\end{minipage}%
\hfill\allowbreak%
\begin{minipage}[b]{\textwidth}
Minipage with a lot of very very long content which should overflow in the next line because it is not able to fit into the previous line.
\strut\end{minipage}%
\end{document}