Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

Table of families invited in a wedding, alphabetically sorted (1st column)

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".

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

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:

enter image description here

\documentclass{article}

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

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

\let\savedendhead\endhead
\def\endhead{\xxLT@tabularcr\savedendhead}

\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}%
\global\advance\rownum\m@ne
\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
\endhead
Apple & 2\\
Artichoke &3\\
Banana&1\\
Cabbage&6\\
Cucumber&8
\end{longtable}


\end{document}
share|improve this answer
add comment

Your Answer

 
discard

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.