1

I am trying to write a class that could produce a table with employee name and salary in it. I need the user of the class is to be able to just write the employee name and the salary inside the tex file. Minimal example is the following:

\ProvidesClass{Employee}[2016/07/11 version 1.00 Employee's Salaries]
\NeedsTeXFormat{LaTeX2e}
\LoadClass{article}
 %%%
 \RequirePackage{tabu,url}

  \newenvironment{salary}{
    \begin{center}


         \begin{tabular}{|c|c|}
               \hline 
                Name  & Salary \\ \hline

                John & 40,000\$\\ \hline
                %%% Here I do not want a pre--defined data

          \end{tabular}

   \end{center}


}{%}

}

and my tex file looks like this

\documentclass[9pt,a4paper,fullpage]{SXClass}
\begin{document}

  \begin{salary}
   %%%% I would like to add the names here as the following:
   %%%% \employee{empName}{empSalary}
   %%%% \employee{Joseph}{40,000}
   %%%% \employee{Bob}{70,000}
   %%%% and they will appear directly into the table.
   \end{salary}

\end{document}
  • Not about salaries, but related (somehow): tex.stackexchange.com/questions/318961/… – user31729 Jul 12 '16 at 13:05
  • There's a mismatch between the class named Employee and the class used in the document (SXClass), however – user31729 Jul 12 '16 at 13:26
1

I suggest to use longtable which is both already centered by default and capable of page breaks.

\ProvidesClass{Employee}[2016/07/11 version 1.00 Employee's Salaries]
\NeedsTeXFormat{LaTeX2e}
\LoadClass{article}
%%% 
\RequirePackage{tabu}
\RequirePackage{longtable}
\RequirePackage{url} % Why?


\newcommand{\employee}[2]{%
  #1 & #2\tabularnewline
  \hline
}

\newenvironment{salary}{%
  \begin{longtable}{|p{6cm}|>{\raggedleft\arraybackslash}p{5cm}|}
    \hline
    \textbf{Name} & \textbf{Salary} \tabularnewline
    \hline
    \endhead
    }{%
    \end{longtable}
  }
\endinput

Here's the driver

\documentclass[9pt,a4paper,fullpage]{Employee}

\begin{document}

\begin{salary}
  \employee{Wonder Woman}{500,000}
  \employee{Joseph}{40,000}
  \employee{Bob}{70,000}
  \employee{John}{10,000}
  \employee{Paul}{210,000}
\end{salary}

\end{document}

enter image description here

Update A version with siunitx column formatting:

\ProvidesClass{Employee}[2016/07/11 version 1.00 Employee's Salaries]
\NeedsTeXFormat{LaTeX2e}
\LoadClass{article}
%%% 
%\RequirePackage{tabu}
\RequirePackage{longtable}
\RequirePackage{siunitx}
\RequirePackage{url} % Why?


\newcommand{\employee}[2]{%
  #1 & #2\tabularnewline
  \hline
}

\newenvironment{salary}{%
  \begin{longtable}{|p{6cm}|S[table-alignment=right]|}
    \hline
    \textbf{Name} & \multicolumn{1}{c|}{\textbf{Salary}} \tabularnewline
    \hline
    \endhead
    }{%
    \end{longtable}
  }
\endinput

And the modified driver:

\documentclass[9pt,a4paper,fullpage]{Employee}

\begin{document}

\sisetup{copy-decimal-marker=true}

\begin{salary}
  \employee{Wonder Woman}{500,000}
  \employee{Joseph}{40,000}
  \employee{Bob}{70,000}
  \employee{John}{10,000}
  \employee{Paul}{210,000}
\end{salary}

\end{document}

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.