ConTeXt:如何将内容跨越两页?

ConTeXt:如何将内容跨越两页?

我的文档中的大多数页面看起来都像这样,这是书籍中常见的布局:

 ___________________________
|             |             |
| Title       | ........... |
|             | ........... |
|  .......... | ........... |
| ........... | ........... |
| ........... | ........... |
| ........... | ........... |
| ........... | ........... |
| ........... | ........... |
|      1      |      2      |
|_____________|_____________|

我有一些特殊的页面,希望其中的内容能够跨越左页和右页。

  • 该论文基本上被视为一张宽的 A3 纸,只是页码保持不变。
  • 页边距与上面的相同,但是书的折叠处没有页边距。
  • 甚至章节和部分标题也应该跨越。

书中的大多数页面并不以这种方式跨越。

 ___________________________
|             |             |
| The Title Goes Across Too |
|             |             |
|  ........................ |
| ......................... |
| ......................... |
| ......................... |
| ......................... |
| ......................... |
|      1      |      2      |
|_____________|_____________|

我怎样才能以这种方式将某些页面的内容跨越两页?

答案1

如果您的两页跨页没有浮动,那么您可以简单地将内容存储在一个框中,然后将该框分成两部分。

% The default layout
\setuplayout[cutspace=1in, backspace=1in, width=middle]

% The layout for left and right page. ConTeXt treats cutspace=0pt as a signal
% to set cutspace=backspace. So, I use cutspace=1sp (the smallest non-zero 
% space in TeX.
\definelayout[leftpage] [cutspace=1sp, backspace=1in, width=middle]
\definelayout[rightpage][cutspace=1in, backspace=1sp, width=middle]

% A box to store the content
\newbox\twopagebox

% A frame to typeset the content. 
\defineframed
    [twopageframe]
    [
      width=\the\dimexpr2\paperwidth-2\backspace,
      height=\textheight,
      align=normal,
      frame=off,
    ]

% An environment to gather the data, typeset it in a box, and then split 
% the box.
%
% A buffer is not needed here, as we can directly typeset the material in 
% a box.
\unexpanded\def\starttwopagemakeup
    {\grabbufferdata[twopagebuffer][starttwopagemakeup][stoptwopagemakeup]}

\unexpanded\def\stoptwopagemakeup
    {\setbox\twopagebox\hbox{\twopageframe{\getbuffer[twopagebuffer]}}%
     \page[right]%
     \setuplayout[leftpage]%
     \clip[nx=2, ny=1, x=1]{\copy\twopagebox}%
     \page
     \setuplayout[rightpage]%
     \clip[nx=2, ny=1, x=2]{\copy\twopagebox}%
     \page
     \setuplayout[reset]}

\setupbackgrounds[page][frame=on, framecolor=red]
% To visualize the page border

\starttext
  \dorecurse{6}{\input knuth \endgraf}
\starttwopagemakeup
  \chapter {Two page data}
  \dorecurse{6}{\input knuth \endgraf}
\stoptwopagemakeup
  \dorecurse{6}{\input knuth \endgraf}

\stoptext

这使

在此处输入图片描述

笔记在将页面合并在一起以在此处显示图像时,我特意在页面之间留出了空间。

此解决方案仅适用于单页。如果您希望支持多页,则需要将内容存储为\vbox并保留,\vsplit直到没有剩余材料为止。例如,

% The default layout
\setuplayout[cutspace=1in, backspace=1in, width=middle]

% The layout for left and right page. ConTeXt treats cutspace=0pt as a signal
% to set cutspace=backspace. So, I use cutspace=1sp (the smallest non-zero 
% space in TeX.
\definelayout[leftpage] [cutspace=1sp, backspace=1in, width=middle]
\definelayout[rightpage][cutspace=1in, backspace=1sp, width=middle]

% A box to store the content
\newbox\twopagebox
\newbox\contentbox

\unprotect
% An environment to gather the data, typeset it in a box, and then split 
% the box.

\unexpanded\def\starttwopagemakeup
    {\setbox\contentbox\vbox\bgroup
        \hsize\the\dimexpr2\paperwidth-2\backspace\relax}

\unexpanded\def\stoptwopagemakeup
    {\egroup
     \typeset_all_pages}

\def\typeset_all_pages
    {\ifvoid\contentbox
       % Done
     \else\ifdim\ht\contentbox>\textheight
        \setbox\twopagebox\vsplit\contentbox to \textheight
           \typeset_one_page\twopagebox
           \typeset_all_pages
         \else
            \typeset_one_page\contentbox
         \fi
      \fi}

\def\typeset_one_page#1% box
   {\page[right]%
     \setuplayout[leftpage]%
     \clip[nx=2, ny=1, x=1]{\copy#1}%
     \page
     \setuplayout[rightpage]%
     \clip[nx=2, ny=1, x=2]{\copy#1}%
     \page
     \setuplayout[reset]}

\protect

\setupbackgrounds[page][frame=on, framecolor=red]
% To visualize the page border

\setuphead[chapter][page=] % Otherwise we get an extra page

\starttext
\starttwopagemakeup
  \chapter{One}
  \dorecurse{12}{\input knuth \relax}
\stoptwopagemakeup

\chapter{Normal Text}
\dorecurse{12}{\input ward \endgraf}


\stoptext

这使用低级 TeX(因为拆分页面实际上相当于编写输出例程)。有关详细信息,请参阅 TeX by Topic。

相关内容