Skip to main content

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Asked
Modified 10 months ago
Viewed 123 times
4

i try to make some kind of table, where i create a number of rows automatically.

\documentclass{scrartcl} 
\usepackage{polyglossia} 
\setdefaultlanguage{german} 
\usepackage{fontspec} 
\usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}
\usepackage{tabularray} 
\usepackage{tabularx} 
\usepackage{scrlayer-scrpage} % Paket für Kopf- und Fußzeilen 
\usepackage{pgffor} % Paket für Schleifen



%\ohead{\includegraphics[scale=0.05]{c:/Schule/logo_rot_3.jpg}}
\ifoot{08.02.2024}

%\renewcommand{\arraystretch}{2.1}
\newcommand{\createTable}[1]{
    \begin{tblr}{
            colspec = {|Q[5,l]|Q[3,c]|Q[2,c]|Q[2,c]|}, % Gleichmäßige Verteilung der Spalten
            row{1} = {font=\bfseries, c}, % Formatierung der ersten Zeile
            hlines, % Horizontale Linien
            vlines, % Vertikale Linien
            width=\textwidth % Breite der Tabelle auf Textbreite setzen
        }
        Kurs / Klasse & Raum & Anzahl & Vollständig? (abhaken) \\
        Beispiel: Physik Q3 & Starck & P1 & 17 & \checkmark \\
        \foreach \i in {1,...,#1} { & & & \\ }
    \end{tblr}
    }
    
    \begin{document}
        \section{Schulhof Altbau}
        \begin{tabularx}{0.9\textwidth}{l X}
            Räume & 005, 007, 008, 106, 107, 108, 109, 111, 113, 206, 207, 208, 209, 211, 214, 304, 305, 306, 307, 311\\
        \end{tabularx}\\
        \createTable{5}     

\end{document}

Leads to "undefined control sequence". The documentation says something like that, i do not have enough experience to integrate it. Can you help me?

\IgnoreSpacesOn
 \prgNewFunction \makeEmptyTable {mm}  {
  \tlSet \lTmpaTl {\intReplicate {\intEval{#2-1}} {&}}
  \tlPutRight \lTmpaTl {\\}
  \intReplicate {#1} {\tlUse \lTmpaTl}
 }
 \IgnoreSpacesOff
 \begin{tblr}[evaluate=\makeEmptyTable]{hlines,vlines}
  \makeEmptyTable{3}{7}
 \end{tblr}

1 Answer 1

4

You can build the repeated rows beforehand and then expand the created command.

\documentclass{scrartcl} 
\usepackage{polyglossia} 
\setdefaultlanguage{german} 
\usepackage{fontspec} 
\usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}
\usepackage{tabularray} 
\usepackage{scrlayer-scrpage} % Paket für Kopf- und Fußzeilen 

\usepackage{amssymb}


%\ohead{\includegraphics[scale=0.05]{c:/Schule/logo_rot_3.jpg}}
\ifoot{08.02.2024}

\newcommand{\createTable}[1]{%
  \repeatrow{#1}{ & & & \\ }%
  \begin{tblr}[
    expand=\repeatedrow
  ]{
    colspec = {|Q[5,l]|Q[3,c]|Q[2,c]|Q[2,c]|}, % Gleichmäßige Verteilung der Spalten
    row{1} = {font=\bfseries, c}, % Formatierung der ersten Zeile
    hlines, % Horizontale Linien
    vlines, % Vertikale Linien
    width=\textwidth % Breite der Tabelle auf Textbreite setzen
  }
  Kurs / Klasse & Raum & Anzahl & Vollständig? (abhaken) \\
  Beispiel: Physik Q3 & Starck & P1 & 17 & \checkmark \\
  \repeatedrow
  \end{tblr}%
}

\ExplSyntaxOn
\NewDocumentCommand{\repeatrow}{mm}
 {
  \tl_set:Ne \repeatedrow { \prg_replicate:nn {#1} {#2} }
 }
\ExplSyntaxOff

\begin{document}

\section{Schulhof Altbau}

\createTable{5}     

\end{document}

output

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.