我创建了一个环境,它接受输入并创建表格。下面提供了此环境的 MWE。我现在想做的是修改表格格式输入。
此表具有使标题行具有粗体文本的内置方法,但是此方法依赖于将命令 \clearrow 附加到格式化输入的末尾。当用户未|
在格式化末尾提供时,此方法没有问题,但如果他们提供了,则环境将崩溃。
除了修复上述问题之外,我还想获取它们的格式输入并删除任何前面和后面的内容,如果不存在,|
则在每个列规范之间插入一个。下面提供了我希望在几种情况下如何更改格式的示例。|
|C{0.2}L{0.2}R{0.2}L{0.4}| -> C{0.2}|L{0.2}|R{0.2}|L{0.4}
|C{0.2}|L{0.2}|R{0.2}|L{0.4}| -> C{0.2}|L{0.2}|R{0.2}|L{0.4}
C{0.25}L{0.75} -> C{0.25}|L{0.75}
我可以按照我想要的方式修改输入吗?
最小工作示例
\documentclass{article}
\usepackage[table]{xcolor} % Provides coloring for tables and text
\usepackage{tabularx} % Customized table formatting
\RequirePackage{environ} % Used to define custom table environment
% Define table related commands and properties
\definecolor{greyblue}{rgb}{0.6353,0.6863,0.7686} % Define a color used in the tables
\newcommand\setrow[1]{\gdef\rowmac{#1}#1\ignorespaces} % Used for making a row bold
\newcommand\clearrow{\global\let\rowmac\relax} \clearrow % Used for clearing a row formatting
\newcolumntype{C}[1]{>{\hsize=#1\hsize\rowmac\centering\arraybackslash}X} % Centered column, input is relative width of page
\newcolumntype{L}[1]{>{\hsize=#1\hsize\rowmac\raggedright\arraybackslash}X} % Left-aligned column, input is relative width of page
\newcolumntype{R}[1]{>{\hsize=#1\hsize\rowmac\raggedleft\arraybackslash}X} % Left-aligned column, input is relative width of page
% Defines an environment to create a table in the document according to
% a common formatting. This uses the environ package.
\NewEnviron{doctable}[4]{
\begin{table}[!htbp]
\centering
\rowcolors{2}{black!5}{black!15}
\begin{tabularx}{#3\linewidth}{#4<{\clearrow}}%
\hline
\rowcolor{greyblue} \setrow{\bfseries} % Make the header row bold and colored grey-blue
\BODY
\hline
\end{tabularx}
\caption{#2}
\label{#1}
\end{table}
}
\begin{document}
\begin{doctable}
{tbl:label}
{Table Caption}
{1} { C{0.25}L{0.75} }
Heading 1 & Heading 2 \\
Text 1 & Text 2 \\
\end{doctable}
\end{document}