定制表格环境

定制表格环境

我们经常需要在 CI 布局中编写表格(颜色、边框、字体等)。目前,我们使用带有大量额外指令的标准表格环境(在环境参数以及单个单元格中)。

我想编写自己的环境,它可以自行处理所有事情,因此我可以简单地像这样输入:

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

这将自动生成我的 CI 格式的表格(例如,包括头部下方的水平线、头部和身体细胞的特定颜色等等)。

有人可以告诉我该怎么做吗?

谢谢。

答案1

内容和设计的分离是开发该软件包时的一个主要问题cals。cals 表很冗长,但它允许添加钩子进行装饰。

设计中可弯曲

\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}

相关内容