Miktex/XeLaTeX - 分页符处图像换行错误(wrapfigure)

Miktex/XeLaTeX - 分页符处图像换行错误(wrapfigure)

我已经在其他帖子中问过这个问题,但因为我针对两个问题打开了这个问题,所以只有另一个问题被讨论/回答。所以我只针对这个主题添加了一个新帖子,其中包含更多信息和完整的可重现代码。

我的目的是创建 PDF 文档,其中指定高度(和计算宽度)的图像位于右侧,并由左侧的文本包裹。文本可能很短或很长 - 内容会生成,因此 TeX 文档必须能够处理这两种可能性。

我尝试使用 wrapfigure 来实现它:

\begin{wrapfigure}{R}{0pt}
  \centering
  \includegraphics[height=4cm,width=2.5cm]{img.jpg}
\end{wrapfigure}
\paragraph{}\vspace*{-\parskip}
Some text...

完整源代码请参见下面的代码:

\documentclass[a4paper]{book}

\usepackage{fontspec}

\usepackage{polyglossia}
\setmainlanguage{czech}

\usepackage{ulem}
\usepackage{spverbatim}
\usepackage[unicode]{hyperref}
\usepackage{graphicx}
\usepackage{grffile}

\usepackage{wrapfig}
\usepackage{hologo}

\usepackage{pdfpages}


\begin{document}

\chapter{Chapter}
\section{Section}
\subsection{Subsection}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{wrapfigure}{R}{0pt}
  \centering
  \includegraphics[height=4cm,width=2.5cm]{img.jpg}
\end{wrapfigure}
\paragraph{}\vspace*{-\parskip}
Begin of text. This is short text. This is short text. This is short text. This is short text. This is short text. This is short text. This is short text.\newline
%%%%%%%%%%
\begin{wrapfigure}{R}{0pt}
  \centering
  \includegraphics[height=4cm,width=4.5cm]{img.jpg}
\end{wrapfigure}
\paragraph{}\vspace*{-\parskip}
Begin of text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text.\newline
%%%%%%%%%%
\begin{wrapfigure}{R}{0pt}
  \centering
  \includegraphics[height=4cm,width=2.5cm]{img.jpg}
  \caption{This is caption for testing purposes.}
\end{wrapfigure}
\paragraph{}\vspace*{-\parskip}
Begin of text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text.\newline
%%%%%%%%%%
\begin{wrapfigure}{R}{0pt}
  \centering
  \includegraphics[height=4cm,width=4.5cm]{img.jpg}
  \caption{This is caption for testing purposes.}
\end{wrapfigure}
\paragraph{}\vspace*{-\parskip}
Begin of text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text.\newline
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Section 2}
\subsection{Subsection 2}
\paragraph{}Section 2 contents...\newline

\end{document}

我的尝试结果乍一看是错误的,请参见所附的屏幕截图:

屏幕截图 1

屏幕截图 2

我的代码至少存在三个问题:

1)[红色备注] 如果文本太短,下一个块不会根据需要移到图像下方,而是立即开始,尽管前一个块的图像仍在渲染中。

2) [紫色注释] 虽然图片中没有标题,但图片底部边框太高。有趣的是,其他图片的底部边框是正确的。

3) [蓝色注释] 第二幅图像未与第二段文本对齐,而是下移到了下一页。此外,它位于左侧,尽管设置包含 {R} 右对齐。原因似乎在于之前的问题(图像 1 溢出到本应属于图像 2 的空间,因此图像 2 混乱并显示在错误的位置),但第二张屏幕截图 [红色注释] 中存在完全相同的错误 - 垂直和水平空间都足够,但图像也显示在下一页(即使在完全不同的部分)

以上两张截图是针对 {R} 设置截取的。我还尝试了 {r},但有其他副作用:

在此处输入图片描述

  • 图像溢出了页面底部的文本(这里只有几个像素,但仍然可见,但也可能溢出到文本区域之外的其余纸张)

  • 下一页也会受到影响 - 尽管下一页不显示任何图像部分,但前两行会因图像宽度而缩短

基本问题:wrapfigure 能满足我的要求吗?也许我正在尝试使用不方便的功能,而这些功能可能用于其他目的。

如果不是,那么可以使用哪种其他方法让文本正确地包裹图像,而不会导致文本或图像的垂直/水平溢出?

如果可以使用wrapfigure,我的代码需要做哪些修改?

答案1

删除这个\paragraph{}\vspace*{-\parskip}。这是错误的,\paragraph这是一个类似于 \section 的标题命令。要开始新段落,请添加空行。

还删除\newline段落末尾的命令。

但除此之外:wrapfig 还存在一些问题。例如,如果两个 wrapfig 应该放在一个段落中,它就不喜欢这样做。这是前两个 wrapfig 的问题。

如果由于冲突而无法自由移动到下一页,那么在分页符处也会出现问题。因此,如果删除两个包装图,您的示例可以正常工作,但如果您做得过多,则不行:

\documentclass[a4paper]{book}

\usepackage{fontspec}

\usepackage{polyglossia}
\setmainlanguage{czech}

\usepackage{ulem}
\usepackage{spverbatim}
\usepackage[unicode]{hyperref}
\usepackage[]{graphicx}
\usepackage{grffile}

\usepackage{wrapfig}
\usepackage{hologo}

\usepackage{pdfpages}


\begin{document}

\chapter{Chapter}
\section{Section}
\subsection{Subsection}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{wrapfigure}{R}{0pt}
  \centering
  \includegraphics[height=4cm,width=2.5cm]{example-image}
\end{wrapfigure}
Begin of text. This is short text. This is short text. This is short text. This is short text. This is short text. This is short text. This is short text.

%%%%%%%%%%
%\begin{wrapfigure}{R}{0pt}
%  \centering
%  \includegraphics[height=4cm,width=4.5cm]{example-image}
%\end{wrapfigure}
Begin of text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text.

%%%%%%%%%%
\begin{wrapfigure}{R}{0pt}
  \centering
  \includegraphics[height=4cm,width=2.5cm]{example-image}
  \caption{This is caption for testing purposes.}
\end{wrapfigure}
Begin of text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text.

%%%%%%%%%%
%\begin{wrapfigure}{R}{0pt}
%  \centering
%  \includegraphics[height=4cm,width=4.5cm]{example-image}
%  \caption{This is caption for testing purposes.}
%\end{wrapfigure}

Begin of text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text. This is long text.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Section 2}
\subsection{Subsection 2}
Section 2 contents...

\end{document} 

相关内容