# Classroom Seating Chart in TikZ?

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

thanks

-

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.

\documentclass[tikz,border=5]{standalone}
\def\countitemsinmacro#1{\foreach \i [count=\itemcount, remember=\itemcount] in #1{}}
\tikzset{%
every seat/.style={
shape=rectangle,
draw,
font=\footnotesize,
minimum width=1.5cm,
minimum height=1cm,
},
}
\begin{document}
\begin{tikzpicture}
\foreach \childrenrow [count=\rownumber]
in {%
{Alphie,{Bert,Carl},{Dennis,Eon},{Frank,George},{Harry}},%
{{Alice,Beth},{Carrie,Doris},{Ellie,Felicity},{Gina,Hetty}},%
}{
\countitemsinmacro{\childrenrow}%
\let\tabletotal=\itemcount%
\foreach \children [count=\tablenumber] in \childrenrow {
\countitemsinmacro{\children}%
\let\seatcount=\itemcount%
\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};
}}}
\end{tikzpicture}
\end{document}


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.

\documentclass[tikz,border=5]{standalone}
\makeatletter
\def\globalnamelet#1#2{%
\def\marshal{\expandafter\global\expandafter\let\csname#1\endcsname}%
\expandafter\marshal\csname#2\endcsname%
}
\def\setchildnames#1{\foreach\childname[count=\i@,remember=\i@]in{#1}{%
\globalnamelet{childlist@\i@}{childname}%
}\let\childlistcount=\i@}

\def\shufflechildnames#1{%
\foreach\i@ in{1,...,#1}{%
\foreach\j@ in{1,...,\childlistcount}{%
\pgfutil@namelet{tmpchild}{childlist@\j@}%
\pgfmathrandominteger\k@{1}{\childlistcount}%
\globalnamelet{childlist@\j@}{childlist@\k@}%
\globalnamelet{childlist@\k@}{tmpchild}%
}}}

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

\begin{document}
\setchildnames{Alfie,Ben,Carol,Dalia,Ellie,Felicty,George,%
Qaniah,Rohana,Samita,Thomas,Ute,Vera}
\shufflechildnames{10}
\begin{tikzpicture}
\def\c{0}
\foreach \tables/\tableseats [count=\rowcount, remember=\c] in
%
{5/{1,2,2,2,1},4/{2,2,2,2},3/{2,2,2}}
%
\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)
{\strut\getchildname{\c}};
\end{tikzpicture}
\end{document}


-
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