3

we've quite often have to write tables in our CI layout (colors, borders, fonts, etc). At the moment we use the standard tabular environment with lots of extra instructions (in the environment parameters as well as individual cells).

I'd like to code my own environment, which handles everything on its own, so I can simply type it like that:

\begin{myTable}{lll}
    head a &  head b  & head c \\
    data a1 & data b1 & datac1 \\
    data a2 & data b2 & datac2 \\
    ...
\edd{myTable}

And this will automatically produce my CI-formatted table (eg. including horizontal line under head, specific colors for head and body cells, etc, etc).

Could anyone please enlighten me on how do that ?

thx.

2

1 Answer 1

2

Separation of content and design was a major issue in developing the cals package. The cals tables are verbose, but it allows to add hooks for decorations.

calstable in designs

\documentclass{article}
\usepackage{cals}
\usepackage{xcolor}
\begin{document}
\makeatletter

%
% The table.
%
\newcommand\mktable{%
\begin{calstable}
\colwidths{{12mm}{12mm}}
\alignR
\thead{
\brow \cell{$\phantom{n^2}n$} \cell{$n^2$} \erow
}
\brow \cell{1} \cell{1} \erow
\brow \cell{2} \cell{4} \erow
\brow \cell{3} \cell{9} \erow
\brow \cell{4} \cell{16} \erow
\brow \cell{5} \cell{25} \erow
\end{calstable}
}

%
% Display the table in the default design
%
\noindent Default design\par\smallskip
\mktable

\bigskip

%
% Implement the corpodate design
%
\let\calstable@old=\calstable
\let\thead@old=\thead
\newcommand\setbodycolor{\def\cals@bgcolor{gray}}
\newcommand\setheadcolor{\def\cals@bgcolor{blue}}

\renewcommand\calstable{\calstable@old
\def\cals@bodyrs@width{1mm}
\cals@setpadding{\vbox to 6mm{}}
\setbodycolor}

\renewcommand\thead[1]{\setheadcolor
\thead@old{#1}
\setbodycolor}

%
% Display the table in the corporate design
%
\noindent Corporate design\par\smallskip
\mktable

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .