wrapfig 和 wraptable 不遵守 \FloatBarrier

wrapfig 和 wraptable 不遵守 \FloatBarrier

我已经使用这个论坛一年了,它非常有用。我有一个关于浮动图形和表格的问题。它似乎已经在这里得到解决:浮动 - 如何将浮动限制在文档的一个部分中的子部分?

但是,我发现很多情况下\FloatBarrierwrapfig 和 wraptable 不起作用。我明显遗漏了什么吗?下面是我的最小工作示例。即使使用显式命令,wraptable 也不会进入其指定的部分\FloatBarrier。有什么想法吗?谢谢!

\documentclass[12pt]{report}

\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage{float}
\usepackage[section]{placeins}

\begin{document}

\section{Characterization of Porosity}

\Blindtext

\begin{wraptable}{L}{0.4\textwidth}
 \caption{Comparison of porosity parameters.}
\begin{center}
 \begin{tabular}{lccc}
 Fabric &                       $K_{n}$&$K_{c}$   \\ \hline
 A                              & 0.53 & 0.772      \\
 B                              & 0.56 & 0.533       \\
 B, speckled                    & 0.56 & 0.485       \\
 \end{tabular}
\end{center}
\label{t:porosity_label}
 \end{wraptable}

\FloatBarrier
\section{Strain Effect on Porosity}

\Blindtext

\end{document}

答案1

1)略有不同的 MWE

据我所知,它表现出了您所谈论的相同类型的行为:

\documentclass[a5paper,12pt]{memoir}
\usepackage{graphicx, wrapfig, lipsum}

\begin{document}
\section{First section}
% \lipsum[1]  % uncommenting this make image jump to after section 2
\begin{wrapfigure}{R}{0.4\linewidth}        
    \centering
    \includegraphics[width=1\linewidth]{example-image-a}%
    \caption{ This is example image A }
\end{wrapfigure}
\lipsum[1]

\section{Second section}
\lipsum[2]
\end{document}

下页同

如果注释掉这几行,结果看起来不错: 1_工作正常_imcat

但是,如果取消注释该行,图像将跳转到最后: 2_notOK_imcat 有时,只需添加一个字符即可触发此“跳跃”。就我个人而言,跳跃这么远并不是我所期望的行为。

2) \WFclear

唐纳德·阿瑟诺 (wrapfig 开发者)建议\WFclear为此使用内置的未记录的命令。

\documentclass[a5paper,12pt]{memoir}
\usepackage{graphicx, wrapfig, lipsum}

\begin{document}
\section{First section}

\lipsum[1]

\begin{wrapfigure}{R}{0.4\linewidth}        
    \centering
    \includegraphics[width=1\linewidth]{example-image-a}%
    \caption{ This is example image A }
\end{wrapfigure}
\lipsum[2]

% \lipsum[3]  % if uncommented, the image would be next-to-this paragraph


\WFclear

\section{Second section}
\lipsum[2]
\end{document}

下页同

乍一看,这就是您所需要的。如果没有合适的段落,它只会将图像与文本分开: 3_WFclear_one_par_imcat

并使用第一个合适的(如果有): 4_WFclear_two_par_imcat

然而,段落太短也存在一个需要注意的地方:

\documentclass[a5paper,12pt]{memoir}
\usepackage{graphicx, wrapfig, lipsum}

\begin{document}
\section{First section}

\lipsum[1]

\begin{wrapfigure}{R}{0.4\linewidth}        
    \centering
    \includegraphics[width=1\linewidth]{example-image-a}%
    \caption{ This is example image A }
\end{wrapfigure}
\lipsum[2]

% \lipsum[3]  % if uncommented, the image would be next-to-this paragraph
This is a very short paragraph.

\WFclear

\section{Second section}
\lipsum[2]
\end{document}

下页同

在此处输入图片描述

3) \WFfill

和 Donald 的帖子一样提出了一个解决方案:

\documentclass[a5paper,12pt]{memoir}
\usepackage{graphicx, wrapfig, lipsum}

%%% Adds empty text lines next to the wrapfigure, 
%   if the paragraph is shorter than needed.
\makeatletter 
\def\WFfill{\par 
    \ifx\parshape\WF@fudgeparshape 
    \nobreak 
    \ifnum\c@WF@wrappedlines>\@ne 
    \advance\c@WF@wrappedlines\m@ne 
    \vskip\c@WF@wrappedlines\baselineskip 
    \global\c@WF@wrappedlines\z@ 
    \fi 
    \allowbreak 
    \WF@finale 
    \fi 
} 
\makeatother 


\begin{document}
\section{First section}

\lipsum[1]

\begin{wrapfigure}{R}{0.4\linewidth}        
    \centering
    \includegraphics[width=1\linewidth]{example-image-a}%
    \caption{ This is example image A }
\end{wrapfigure}
\lipsum[2]

% \lipsum[3]  % if uncommented, the image would be next-to-this paragraph (works OK)
This is a very short paragraph.

% \lipsum[3]  % if uncommented, this paragraph would wrap the figure as well (works OK)

\WFfill
\WFclear


\section{Second section}
\lipsum[4]
\end{document}

下页同

现在短段落的情况看起来并不是那么糟糕: short_paragraph_issue_fixed

如果第一个合适但太短的段落后面跟着另一个段落,那么也可以完美地发挥作用: 7_short_paragraph_issue_fixed2

4)放入\section

只是喜欢 FloatBarrier,这些命令可以嵌入到\section

\documentclass[a5paper,12pt]{memoir}
\usepackage{graphicx, wrapfig, lipsum}

%% Adds empty text lines next to the wrapfigure, if the paragraph is shorter than needed.
\makeatletter 
\def\WFfill{\par 
    \ifx\parshape\WF@fudgeparshape 
    \nobreak 
    \ifnum\c@WF@wrappedlines>\@ne 
    \advance\c@WF@wrappedlines\m@ne 
    \vskip\c@WF@wrappedlines\baselineskip 
    \global\c@WF@wrappedlines\z@ 
    \fi 
    \allowbreak 
    \WF@finale 
    \fi 
} 
\makeatother 

%% Modify `\section` definition to include all the barriers inside.
\usepackage{placeins}
\let\Oldsection\section
\renewcommand{\section}{\WFfill\WFclear\FloatBarrier\Oldsection}


\begin{document}
\section{First section}

\lipsum[1]

\begin{wrapfigure}{R}{0.4\linewidth}        
    \centering
    \includegraphics[width=1\linewidth]{example-image-a}%
    \caption{ This is example image A }
\end{wrapfigure}
\lipsum[2]

% \lipsum[3]  % if uncommented, the image would be next-to-this paragraph (works OK)
This is a very short paragraph.

% \lipsum[3]  % if uncommented, this paragraph would wrap the figure as well (works OK)


\section{Second section}
\lipsum[4]
\end{document}

下页同

相关内容