I would like to make a random classroom seating chart starting from a numbered list of students. I would also like to specify the number of seats per row (as it varies in my classroom) and the number of seats per table (2, else 1, in my case).

My specific classroom configuration of 22 seats looks like this (where S = a seat):

S   S S   S S   S S   S  ← 8 seats in row
 S S   S S   S S   S S   ← 8 seats in row
    S S   S S   S S      ← 6 seats in row
  front of classroom

How would I solve this problem with TikZ in general, where I would only have to pass it an array of the number of seats in each row from the front of the room ({6,8,8} in my specific case), a list of students {"Albert","Bob","Chris",…,"Zach"}, and the number of seats per table (2, else 1, in my specific case)?



Two version here, firstly a version that is not very friendly looking in some places but most of the parameters (number of tables and seats) are derived automatically from a list of children.

It also will not easily generalize to other table layouts, and some "fooling around" will probably be required if the sizes are changed.

\def\countitemsinmacro#1{\foreach \i [count=\itemcount, remember=\itemcount] in #1{}}
  every seat/.style={
    minimum width=1.5cm,
    minimum height=1cm,
\foreach \childrenrow [count=\rownumber] 
  in {%
    \foreach \children [count=\tablenumber] in \childrenrow {
      \foreach \child [count=\seatnumber] in \children{
        \node [every seat/.try, seat \rownumber-\tablenumber-\seatnumber/.try]
          at (-\tabletotal/2*4+\tablenumber*4+\seatnumber*1.5-\seatcount/2*1.5,-\rownumber*2) (seat-\rownumber-\tablenumber-\seatnumber) {\child};

enter image description here

Secondly, a bit more needs to be specified (i.e., the number of tables in each row and the number of seats at each table), but the list of children's names is automatically randomised.


\foreach\i@ in{1,...,#1}{%
  \foreach\j@ in{1,...,\childlistcount}{%

\def\getchildname#1{\csname childlist@#1\endcsname}

\foreach \tables/\tableseats [count=\rowcount, remember=\c] in
  \foreach \seats [count=\tablecount, remember=\c] in \tableseats
    \foreach \seat [evaluate={\c=int(\c+1);}, remember=\c] in {1,...,\seats}
    \node [draw, minimum width=1.5cm, minimum height=1cm, anchor=base] 
      at (\tablecount*4-\tables/2*4+\seat*1.5-\seats/2*1.5,-\rowcount*2) 

enter image description here

  • very nice, short, clean code! It's a very good beginning. thank you! – Geremia Aug 22 '14 at 4:03
  • How would I change \setchildnames so that it would take a parameter for the total number of seats and pad the list if the number of students is less than the number of seats, so the list is always the same length as the number of seats? thanks – Geremia Sep 3 '14 at 18:37
  • And what about if I wanted to put certain children in determined seats and randomize the others? How would that be done? thanks again – Geremia Sep 3 '14 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.