我使用 cals 包制作了一个表格,我想使用 colwidths 修改表格的宽度,当我重写此代码中的值时:\colwidths{{\dimexpr(\columnwidth)/34*4\relax},表格向右加宽,我该如何让它向左和向右加宽?如果我想将规则颜色更改为 RGB:221, 216, 195,我该如何修改代码?这是我的代码
\documentclass[a4paper, 11pt, UTF8]{ctexrep}
\usepackage[T1]{fontenc}
\usepackage{ctex}
\usepackage{etoolbox}
\usepackage{cals, caption}
\usepackage[svgnames]{xcolor}
\definecolor{st_table_blue}{RGB}{87, 142, 210}
\definecolor{gridcolor}{RGB}{221, 216, 195}
\let\nc=\nullcell % Shortcuts
\let\sc=\spancontent
\begin{document}
\begin{table}
\caption{A table\label{tabelTable}}
\begin{calstable}[c]
%\arrayrulecolor{gridcolor}
% Defining columns relative to each other and relative to the margins
\colwidths{{\dimexpr(\columnwidth)/34*4\relax}
{\dimexpr(\columnwidth)/34*12\relax}
{\dimexpr(\columnwidth)/34*6\relax}
{\dimexpr(\columnwidth)/34*6\relax}
%{\dimexpr(\columnwidth)/34*6\relax}
{\dimexpr(\columnwidth)/25*6\relax}
}
% The tabular fills the text area if sum of all columns is 6
% Set up the tabular
\makeatletter
%\def\cals@framers@width{0.2pt}
\def\cals@framers@width{0.2pt} % Outside frame rules, reduce if the rule is too heavy
\def\cals@framecs@width{0.2pt}
\def\cals@framers@color{gridcolor}
\def\cals@bgcolor{}
\def\cals@AtBeginCell{\vfil} % Ensure that all cells is vertically centred
\setlength{\cals@paddingL}{3pt}
\setlength{\cals@paddingR}{3pt}
\def\lblue{\ifx\cals@bgcolor\empty % "Switch" to turn on and off colour
%\def\cals@bgcolor{LightSteelBlue}
\def\cals@bgcolor{st_table_blue}
\else \def\cals@bgcolor{} \fi}
% R1H1
\thead{\footnotesize\bfseries
\brow
\lblue\nc{lrt}
\nc{ltb}
\nc{tb}
\nc{rtb}\alignC\sc{Heading spanning three columns}
\nc{lrt}
\erow
%R2H2
\brow
\nc{lrb}\alignC\sc{Text}
%\cell{\bfseries\textcolor{white}{Subheading is long and that wraps}}
\cell{\bfseries\textcolor{white}{FDA/NMPA\\批准于本癌种}}
\cell{Short}
\cell{Subheading that wraps}
\nc{lrb}\alignC\sc{Text}\lblue
\erow
\mdseries}
\tfoot{\lastrule\strut}
%R3B1
\brow
\alignC\cell{Wrapping text}
%\cell{Horiz. and vertic. centred}
\alignC\cell{阿法替尼*,达克替尼*, 奥西替尼*,吉非替尼*,埃克替尼*,厄洛替尼*,阿美替尼*}
\cell{2}
\cell{3}
\cell{1}
\erow
%R3B1
\brow
\alignC\cell{1}
\cell{2}
\cell{2}
\cell{3}
\cell{1}
\erow
\makeatletter
\end{calstable}
\end{table}
\end{document}
答案1
希望以下修改MWE
能满足您的要求:
\documentclass[a4paper, 11pt, UTF8]{ctexrep}
\usepackage[T1]{fontenc}
\usepackage{ctex}
\usepackage{etoolbox}
\usepackage{cals, caption}
\usepackage[svgnames]{xcolor}
\definecolor{st_table_blue}{RGB}{87, 142, 210}
\definecolor{gridcolor}{RGB}{221, 216, 195}
\let\nc=\nullcell % Shortcuts
\let\sc=\spancontent
\begin{document}
\makeatletter
\renewcommand\cals@cs@outOne[3]{%
\ifx \relax#1%
\else
\cals@withColorII\cals@bgcolor{#3}\iftrue
\textcolor{\cals@color}{\vrule depth0pt width#1 }%
\hskip -#1\relax
\fi
\fi
\cals@withWidthII\cals@cs@width{#2}\iftrue
\cals@halfWidthToDimen0 \cals@width %
\hskip -\dimen0 %
\color{white}\vrule depth0pt width\cals@width\relax
\hskip -\dimen0 %
\fi
\let\cals@lastLeftWidth=\cals@width
\ifx \relax#1\else \hskip#1 \fi
}
\renewcommand\cals@rs@sofar@out{%
\ifdim 0pt=\cals@rs@sofar@width\relax
\hskip\cals@rs@sofar@length\relax
\else
\cals@halfWidthToDimen0\cals@rs@sofar@borderl
\hskip-\dimen0\relax
\cals@halfWidthToDimen2\cals@rs@sofar@borderr
\dimen4=\cals@rs@sofar@length\relax
\advance\dimen4 by \dimen0\relax \advance\dimen4 by \dimen2\relax
\cals@halfWidthToDimen6\cals@rs@sofar@width
\color{white}\vrule height\dimen6 depth\dimen6 width\dimen4\relax
\hskip-\dimen2\relax
\fi}
\makeatother
\begin{table}
\caption{A table\label{tabelTable}}
\begin{calstable}[c]
% Defining columns relative to each other and relative to the margins
\colwidths{{\dimexpr(\columnwidth)/34*4\relax}
{\dimexpr(\columnwidth)/34*12\relax}
{\dimexpr(\columnwidth)/34*6\relax}
{\dimexpr(\columnwidth)/34*6\relax}
%{\dimexpr(\columnwidth)/34*6\relax}
{\dimexpr(\columnwidth)/25*6\relax}
}
% The tabular fills the text area if sum of all columns is 6
% Set up the tabular
\makeatletter
%\def\cals@framers@width{0.2pt}
\def\cals@framers@width{0.2pt} % Outside frame rules, reduce if the rule is too heavy
\def\cals@framecs@width{0.2pt}
\def\cals@framers@color{gridcolor}
\def\cals@bgcolor{}
\def\cals@AtBeginCell{\vfil} % Ensure that all cells is vertically centred
\setlength{\cals@paddingL}{3pt}
\setlength{\cals@paddingR}{3pt}
\def\lblue{\ifx\cals@bgcolor\empty % "Switch" to turn on and off colour
%\def\cals@bgcolor{LightSteelBlue}
\def\cals@bgcolor{st_table_blue}
\else \def\cals@bgcolor{} \fi}
% R1H1
\thead{\footnotesize\bfseries
\brow
\lblue\nc{lrt}
\nc{ltb}
\nc{tb}
\nc{rtb}\alignC\sc{Heading spanning three columns}
\nc{lrt}
\erow
%R2H2
\brow
\nc{lrb}\alignC\sc{Text}
%\cell{\bfseries\textcolor{white}{Subheading is long and that wraps}}
\cell{\bfseries\textcolor{white}{FDA/NMPA\\??????}}
\cell{Short}
\cell{Subheading that wraps}
\nc{lrb}\alignC\sc{Text}\lblue
\erow
\mdseries}
\tfoot{\lastrule\strut}
%R3B1
\brow
\alignC\cell{Wrapping text}
%\cell{Horiz. and vertic. centred}
\alignC\cell{????*,????*, ????*,????*,????*,????*,????*}
\cell{2}
\cell{3}
\cell{1}
\erow
%R3B1
\brow
\alignC\cell{1}
\cell{2}
\cell{2}
\cell{3}
\cell{1}
\erow
\makeatletter
\end{calstable}
\end{table}
\end{document}
输出