This is a follow-up question

in which I asked how to define classes with \newcommands into \newenvironments, and I had some good answers to this particular issue. However, the problem that I have does not rely only on the issue described in the other thread, but it is more general. for instance, I wish to create a class to generate tables like the following


The plain code that I use to create this table is the following

\documentclass[landscape, 12pt]{report}

\usepackage[top=0.1cm, bottom=0cm, left=0.1cm, right=-0cm]{geometry}


    Champions League \\
    - Team 1: The Hawks\\
         \item John
         \item Carl
         \item Smith
     \end{enumerate} \
         \item Anthony
         \item Luke
     \end{enumerate} \\
     COACH: Robert\\\hline


And I am quite happy with that, but I wish also to create a class such, referring to the example in the picture:

  1. The "1" after "- Team" in the second line is an incresing number (so I guess I need a counter inside a \newenviroment definition);
  2. What is written with capital letters (e.g. FIRST-STRING PLAYERS, etc.) is fixed in the table;
  3. The tournament name (e.g. Champions League is a kind of "global" variable)

As an indicative example, here is a kind of main document I wish to use:



\CUP{Champions League}

\TeamName{The Hawks}
    \item John
    \item Carl
    \item Smith
    \item Anthony
    \item Luke

I hope that my problem is clear. Unfortunately, I have never written any class before, so any help will be greatly appreciated.


There are many ways to do this, but here's one building on the tabular format that you created. There's no need to create a document class for this; you would want to make it a package instead, and use it with whatever document class you wanted.

Save the teams.sty document in your local texmf folder. It should go in <path-to-local-folder>/tex/latex/.


\ProvidesPackage{teams}[2013/08/16 Team formatting environment]
\RequirePackage[dvipsnames,usenames]{xcolor} % load xcolor before realboxes
\RequirePackage[xcolor]{realboxes} % to use boxes in environments
\RequirePackage{etoolbox} % for easy list processing
\RequirePackage{array} % for tables
% Create user commands for the fixed names in case you want to change them
% This is probably a bit of an overkill in this case, but this is how 
% you should do things to make them changeable when needed.

% Setup some defaults (formatting will be done by \namefont)
\firststringname{First string players:}
\reservesname{Reserve players:}
\leaguename{Champions League}
\teamname{- Team:}

% Setup some formatting parameters

% Two commands for the first string and reserves
  \renewcommand*{\do}[1]{\item ##1}
  \renewcommand*{\do}[1]{\item ##1}

% Command for coach (but will be provided as an argument of the environment)
\newcommand{\coach}[1]{\gdef\teams@coachprint{\namefont\teams@coach #1}}

% Set up a team counter

% Make a column type for the table

% Now create a team environment
% This takes two obligatory arguments, and one optional one
% \begin{team}[color]{<team name>}{<coach name>}
    \refstepcounter{teamcount}\teams@team\ \theteamcount: #2\\
{  \hline

Sample document


\begin{team}{The Hawks}{Robert}

\begin{team}{The Owls}{Bob}
\firststring{Fred, Joe, Dave}
\reserves{Roger, Harry}

\leaguename{National Hockey League}
\begin{team}[red!30]{The Red Wings}{Mike Babcock}
\firststring{Henrik Zetterberg, Pavel Datsyuk,Justin Abdelkader}
\reserves{Drew Miller, Joakim Andersson,Patrick Eaves}


output of code

  • You suggests me to use a .sty, but I read in the class guide link that "If the commands could be used with any document class, then make them a package; and if not, then make them a class". That's why I was using a class, since it the output is a very particular document, and I don't think it will be used in any other document. Finally, I wonder how to find a guide to understand commands like \gdef\teams@coachprint. Are they TeX or LaTeX commands? – Ubaldo Tiberi Aug 29 '13 at 7:55
  • Creating your own class is more work, and for this application not necessary. Also, fundamentally the functionality here provides simply an environment to display a team; it's not the design of a whole document. As for the \gdef commands, yes, they are TeX not LaTeX; sorry about that. A good (free) guide to TeX can be found in TeX by Topic, which should be part of your distribution documentation. The proper LaTeX way would be the following: define each of the internal macros first with \newcommand, and then replace the \gdef command with \renewcommand. – Alan Munn Aug 29 '13 at 11:38
  • For example: \newcommand{\teams@coachprint}{} and then use \newcommand{\coach}[1]{\renewcommand{\teams@coachprint}{\namefont\teams@coach #1}} – Alan Munn Aug 29 '13 at 11:41
  • Great! And what about the "@" symbol. When it is used? Any guide? – Ubaldo Tiberi Sep 3 '13 at 7:30
  • The @ symbol is commonly used inside class and package files to create macro names that are protected from the end user, since @ is not permitted in user defined macro names. See What do \makeatletter and \makeatother do? – Alan Munn Sep 3 '13 at 13:13

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.