# Automatically insert capital letters as alphabetical breakpoints in a sorted column of names

Recently I used LyX to prepare a list with 200+ guest names for a wedding (page 1 illustrated below). Actually, it was a table including invited family names, the number of persons of each invited family, the number of the table given to the family and an alternative table number.

The table was initially created in a spreadsheet and afterwards extracted as a csv file which was the basis for the final "guest list". The family names (1st column of the table) were already alphabetically sorted. Small caps were applied for family names, alternate table row-coloring (for a longtable within LyX), bold numbers referring to the tables and other font details.

In addition, I manually inserted capital letters, just before family names started with a "new" letter, to give the sense of alphabetically grouped names and ease tracing them when the moments come were 50~100 people altogether, waiting in the entrance of the event hall, expect to be guided to their table.

The question: is there a way to automatically insert single rows with capital letters as "breakpoints" (as shown in the attached page above) using a "normal", sorted, column of names? And how about automatically adding some custom command in each of the "letter"-rows, like for example \hiderowcolors{} and \showrowcolors{} in each following row? I imagine that something like this could be useful to create easier to read long "guests lists".

-

It's probably easier to get the spreadsheet to add the headings as it writes the csv file but anyway If you want Tex to do it, then something like this:

\documentclass{article}

\usepackage{longtable}
\usepackage[table]{xcolor}

\makeatletter
\let\savedcr\LT@tabularcr
\def\LT@tabularcr{\xxLT@tabularcr\savedcr}

\def\xxLT@tabularcr#1#2{%
\ifcat a\noexpand#2%
\if\thisletter#2%
\expandafter\@gobble
\else
\expandafter\@firstofone
\fi
{\expandafter#1\expandafter\letterrow\expandafter#2\expandafter}%
\fi
\savedcr#2}

\def\letterrow#1{%
\noalign{\gdef\thisletter{#1}}%
\rowcolor{blue}%
\multicolumn{\LT@cols}{c}{%
\color{white}%
\bfseries\thisletter}}

\makeatother

\begin{document}

\rowcolors{1}{gray!20}{white}
\def\thisletter{?}
\def\zzz#1{\def\a{#1}\show\a#1}
\begin{longtable}{ll}
\rowcolor{yellow}Name&Number\\
\hline