为什么图片在 XeLaTeX 中出现在不同的位置?

为什么图片在 XeLaTeX 中出现在不同的位置?

最小代表:

\documentclass{article}
\usepackage{graphicx}
\usepackage{adjustbox}
\usepackage{showframe} % just to illustrate

\begin{document}
\adjustbox{trim={.5\width} 0 0 0,clip}{\includegraphics{example-image}}%

\end{document}

对于复制来说,这clip是至关重要的。

潜在线索:

我正在尝试显示一张两页的图片。我正在使用来自这个答案的功能

当我使用pdflatex图片时,它就按照我预期的那样显示在标题下方。

在此处输入图片描述 在此处输入图片描述

但是,当我使用 时XeLaTeX,它会显示在页面的中间位置(对于gull.jpg或 , 完全不存在example-image)。

在此处输入图片描述 在此处输入图片描述

\documentclass[twoside,b5paper]{scrbook}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage[strict]{changepage}
\usepackage{afterpage,adjustbox}
\usepackage{caption}

\makeatletter
\newcommand{\twopagepicture}[4]{%
    {\afterpage{%
    \begin{figure}[#1]
            \caption{#4}%
        \makebox[\textwidth][l]{%
            \let\mywidth\linewidth
        \adjustbox{trim=0 0 {.5\width} 0,clip}{\includegraphics[width=2\mywidth]{#3}}}%
            \caption*{.}%
    \end{figure}%
    \begin{figure}[#1]
            \caption*{\phantom{#4}}%
        \makebox[\textwidth][l]{%
            \let\mywidth\linewidth
        \adjustbox{trim={.5\width} 0 0 0,clip}{\includegraphics[width=2\mywidth]{#3}}}%
    \end{figure}%
    }}%
}
\makeatother

\begin{document}
.
\twopagepicture{t}{l}{example-image}{Top caption}

\clearpage\clearpage
\includegraphics{example-image}

\end{document}

\listfiles

 *File List*
 article.cls    2014/09/29 v1.4h Standard LaTeX document class
  size10.clo    2014/09/29 v1.4h Standard LaTeX file (size option)
graphicx.sty    2014/10/28 v1.0g Enhanced LaTeX Graphics (DPC,SPQR)
  keyval.sty    2014/10/28 v1.15 key=value parser (DPC)
graphics.sty    2016/05/09 v1.0r Standard LaTeX Graphics (DPC,SPQR)
    trig.sty    2016/01/03 v1.10 sin cos tan (DPC)
graphics.cfg    2016/01/02 v1.10 sample graphics configuration
   xetex.def    2016/04/06 v4.08 LaTeX color/graphics driver for XeTeX (TeX Liv
e/RRM/JK)
infwarerr.sty    2016/05/16 v1.4 Providing info/warning/error messages (HO)
 ltxcmds.sty    2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
adjustbox.sty    2012/05/21 v1.0 Adjusting TeX boxes (trim, clip, ...)
 xkeyval.sty    2014/12/03 v2.7a package option processing (HA)
 xkeyval.tex    2014/12/03 v2.7a key=value parser (HA)
 adjcalc.sty    2012/05/16 v1.1 Provides advanced setlength with multiple back-
ends (calc, etex, pgfmath)
trimclip.sty    2012/05/16 v1.0 Trim and clip general TeX material
collectbox.sty    2012/05/17 v0.4b Collect macro arguments as boxes
tc-xetex.def    2012/05/13 v1.0 Clipping driver for xetex
ifoddpage.sty    2016/04/23 v1.1 Conditionals for odd/even page detection
varwidth.sty    2009/03/30 ver 0.92;  Variable-width minipages
showframe.sty    2011/02/24 v0.1i showframe (new impl., RN)
 eso-pic.sty    2015/07/21 v2.0g eso-pic (RN)
atbegshi.sty    2016/05/16 v1.17 At begin shipout hook (HO)
   ifpdf.sty    2016/05/14 v3.1 Provides the ifpdf switch
  xcolor.sty    2016/05/11 v2.12 LaTeX color extensions (UK)
   color.cfg    2016/01/02 v1.6 sample color configuration
example-image.pdf    Graphic file (type QTm)

答案1

这是这里报告的同一个错误:\scalebox 的 \clipbox 在 xelatex 中无法正常工作

Joseph 提供了一个解决方案:

\makeatletter
\ifdefined\XeTeXversion
  \def\@cliptoboxdim#1{%
    \setbox #1=\hbox{%
      \Gin@defaultbp\WIDTH{\wd #1}%
      \Gin@defaultbp \DEPTH {\dp #1}%
      \@tempdima \ht #1%
      \advance\@tempdima\dp#1%
      \Gin@defaultbp \TOTALHEIGHT {\@tempdima }%
      \special{pdf:literal q}% 
      \special{pdf:literal 0 -\DEPTH \space \WIDTH \space \TOTALHEIGHT \space re W n }%
      \rlap{\copy #1}%
      \special {pdf:literal Q}%
      \hskip\wd#1%
    }%
  }
\fi
\makeatother

将 Joseph 的修复应用到您的代码中:

\documentclass[twoside,b5paper]{scrbook}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage[strict]{changepage}
\usepackage{afterpage,adjustbox}
\usepackage{caption}

\makeatletter
\newcommand{\twopagepicture}[4]{%
    {\afterpage{%
    \begin{figure}[#1]
            \caption{#4}%
        \makebox[\textwidth][l]{%
            \let\mywidth\linewidth
        \adjustbox{trim=0 0 {.5\width} 0,clip}{\includegraphics[width=2\mywidth]{#3}}}%
            \caption*{.}%
    \end{figure}%
    \begin{figure}[#1]
            \caption*{\phantom{#4}}%
        \makebox[\textwidth][l]{%
            \let\mywidth\linewidth
        \adjustbox{trim={.5\width} 0 0 0,clip}{\includegraphics[width=2\mywidth]{#3}}}%
    \end{figure}%
    }}%
}
\makeatother

\begin{document}
\makeatletter
\ifdefined\XeTeXversion
  \def\@cliptoboxdim#1{%
    \setbox #1=\hbox{%
      \Gin@defaultbp\WIDTH{\wd #1}%
      \Gin@defaultbp \DEPTH {\dp #1}%
      \@tempdima \ht #1%
      \advance\@tempdima\dp#1%
      \Gin@defaultbp \TOTALHEIGHT {\@tempdima }%
      \special{pdf:literal q}% 
      \special{pdf:literal 0 -\DEPTH \space \WIDTH \space \TOTALHEIGHT \space re W n }%
      \rlap{\copy #1}%
      \special {pdf:literal Q}%
      \hskip\wd#1%
    }%
  }
\fi
\makeatother
.
\twopagepicture{t}{l}{example-image}{Top caption}

\clearpage\clearpage
\includegraphics{example-image}

\end{document}

XeLaTeX:

在此处输入图片描述

PDFLaTeX

在此处输入图片描述

问题在于trimclip,其中有一些过时的代码。

相关内容