9

Min reprex:

\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}

The clip is essential to reproduce.

Potential clue:

I am trying to display a two-page picture. I am using the function from this answer.

When I use pdflatex the picture displays as I intend it to, immediately under the caption.

enter image description here enter image description here

When I use XeLaTeX, however, it displays half-way down the page (for gull.jpg or is completely absent for example-image).

enter image description here enter image description here

\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
    looks odd, it would be good if you could simplify this to an example using example-image (a test file already in tex distributions) and without all the after page and float tests – David Carlisle Jun 17 '16 at 14:29
  • I've taken your comment on board. Interestingly, example-image doesn't appear on the page when compiled using xelatex. (In the gull and my particular example the image occurs about half-way down the page.) – Hugh Jun 17 '16 at 14:49
  • 1
    Do you have two different versions of your image (for example, gull.jpg and gull.eps)? If so, it may be that XeLaTeX is picking up a different file, which might have a different bounding box. – Nicola Talbot Jun 19 '16 at 17:11
  • 1
    Hi, which version of XeLaTeX and adjustbox are you using? – Martin Scharrer Jun 21 '16 at 18:41
  • Latest xetex and adjustbox 2012/05/21 v1.0 Adjusting TeX boxes (trim, clip, ...) – Hugh Jun 22 '16 at 3:04
4

It is the same bug reported here: \clipbox of a \scalebox not working properly in xelatex.

Joseph provided a fix:

\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

Applying Joseph's fix to your code:

\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:

enter image description here

pdflatex

enter image description here

The problem resides in trimclip, which has some outdated code.

|improve this answer|||||

Not the answer you're looking for? Browse other questions tagged or ask your own question.