I have to print tickets for a theater. The seating plan of the theater is as follows:

Blocks (A right, A left, B right, B left, etc., through H)

Rows (Block A could have rows from 1 to 15, Block B from 1 to 20, and so on: they are not all the same in number)

Seat (Block A right row 1 could have seats from 1 to 4, Block A right row 2 from 1 to 22, and so on: again, not all the same in number)

I'm aware of the existence of for-loops in Latex, and I have successfully used them before, but I have the problem of how to tell the loop that it has to stop at row 15 if the Block is A, but it has to go to 20 if the Block is B, etc. Same for the seats (whereas if I solve the problem for the rows, I can solve it for the seats).

I though about putting the information about the number of rows per Block and the number of seats per row in a table, but then I don't know how to get the for loop to read the table. Or maybe the for is not right in this case? Maybe a while ... do would be more appropriate? But then I don't know how to implement that in Latex.

  • Which for-loop-construction do you use currently (please show some code)?
    – TeXnician
    Jul 3, 2017 at 12:14
  • @TeXnician. I didn't even know how to start writing some code for this example, but I normally like the \foreach of package pgffor.
    – Andyc
    Jul 3, 2017 at 13:12

3 Answers 3


Using the pgffor package

One possibility:



\foreach \block/\rows in {
    A right/{4,22,31},
    A left/{4,5},
    B right/{10,4,3,4,5},
    } {
    \foreach \seats [count=\row] in \rows {
        \foreach \seat in {1, ..., \seats} {
            Block: \block\  Row: \row, Seat:\seat

Each block is defined using a block name and a list of the row sizes.

  • Nice and compact solution. I ended up using this one, modifying for "symmetrical" theater (one more for-loop for printing "right" and "left").
    – Andyc
    Jul 3, 2017 at 13:21

Since the OP gave no indication that a row's seat number may begin with something other than 1, I assumed that, but could change accordingly. Syntax:

\printtickets{<section name> : <row 1 seats>, <row 2 seats>,.../ ...}

The MWE:

    \foreach\y in {1,...,{\listlen\seatcount[\xcnt,2]}}{%
      \foreach\z in {1,...,{\seatcount[\xcnt,2,\y]}}{%
          \Longstack{Block~\seatcount[\xcnt,1] Row~\y{} Seat~\z}}}}\kern3pt\allowbreak%
  A right : 3,5,7     / 
  A left  : 3,5,6     /
  B right : 4,5,6,9,11/
  B left  : 4,5,6,9,11

enter image description here

  • 1
    Your assumption is correct. All the rows start with seat number 1.
    – Andyc
    Jul 3, 2017 at 13:07

something like this

enter image description here



\count@#4 %
Block: #1, Row: \number#2, Seat: \the\count@\par
\ifnum\count@<#5 %
\advance\count@ 1 %
\ifnum#2=#3 %


%     block    row   low high      
\seats{A Left} {2-6} {1}  {10}
\seats{A Left} {1}   {2}  {8}
\seats{B Right}{1-8} {1}  {12}
\seats{B Right} {9}  {10}  {12}
\seats{B Right} {10} {10}  {12}

  • Nice solution for the case where the rows do not start with seat number 1. Also nice for not using extra packages.
    – Andyc
    Jul 3, 2017 at 13:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .