![如何在当前行后添加块元素而不中断段落?](https://linux22.com/image/320572/%E5%A6%82%E4%BD%95%E5%9C%A8%E5%BD%93%E5%89%8D%E8%A1%8C%E5%90%8E%E6%B7%BB%E5%8A%A0%E5%9D%97%E5%85%83%E7%B4%A0%E8%80%8C%E4%B8%8D%E4%B8%AD%E6%96%AD%E6%AE%B5%E8%90%BD%EF%BC%9F.png)
multicols 包不支持单列浮动,仅支持 * 形式的浮动。我使用 multicols,并且我有块元素(表格、图形等)。我想浮动到单列的顶部(通常)。
我准备“手动浮动”对象。我可以看到分栏符的位置,从而看到要插入的对象之前和之后出现的内容。如何在不结束段落的情况下插入块元素?
我感觉wrapfig
宽度为\linewidth
(可以放在段落的“单词之间”,正确保留行/段落的结尾......它可能会干扰连字,但如果我处于手动调整的这个阶段,我可以更改单词以避免连字)会是答案,但我想知道是否还有其他或更好的方法。
编辑:我刚刚意识到一个可能与“浮动长表”相关的问题。有时这些数据的表格长度超过文本高度。我可以立即启动它们(可能结束多列环境)并让事情按照它们想要的方式进行,但能够说“在此页面末尾添加包含长表的块”可能会更好。也就是说,我负责做出决定,而 LaTeX“只是”执行该决定。
MWE 起点:
\documentclass{article}
\usepackage{multicol}
\usepackage{lipsum}
\title{Test Document}
\author{me}
\begin{document}
\maketitle
\begin{multicols}{2}
\lipsum[1]
Nam dui ligula, fringilla a, euismod
sodales, sollicitudin vel, wisi. Morbi
auctor lorem non justo. Nam lacus
libero, pretium at, lobortis vitae, ul-
tricies et, tellus. Donec aliquet, tortor
sed accumsan bibendum, erat ligula
aliquet magna, vitae ornare odio metus
a mi. Morbi ac orci et nisl hendrerit
mollis. Suspendisse ut massa. Cras
nec ante. Pellentesque a nulla. Cum
sociis natoque penatibus et magnis dis
parturient montes, nascetur ridiculus
mus. Aliquam tincidunt urna. Nulla
ullamcorper vestibulum turpis. Pellen-
tesque cursus luctus mauris.
\section*{Column broke on `dis'}
If I insert a manual break I get an indent on the next line because
it is a new paragraph (and the `dis line' might end up not justified,
if it otherwise had space added to cause justification --- it doesn't
seem to be the case this time). I want to be able to, say, somewhere
around `natoque' insert an instruction that says ``after this line is
complete, put a picture here''.
Or, I suppose, immediately between `dis' and `parturient' somehow say
``put the table \emph{right here}, no kidding around''. I think
wrapfig does this, but I haven't used it before, and I'm not certain of
the interactions between multicol and a wrapfig where the width is the
full linewidth.
\bigskip\noindent
\lipsum[3]
\lipsum[4]
\end{multicols}
\end{document}
答案1
\parfillskip
您可以在设置为时强制在“dis”处结束段落0pt
(请参阅是否有一个工具可以把段落变成矩形?),然后使用非浮动插入您的图形float
的[H]
ERE 规范,并使用 继续段落\noindent
。 设置的分组\parfillskip
只会影响相关段落。
\documentclass{article}
\usepackage{multicol,float,graphicx}
\usepackage{lipsum}
\title{Test Document}
\author{me}
\begin{document}
\maketitle
\begin{multicols}{2}
\lipsum[1]
{\setlength{\parfillskip}{0pt}%
Nam dui ligula, fringilla a, euismod
sodales, sollicitudin vel, wisi. Morbi
auctor lorem non justo. Nam lacus
libero, pretium at, lobortis vitae, ul-
tricies et, tellus. Donec aliquet, tortor
sed accumsan bibendum, erat ligula
aliquet magna, vitae ornare odio metus
a mi. Morbi ac orci et nisl hendrerit
mollis. Suspendisse ut massa. Cras
nec ante. Pellentesque a nulla. Cum
sociis natoque penatibus et magnis dis}
\begin{figure}[H]
\centering
\includegraphics[width=\linewidth]{example-image}
\caption{This is a figure caption.}
\end{figure}
\noindent
parturient montes, nascetur ridiculus
mus. Aliquam tincidunt urna. Nulla
ullamcorper vestibulum turpis. Pellen-
tesque cursus luctus mauris.
\section*{Column broke on `dis'}
If I insert a manual break I get an indent on the next line because
it is a new paragraph (and the `dis line' might end up not justified,
if it otherwise had space added to cause justification --- it doesn't
seem to be the case this time). I want to be able to, say, somewhere
around `natoque' insert an instruction that says ``after this line is
complete, put a picture here''.
Or, I suppose, immediately between `dis' and `parturient' somehow say
``put the table \emph{right here}, no kidding around''. I think
wrapfig does this, but I haven't used it before, and I'm not certain of
the interactions between multicol and a wrapfig where the width is the
full linewidth.
\bigskip\noindent
\lipsum[3]
\lipsum[4]
\end{multicols}
\end{document}