Following-up this answer, how can I edit the command \FillAnswerRules to enclose the leaders by a border/frame by using tocolorbox or mdframed so that I can get the same output of \CountAnswerRules?
\documentclass{exam}
\usepackage{xparse,xcolor,tcolorbox,mdframed,pgffor,blindtext}
\renewcommand{\questionshook}{%
\setlength{\leftmargin}{0pt}%
\setlength{\labelwidth}{-\labelsep}%
\setlength{\topsep}{0\baselineskip}
}
\ExplSyntaxOn
\keys_define:nn { diaa / answers }
{
num-lines .int_set:N = \l_diaa_answers_numlines_int ,
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,
num-lines .initial:n = 3,
d .initial:n = 10mm,
t .initial:n = 0.2pt,
c .initial:n = gray,
}
\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:
}
\NewDocumentCommand{\CountAnswerRules}{O{}}
{
\keys_set:nn { diaa / answers } { #1 }
\begin{mdframed}[
innerrightmargin = 10pt, innertopmargin = 20pt,
innerleftmargin = 10pt, innerbottommargin = 20pt,
leftmargin = 0pt,
rightmargin = 0pt,
linecolor=black, linewidth = 2pt]
\setlength{\parskip}{0pt}
\setlength{\baselineskip}{\l__diaa_answers_distance_dim}
\foreach \i in {1,...,\l_diaa_answers_numlines_int} {\color{\l__diaa_answers_color_tl}%
\noindent\rule{\linewidth}{\l__diaa_answers_thickness_dim}\par
}
\end{mdframed}
}
\ExplSyntaxOff
\begin{document}
\begin{questions}
\question short question \CountAnswerRules[d = 20pt]
\question \blindtext[1]\FillAnswerRules[t = 1pt]
\end{questions}
\end{document}




\l__diaa_answers_distance_dim-\l__diaa_answers_thickness_dimabove it and no space below it. With my change, vertical blank space is more equally spread around each rule. – frougon Feb 21 '20 at 09:21bottom = 0.25 <spacing> , top = 0ptwithdepth = 0ptyields better eye-comforting layout for me. – Diaa Feb 21 '20 at 11:35