xwatermark 导致 \includegraphics 选项出现问题

xwatermark 导致 \includegraphics 选项出现问题

xwatermark我目前在使用和clip以及trim={}选项时遇到了问题,因为\includegraphics这些图形与 生成的水印完全无关xwatermark。以下 MWE 说明了这个问题:

\documentclass[letterpaper,10pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{newtxtext}
\usepackage{newtxmath}
\usepackage[usenames,dvipsnames,svgnames,table,hyperref]{xcolor}
\usepackage{graphicx}
\usepackage[extendedchars,encoding,filenameencoding=utf-8]{grffile}
\usepackage{float}
\usepackage[letterpaper,left=0.5in,right=0.5in,top=0.75in,bottom=0.75in]{geometry}
\usepackage{fancyhdr}
\usepackage{varioref}
\usepackage[unicode,bookmarks,raiselinks,pageanchor,hyperindex,colorlinks]{hyperref}
\usepackage{cleveref}
\usepackage[all]{hypcap}

% The problem package
\usepackage[printwatermark]{xwatermark}

\begin{document}

    CTAN lion draw­ing by Duane Bibby.

    % This works with \usepackage[printwatermark]{xwatermark}
    \begin{figure}[H]
        \centering
        \includegraphics[width=10cm,height=10cm,keepaspectratio]{ctan-lion.png}
    \end{figure}

    % This doesn't work with \usepackage[printwatermark]{xwatermark}
    \begin{figure}[H]
        \centering
        \includegraphics[width=10cm,height=10cm,keepaspectratio,clip,trim={2cm 2cm 2cm 2cm}]{ctan-lion.png}
    \end{figure}

\end{document}

当注释掉\usepackage[printwatermark]{xwatermark}以下正确的PDF时,生成:正确的 PDF

如果使用 active 编译文档,\usepackage[printwatermark]{xwatermark}则会报告以下 LaTeX 错误:

! Paragraph ended before \Gread@parse@vp was complete.<to be read again>\par
! LaTeX Error: \begin{figure} on input line 32 ended by \end{document}.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help.... \end{document}
! You can't use `\end' in internal vertical mode.\enddocument ...cumenthook \deadcycles \z@ \@@end \end{document}
! LaTeX Error: \begin{figure} on input line 32 ended by \end{document}.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help.... \end{document}
! Emergency stop.<> xwatermark-issue.tex (job aborted, no legal \end found)Here is how much of TeX's memory you used:18296 strings out of 492639284815 string characters out of 6133102404018 words of memory out of 1200000021996 multiletter control sequences out of 15000+6000007211 words of font info for 16 fonts, out of 8000000 for 90001141 hyphenation exceptions out of 819153i,6n,58p,860b,638s stack positions out of 5000i,500n,10000p,200000b,80000s! ==> Fatal error occurred, no output PDF file produced!

我已经将问题追溯到MWE 中的第二个clip和选项。如果trim={}\includegraphics两个都省略了选项,使用时文档可以正常编译\usepackage[printwatermark]{xwatermark}。有谁知道为什么xwatermark会干扰选项\includegraphics或如何修复它?

先感谢您。

答案1

更改选项的顺序\includegraphicsclip trim(无括号)。

\includegraphics[width=10cm,height=10cm,keepaspectratio,trim=2cm 2cm 2cm 2cm,clip]{example-image-a}

相关内容