按水平规则逐页动态填充可写文本高度

按水平规则逐页动态填充可写文本高度

以下,如何根据每页剩余的可写文本高度计算水平规则的数量(即19和)?11

\documentclass{exam}
\usepackage[
a4paper, left = 10 mm, right = 10 mm, includehead, 
top = 10 mm, headheight = 60 mm, headsep = 0pt,
includefoot, foot = 0 mm, bottom = 25 mm 
]{geometry}
\usepackage{mdframed,xparse,blindtext,pgfplots}


\NewDocumentCommand{\AnswerRules}{ O{10mm} O{0.2pt} m O{nobreak} }{%
    \begin{mdframed}[linewidth = 0pt, nobreak = false]

        \setlength{\parskip}{0pt}
        \setlength{\baselineskip}{#1}
        \foreach \i in {1,...,#3} {\noindent\rule{\linewidth}{#2}\par}

    \end{mdframed}
}

\begin{document}
    \setlength{\parindent}{0cm}
    \begin{questions}

        \question short question\vspace{\baselineskip}
        \AnswerRules{19}

        \newpage
        \question \blindtext[3] \vspace{\baselineskip}
        \AnswerRules{11}

    \end{questions}
\end{document}

在此处输入图片描述

答案1

您可以使用\leaders框的副本来填充空间。

\documentclass{exam}
\usepackage[
  a4paper,
  left = 10mm,
  right = 10mm,
  includehead, 
  top = 10mm,
  headheight = 60mm,
  headsep = 0pt,
  includefoot,
  foot = 0mm,
  bottom = 25mm 
]{geometry}

\usepackage{blindtext}

\newcommand{\answerspace}{%
  \par\leaders\hbox to \textwidth{\vrule width 0pt height 1cm\hrulefill}\vfill
  \clearpage
}

\begin{document}

\begin{questions}

\question short question\answerspace

\question \blindtext[3]\answerspace

\end{questions}

\end{document}

在此处输入图片描述

如果要指定厚度和颜色,请更改为

\newcommand{\answerspace}[2]{% #1 = thickness, #2 = color
  \par\leaders\hbox to \textwidth{\color{#2}\vrule width 0pt height 1cm\leaders\hrule height #1\hfill}\vfill
  \clearpage
}

并使用例如

\answerspace{0.5pt}{red}

更简单的指定方法独立地参数是使用键值语法:这里我使用d线条之间的距离、t厚度和c颜色。

\documentclass{exam}
\usepackage[
  a4paper,
  left = 10mm,
  right = 10mm,
  includehead, 
  top = 10mm,
  headheight = 60mm,
  headsep = 0pt,
  includefoot,
  foot = 0mm,
  bottom = 25mm 
]{geometry}
\usepackage{xparse,xcolor}

\usepackage{blindtext}

\newcommand{\answerspace}{%
  \par\leaders\hbox to \textwidth{\vrule width 0pt height 1cm\hrulefill}\vfill
  \clearpage
}

\ExplSyntaxOn
\keys_define:nn { diaa / answers }
 {
  d .dim_set:N = \l__diaa_answers_distance_dim,
  t .dim_set:N = \l__diaa_answers_thickness_dim,
  c .tl_set:N  = \l__diaa_answers_color_tl,
  d .initial:n = 10mm,
  t .initial:n = 0.2pt,
  c .initial:n = .,
 }

\NewDocumentCommand{\FillAnswerRules}{O{}}
 {
  \group_begin:
  \par
  \keys_set:nn { diaa / answers } { #1 }
  \leaders \hbox:n
   {
    \makebox[\textwidth][s]{
      \color{\l__diaa_answers_color_tl}
      \vrule width 0pt height \l__diaa_answers_distance_dim % the distance
      \leaders\hrule height \l__diaa_answers_thickness_dim\hfill
    }
   }\vfill
  \clearpage
  \group_end:
 }

\ExplSyntaxOff

\begin{document}

\begin{questions}

\question short question\FillAnswerRules[d=2cm]

\question \blindtext[3]\FillAnswerRules[t=1pt,c=red]

\end{questions}

\end{document}

在此处输入图片描述

相关内容