如何将 \twopagepicture 移离外边距?

如何将 \twopagepicture 移离外边距?

我使用此处发布的 \twopagepicture 片段。

如何在两页上添加图片,左侧部分在左侧,右侧部分在右侧(用于书籍)?

我需要进行一些小调整,使图形不与文档边缘接触,而是偏离边缘。垂直移动图形很容易,但每次我尝试调整时

\let\mywidth\paperwidth 

\let\mywidth\paperwidth - <some offset>in

因此水平边缘向内延伸,中间图形的某些部分被剪掉。

这是未经我修改的 MWE。它往往对齐方式很奇怪,但对于我正在处理的主要文档来说没问题。

\documentclass[10pt,]{article}
\usepackage{graphicx}
\usepackage{adjustbox}
\usepackage{afterpage} 
\usepackage{caption} 

\setcounter{totalnumber}{1}
\setcounter{topnumber}{1}
\setcounter{bottomnumber}{1}
\renewcommand{\topfraction}{.99}
\renewcommand{\bottomfraction}{.99}
\renewcommand{\textfraction}{.01}

\makeatletter
\newcommand*{\twopagepicture}[4]{%
    \checkoddpage
    \ifoddpage
        \expandafter\@firstofone
    \else
        \expandafter\afterpage
    \fi
    {\afterpage{%
    \if #1t%
        \if #2p%
            \thispagestyle{empty}%
            \afterpage{\thispagestyle{empty}}%
        \fi
    \fi
    \begin{figure}[#1]
        \if #2p%
            \if #1t%
                % Note #1: Controls vertical positioning of even page.
                % Addition leads to moving the image downward..
                \vspace*{-\dimexpr1in+\voffset+\topmargin+\headheight+\headsep\relax}
            \fi
        \fi
        \if #1b%
            \caption{#4}%
        \fi
        \makebox[\textwidth][l]{%
        \if #2p\relax
            % Controls horizontal positioning of the even page
            \let\mywidth\paperwidth
            \hskip-\dimexpr1in+\hoffset+\evensidemargin\relax
        \else
            \let\mywidth\linewidth
        \fi
        \adjustbox{trim=0 0 {\mywidth} 0,clip}{\includegraphics[width=2\mywidth]{#3}}}%
        \if #1b\else
            \caption{#4}%
        \fi
        \if #2p%
            \if #1b%
                \vspace*{-\dimexpr\paperheight-\textheight-1in-\voffset-\topmargin-\headheight-\headsep\relax}%
            \fi
        \fi
    \end{figure}%
    \begin{figure}[#1]
        \if #2p%
            \if #1t%
                \vspace*{-\dimexpr1in+\voffset+\topmargin+\headheight+\headsep\relax} % Note #1.
            \fi
        \fi
        \makebox[\textwidth][l]{%
        \if #2p%
            \let\mywidth\paperwidth
            \hskip-\dimexpr1in+\hoffset+\oddsidemargin\relax
        \else
            \let\mywidth\linewidth
        \fi
        \adjustbox{trim={\mywidth} 0 0 0,clip}{\includegraphics[width=2\mywidth]{#3}}}%
        \if #2p%
            \if #1b%
                \vspace*{-\dimexpr\paperheight-\textheight-1in-\voffset-\topmargin-\headheight-\headsep\relax}%
            \fi
        \fi
    \end{figure}%
    }}%
}
\makeatother

\begin{document}



The diagonal in the picture should not be broken.

\twopagepicture{t}{p}{diagonal.png}{}

And the picture continues to the next page.

\end{document}

diagonal.png 是一张简单的图片。如果页面顶部和图片之间没有空格,或者线条断开,则无法按预期工作。

在有人认为我的问题是关于删除文件扩展名之前,这就是我想做的事情。 在此处输入图片描述

我采取的临时解决方案是制作一个宽度为两页长度的 PNG 文件,然后手动重新缩放图像 (JPG)。这几乎使图像的文件大小翻倍,因此理想情况下,我仍然希望在 LaTeX 中处理位置。

答案1

这个问题已经被@MartinScharrer 解决了 ---如何在两页上添加图片,左侧部分在左侧,右侧部分在右侧(用于书籍)?

请注意,您需要插入您选择的源图像,如下所示

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

平均能量损失

\documentclass[twoside]{book}

\usepackage{graphicx}
\usepackage{adjustbox}
\usepackage{afterpage}
\usepackage{placeins}
\usepackage{xcolor}

% For the `memoir` class remove the following two packages.
% This class already provide the functionality of both
\usepackage{caption}
\usepackage[strict]{changepage}
%%%

\setcounter{totalnumber}{1}
\setcounter{topnumber}{1}
\setcounter{bottomnumber}{1}
\renewcommand{\topfraction}{.99}
\renewcommand{\bottomfraction}{.99}
\renewcommand{\textfraction}{.01}

\makeatletter
\newcommand*{\twopagepicture}[4]{%
    \checkoddpage
    \ifoddpage
        \expandafter\@firstofone
    \else
        \expandafter\afterpage
    \fi
    {\afterpage{%
    \if #1t%
        \if #2p%
            \thispagestyle{empty}%
            \afterpage{\thispagestyle{empty}}%
        \fi
    \fi
    \begin{figure}[#1]
        \if #2p%
            \if #1t%
                \vspace*{-\dimexpr1in+\voffset+\topmargin+\headheight+\headsep\relax}%
            \fi
        \fi
        \if #1b%
            \caption{#4}%
        \fi
        \makebox[\textwidth][l]{%
        \if #2p\relax
            \let\mywidth\paperwidth
            \hskip-\dimexpr1in+\hoffset+\evensidemargin\relax
        \else
            \let\mywidth\linewidth
        \fi
        \adjustbox{trim=0 0 {.5\width} 0,clip}{\includegraphics[width=2\mywidth]{#3}}}%
        \if #1b\else
            \caption{#4}%
        \fi
        \if #2p%
            \if #1b%
                \vspace*{-\dimexpr\paperheight-\textheight-1in-\voffset-\topmargin-\headheight-\headsep\relax}%
            \fi
        \fi
    \end{figure}%
    \begin{figure}[#1]
        \if #2p%
            \if #1t%
                \vspace*{-\dimexpr1in+\voffset+\topmargin+\headheight+\headsep\relax}%
            \fi
        \fi
        \makebox[\textwidth][l]{%
        \if #2p%
            \let\mywidth\paperwidth
            \hskip-\dimexpr1in+\hoffset+\oddsidemargin\relax
        \else
            \let\mywidth\linewidth
        \fi
        \adjustbox{trim={.5\width} 0 0 0,clip}{\includegraphics[width=2\mywidth]{#3}}}%
        \if #2p%
            \if #1b%
                \vspace*{-\dimexpr\paperheight-\textheight-1in-\voffset-\topmargin-\headheight-\headsep\relax}%
            \fi
        \fi
    \end{figure}%
    }}%
}
\makeatother

\usepackage{lipsum}
\begin{document}
\lipsum
\lipsum
\twopagepicture{b}{l}{image}{Test}%<-----insert image source here{image}
\lipsum
\twopagepicture{t}{l}{image}{Test}
\lipsum
\twopagepicture{b}{p}{image}{Other test}
\lipsum
\twopagepicture{t}{p}{image}{Other test with 
very very very very very very very very very very very
very very very very very very very very very very very
very very very very very very very very very very very
long caption
}
\lipsum
\lipsum

\end{document}

相关内容