TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)?


share|improve this question
up vote 9 down vote accepted

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

share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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