% !TeX spellcheck = es_Cl
\documentclass[spanish,letterpaper,11pt]{article}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%DATOS A MODIFICAR
\newcommand{\curso}{Curso}
\newcommand{\carrera}{Carrera}
\newcommand{\fecha}{Fecha}
\newcommand{\taller}{Prueba Parcial Nº X}
\newcommand{\estudiantes}{20} % Número de estudiantes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\usepackage{amsmath,amssymb}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage[spanish,activeacute]{babel}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage[margin=10mm,includehead,headheight=34mm,headsep=6mm]{geometry}
\usepackage{array}
\usepackage{nicematrix}
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\newcommand{\cabecera}{%
  \noindent
  \begin{minipage}[c]{0.22\textwidth}
    \includegraphics[width=\linewidth]{logoINSTMAT.jpg}
  \end{minipage}
  \hfill
  \begin{minipage}[c]{0.68\textwidth}
    \centering
    {\LARGE \textbf{\textit{Asistencia \taller}}}
  \end{minipage}

  \vspace{4mm}

  \noindent
  M\'odulo: \textbf{\curso} \quad Carrera: \textbf{\carrera} \hfill Fecha: \textbf{\fecha}
}

\fancyhead[C]{\parbox[t]{\textwidth}{\cabecera}}
\fancypagestyle{plain}{%
  \fancyhf{}
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}
  \fancyhead[C]{\parbox[t]{\textwidth}{\cabecera}}
}

% Adjust row height in tables
\newcommand{\filasporpagina}{22}
\renewcommand{\arraystretch}{1.0}
\setlength{\arrayrulewidth}{0.8pt}

\newlength{\anchoColumnaNumero}
\newlength{\anchoColumnaNombre}
\setlength{\anchoColumnaNumero}{7mm}
\setlength{\anchoColumnaNombre}{\dimexpr(\textwidth-\anchoColumnaNumero-32mm-10\tabcolsep-6\arrayrulewidth-17pt)/3\relax}

\newcommand{\alturaFila}{\rule[-0.3mm]{0pt}{7.2mm}}
\NiceMatrixOptions{cell-space-top-limit=1pt,cell-space-bottom-limit=1pt}

\ExplSyntaxOn

\cs_new_protected:Npn \asistencia_tabla:nn #1 #2 {
  \noindent\begin{NiceTabular}{|>{\centering\arraybackslash}p{\anchoColumnaNumero}|p{\anchoColumnaNombre}|p{\anchoColumnaNombre}|p{\anchoColumnaNombre}|>{\centering\arraybackslash}p{32mm}|}[hvlines]
    \textbf{N\textdegree} & \centering\textbf{Apellido\ paterno} & \centering\textbf{Apellido\ materno} & \centering\textbf{Nombres} & \textbf{Firma} \\
    \int_step_inline:nn {#1} {
      \alturaFila\int_eval:n {#2 + ##1} & \alturaFila & \alturaFila & \alturaFila & \alturaFila
      \int_compare:nNnT {##1} < {#1} { \\
      }
    }
  \end{NiceTabular}
}

\newcommand{\imprimirasistencia}{%
  \int_compare:nNnT {\estudiantes} > {0} {
    \int_step_inline:nn { \int_eval:n { \int_div_truncate:nn { \estudiantes + \filasporpagina - 1 } { \filasporpagina } } } {
      \asistencia_tabla:nn
        { \int_eval:n { \int_min:nn { \filasporpagina } { \estudiantes - (##1 - 1) * \filasporpagina } } }
        { \int_eval:n { (##1 - 1) * \filasporpagina } }
      \int_compare:nNnT {##1} < { \int_eval:n { \int_div_truncate:nn { \estudiantes + \filasporpagina - 1 } { \filasporpagina } } } {
        \newpage
      }
    }
  }
}

\ExplSyntaxOff

\begin{document}
\thispagestyle{fancy}

%--- Asistencia ---
\imprimirasistencia

\end{document}
