在冲突环境中使用 Wrapfig

在冲突环境中使用 Wrapfig

我一直在搜索和尝试一段时间,寻找警告的原因以及将图形意外地放置在文本底部(而图形应该位于文本旁边)的原因。我想提供错误的 MWE。问题是当代码很短时没有问题。我得到了我所期望的。但是我正在写一本书,其中twoside在包中设置了不均匀的内外边距选项geometry。内容已经太长了,无法真正查明原因。我制作了一个单独的章节来制作一些传记,并在文本的侧面添加了作者的照片,最好是在左上角(在文本的开头)。在本章中,没有列表或代码列表或任何可能与wrapfigure环境冲突的内容。但我仍然收到警告和错误的图形位置。我正在为项目使用 Overleaf。而该章节只是一个单独的文件,通过命令包含在主脚本中input。用编写小代码wrapfig就可以了。我可能会尝试使用minipage作为替代方案。但我认为这可能是最好的。任何澄清和解决方案都会有所帮助。

来自 Overleaf

我的序言如下:

\documentclass[10pt, twoside]{book}

%\usepackage{showframe}

\usepackage[colorinlistoftodos]{todonotes}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\DeclareMathOperator{\Tr}{Tr}
\usepackage{mathtools, nccmath}

\usepackage{tikz}
\usepackage{tkz-euclide}
\usetikzlibrary{positioning}
\usepackage{graphicx}
\usepackage{float}
\usepackage{wrapfig, blindtext}
\usepackage{hyperref}
\usepackage{cleveref} % For making multiple references.
\usepackage[numbered, useliterate]{mcode} % For MATLAB codes.
%\usepackage{xcolor} % For colored environments or texts.
\usepackage{listings} % For code listings.
\usepackage{caption, subcaption} % For figures and subfigures.
\usepackage{color,soul}
\usepackage{tcolorbox}
\usepackage{multirow}
\usepackage{amsfonts}
\usepackage{amsthm,enumitem}
\usepackage{tabularx}
\usepackage{amssymb}
\graphicspath{ {./graphics/} }
\usepackage{marginnote}
\usepackage{pdfpages}
%\usepackage{import}
\usepackage{example}
%\usepackage{makeidx}
\usepackage{pgfplots}
\usepackage{ragged2e}
\usepackage[paperwidth=6in, paperheight=9in, top=0.5in, bottom=0.5in, outer=0.5in, inner=0.75in,includehead,includefoot]{geometry}
\usepackage[T1]{fontenc}
\usepackage{imakeidx}
\makeindex[columns=2, title=Alphabetical Index, options=-s]
\usetikzlibrary{trees}
\usepackage{tikz-qtree}
\usepackage{verbatim} % For commenting block of codes
\usepackage[export]{adjustbox}
\usepackage{emptypage} % For inserting empty pages at the end of chapters.
\usepackage{lineno}
\renewcommand{\listfigurename}{List of Figures}
\renewcommand{\listtablename}{List of Table}
\allowdisplaybreaks
% For reducing space between chapter title and top of page
\usepackage{titlesec}
\titleformat{\chapter}[display] 
{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter}{20pt}{\Huge} 
\titlespacing*{\chapter}{0pt}{-20pt}{40pt}
%

% For header and footer line on every page
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}
\fancyhead[LE]{\leftmark}
\fancyhead[RO]{\rightmark}
\renewcommand{\headrulewidth}{1pt}
\fancyfoot{}
\lfoot{cdass text(import)}
\rfoot{\thepage}
\renewcommand{\footrulewidth}{1.5pt}
\makeatletter
\def\chaptermark#1{%
          \markboth{\MakeUppercase{%
            \ifnum \c@secnumdepth >\m@ne \if@mainmatter
              \@chapapp\ \thechapter. \ \fi\fi#1}}{}}
\makeatother
%

\pgfplotsset{compat=1.17}

答案1

该示例(如评论中所述)可以简化为

\documentclass{article}

\usepackage{wrapfig}

\begin{document}

\center

\begin{wrapfigure}{r}{.5\textwidth}
  
\end{wrapfigure}
\end{document}

产生警告

Package wrapfig Warning: wrapfigure used inside a conflicting environment on in
put line 9.

这里的错误是\centerwhich 是 的内部形式\begin{center},不应用作命令。命令形式是\centeringwhich 不会发出警告。

实际情况是\justifyragged2e再次是内部环境形式,命令形式是\justifying。但是对于这种情况,修复更简单:您只需删除命令即可。该 ragged2e包添加了作为对、和\justifying的补充,但对齐是 TeX 中的默认设置,我从未见过此命令的任何有效用法。当使用它时,通常是为了尝试减轻早期的错误,其中未使用正确的范围,因此应用于太多的文档,但更好的方法是修复的使用,使其在一个组中并在正确的位置结束,而不是试图通过 在不规则部分内应用来撤消不规则性。\centering\raggedright\raggedleft\raggedright\raggedright\justifying

相关内容