在 ConTeXt 中创建一个填充页面上可用文本区域的网格?

在 ConTeXt 中创建一个填充页面上可用文本区域的网格?

我有一些页面仅包含顶部的一个小段落和一个很大的空白区域,读者可以在其中添加注释或绘图,例如:

 _______________
|               |
| This is some  |
| text in a pa- |
| ragraph.      |
|               |
|               |
|               |
|               |
|               |
|               |
|               |
|_______________|

添加分页符,以便下一个段落出现在下一页。我想用由浅线组成的网格填充空白文本区域,例如:

 _______________
|               |
| This is some  |
| text in a pa- |
| ragraph.      |
|  ___________  |
| |_|_|_|_|_|_| |
| |_|_|_|_|_|_| |
| |_|_|_|_|_|_| |
| |_|_|_|_|_|_| | 
| |_|_|_|_|_|_| |
| |_|_|_|_|_|_| |
| |_|_|_|_|_|_| |
|_______________|

如何创建这样一个网格,使其填充文本区域的宽度和页面上可用的剩余高度?

答案1

正如所述如何定义图形大小以使其占据页面的剩余部分?,首先定义一个measure来测量页面上的剩余空间

\definemeasure[page][\dimexpr\pagegoal-\pagetotal-\lineheight\relax]

然后使用高度等于该尺寸的框架

\framed[height=\measure{page}, width=\textwidth]{}

现在,要添加网格,您可以使用以下方式创建 Metapost 背景

\startuseMPgraphic{page:grid}
   ....
\stopuseMPgraphic

并将其用作框架的背景

\defineoverlay[page:grid][\useMPgraphic{page:grid}]     
\framed[background=page:grid]{}

综合以上所有,我们得到

\definemeasure[topoffset][\bigskipamount] % We add this space before the answer
\definemeasure[page][\dimexpr\pagegoal-\pagetotal-\measure{topoffset}-5pt\relax]
% The 5pt is to avoid roundoff effects that can force the frame to the next
% page

% Add an option for grid size
\setupframed
    [gridsize=10pt]

\startuseMPgraphic{page:grid}
  begingroup;
  newnumeric grid_size; 
  grid_size = \frameddimension{gridsize};

  newnumeric x_count, y_count;

  x_count := floor(OverlayWidth/grid_size);
  y_count := floor(OverlayHeight/grid_size);

  % The requested width and height may not a multiple of grid_size
  % So, we center the grid horizontally and top align it vertically

  newnumeric y_offset; y_offset := OverlayHeight - y_count*grid_size;
  newnumeric x_offset; x_offset := (OverlayWidth  - x_count*grid_size)/2 ;


  newpath x_axis, y_axis;

  x_axis := (x_offset, 0) -- (x_offset + x_count * grid_size, 0);
  y_axis := (0, y_offset) -- (0, OverlayHeight);


  pickup pensquare scaled OverlayLineWidth;

  for i = 0 upto x_count :
      draw y_axis shifted (x_offset + grid_size*i,0) ;
  endfor ; 

  for i = 0 upto y_count :
      draw x_axis shifted (0,y_offset + grid_size*i) ;
  endfor ; 

  setbounds currentpicture to OverlayBox;

  endgroup;
\stopuseMPgraphic

\defineoverlay[page:grid][\useMPgraphic{page:grid}]


% Define a new framed for answers
\defineframed
    [answerframed]
    [width=\textwidth, height=\measure{page}, 
     frame=off,        background={page:grid}]

\define\answer
    {\blank[\the\dimexpr\measure{topoffset}]%
     \answerframed{}}

\setupwhitespace[big] 
\showframe % to visualize the result
\starttext

\input knuth

\answer

\stoptext

这使

在此处输入图片描述

您可以使用参数调整网格的大小gridsize。如果您愿意,您也可以定义一个gridcolor参数,然后使用 绘制规则\MPcolor{\framedparameter{gridcolor}}

相关内容