
%%
\NeedsTeXFormat{LaTeX2e}[1994/12/01]
\ProvidesPackage{tablestyles}
          [2011/10/01 v0.1 tablestyles]
\RequirePackage{array}
\RequirePackage{etoolbox}
%% check that xcolor is not loaded
\@ifpackageloaded{xcolor}{%
  \ifcsdef{rowcolors}{}{%
    \PackageError{tablestyles}%
    {%
\MessageBreak%
Package 'xcolor' must be loaded with the option\MessageBreak%
'tables'. Otherwise the command rowcolors\MessageBreak%
is not available. \MessageBreak%
    }{}%
    \endinput%
  }%
}{%
  % xcolor not loaded
  \PassOptionsToPackage{table}{xcolor}
  \RequirePackage{xcolor}
}
\RequirePackage{ragged2e}
\AtBeginDocument{%
\@ifpackageloaded{tabularx}{}{
    \PackageError{tablestyles}%
    {%
\MessageBreak%
Package 'tabularx' must be loaded, otherwise tablestyles will not
work.
  }%
}% end of ifpackageloaded
}% end of AtBeginDocument
%% define table styles (save the code)
\newcommand{\setuptablestyle}[2]{%
  \ifcsdef{tsty@style@#1}
  {
    \PackageWarning{tablestyles}{
    \MessageBreak
      table style `#1' is already defined.
    }{}
  }{}
  \csdef{tsty@style@#1}{#2}
}
%% apply table styles (use the code)
\newcommand{\tablestyle}[1][default]{%
  \ifcsdef{tsty@style@#1}{}{
    \PackageError{tablestyles}{
      \MessageBreak
      table style `#1' is not defined.
      \endinput%
    }{}
  }
  \csuse{tsty@style@#1}
}
%% save font size with name
\newcommand{\setuptablefontsize}[2]{
  \csdef{tsty@font@#1@size}{#2}
}
%% apply font size with name
\newcommand{\tablefontsize}[1]{
  \ifcsdef{tsty@font@#1@size}%
  {\csuse{tsty@font@#1@size}%
  }{ % not defined
    \PackageError{tablestyles}{
      \MessageBreak
      table font size `#1' is not defined.
      \endinput%
    }{}%
  }%
}%
%% define default font sizes
\setuptablefontsize{body}{\small}
\setuptablefontsize{head}{\small}
%% save color with name
\newcommand{\setuptablecolor}[2]{%
  \colorlet{tsty@color@#1}{#2}%
}
%% apply colorwith name
\newcommand{\tablecolor}[1]{tsty@color@#1}
%% default colors
\newcommand{\tsty@defaultcolors}{
  \setuptablecolor{body}{white!100}
  \setuptablecolor{row}{gray!10}
  \setuptablecolor{head}{gray!25}
  \setuptablecolor{subhead}{gray!30}
}
%% exectuted default colors
\tsty@defaultcolors
%% shortcut for alternating rowcolors
\newcommand\tablealtcolored{%
\rowcolors{1}{\tablecolor{row}}{\tablecolor{body}}%
}
%% disable alternating rowcolors by changing the colors
\newcommand{\disablealternatecolors}{%
  \setuptablecolor{row}{\tablecolor{body}}%
}
%% colored horizontal lines (hlines)
\providecommand{\coloredhline}[1]{%
    \arrayrulecolor{#1}\hline
    \arrayrulecolor{black}
}%
%% colored vertical lines (vlines)
\providecommand{\coloredvline}[1]{%
    \color{#1}\vline
}%
%% commands for the style of the lines
\newcommand{\tlinetop}{\coloredhline{black}}
\newcommand{\tlinemid}{\coloredhline{black}}
\newcommand{\tlinebottom}{\coloredhline{black}}
%% commands for the seperations (includes the lines)
\newcommand{\tbegin}{\tlinetop}
\newcommand{\tbody}{\tlinemid}
\newcommand{\tend}{\tlinebottom}
%% default head style (only fontsize)
\newcommand\thead{%
  \tablefontsize{head}
}
%% default subhead style (only fontsize)
\newcommand{\tsubhead}{%
  \tablefontsize{head}
}
%% style of header start (line and row color)
\newcommand\theadstart{%
  \tlinetop%
  \rowcolor{\tablecolor{head}}%
}
%% style of header end - empty
\newcommand\theadend{}
%% style of subheader start (row color)
\newcommand{\tsubheadstart}{%
  \rowcolor{\tablecolor{subhead}}
}
%% style of subheader end - empty
\newcommand\tsubheadend{}
%% shortcut for multi column row in header
\newcommand{\theadrow}[2]{%
  \multicolumn{#1}{>{\columncolor{\tablecolor{head}}}l}{%
  \thead #2%
  }%
  \tabularnewline%
}%
%% shortcut for multi column row in subheader
\newcommand{\tsubheadrow}[2]{%
  \multicolumn{#1}{>{\columncolor{\tablecolor{subhead}}}l}{%
  \tsubhead #2%
  }%
  \tabularnewline%
}%
%% reset to default styles
\newcommand{\resettablestyle}{%
  \normalcolor\normalfont\normalsize%
  \renewcommand{\arraystretch}{1}%
  \rmfamily%
  \tsty@defaultcolors%
  \renewcommand{\tlinetop}{\coloredhline{black}}
  \renewcommand{\tlinemid}{\coloredhline{black}}
  \renewcommand{\tlinebottom}{\coloredhline{black}}
  \renewcommand{\theadstart}{\tlinetop\rowcolor{\tablecolor{head}}}
  \renewcommand{\tbegin}{\tlinetop}
  \renewcommand{\tbody}{\tlinemid}
  \renewcommand{\tend}{\tlinebottom}
}
%% style: default
\setuptablestyle{default}{%
  \resettablestyle
  \renewcommand{\arraystretch}{1.4}
  \centering
  \sffamily
  \upshape%
  \tablefontsize{body}
  \tablealtcolored%
  \renewcommand{\thead}{%
\tablefontsize{head}%
\ignorespaces%
  }
  \renewcommand{\tsubhead}{%
\tablefontsize{head}%
\ignorespaces%
  }
}
%% style: roman
\setuptablestyle{roman}{%
  \resettablestyle
  \renewcommand{\arraystretch}{1.4}
  \centering
  \rmfamily
  \upshape%
  \tablefontsize{body}
  \tablealtcolored%
  \renewcommand{\thead}{%
\tablefontsize{head}%
\ignorespaces%
  }
  \renewcommand{\tsubhead}{%
\tablefontsize{head}%
\ignorespaces%
  }
}
%% style: sansbold
\setuptablestyle{sansbold}{%
  \resettablestyle
  \renewcommand{\arraystretch}{1.4}
  \centering
  \sffamily
  \upshape%
  \tablefontsize{body}
  \tablealtcolored%
  \renewcommand{\thead}{%
\tablefontsize{head}%
\bfseries
\upshape%
\ignorespaces%
  }
  \renewcommand{\tsubhead}{%
\tablefontsize{head}%
\upshape%
\ignorespaces%
  }
}
%% style: sansboldbw
\setuptablestyle{sansboldbw}{%
  \resettablestyle
  \setuptablecolor{body}{white!100}
  \setuptablecolor{row}{gray!15}
  \setuptablecolor{head}{black!60}
  \setuptablecolor{subhead}{gray!40}
  \renewcommand{\arraystretch}{1.4}
  \centering
  \sffamily
  \upshape%
  \tablefontsize{body}
  \tablealtcolored%
  \renewcommand{\thead}{%
\leavevmode\color{white}
\tablefontsize{head}%
\bfseries
\slshape
\ignorespaces%
  }
  \renewcommand{\tsubhead}{%
\tablefontsize{head}%
\bfseries
\ignorespaces%
  }
}
%% bugfix code for lists in tables
\newcommand{\tsty@removeindentation}{%
\leftmargini=\labelsep%
\advance\leftmargini by \labelsep%
}
\newcommand\tableitemize{
\@minipagetrue%
\tsty@removeindentation
}
%% New columntype definitions:
%% centered (X):
\newcolumntype{Z}{>{\centering\arraybackslash\hspace{0pt}}X}
%% right (X):
\newcolumntype{Y}{>{\RaggedLeft\arraybackslash\hspace{0pt}}X}
%% left (X):
\newcolumntype{W}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}
%% left (p):
\newcolumntype{L}[1]{>{\RaggedRight\arraybackslash\hspace{0pt}}p{#1}}
%% right (p):
\newcolumntype{R}[1]{>{\RaggedLeft\arraybackslash\hspace{0pt}}p{#1}}
%% centered (p):
\newcolumntype{C}[1]{>{\Centering\arraybackslash\hspace{0pt}}p{#1}}
\endinput
%%
%% End of file `tablestyles.sty'.
