我想一次定义几种选项样式,例如,,,cf1/.style args={#1}{#1}
等cf2/.style args={#1}{#1}
。cf3/.style args={#1}{#1}
我尝试过这样的方法:
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usepackage{tcolorbox}
\tcbuselibrary{skins,breakable,raster}
\begin{document}
\newcounter{loopvariable}
\setcounter{loopvariable}{5}
\whiledo{\theloopvariable > 1}{%
\addtocounter{loopvariable}{-1}
\tcbset{cf\theloopvariable/.style args={#1}{%
raster column \theloopvariable/.style={#1}}}
}
%
\begin{tcbitemize}
[raster force size=false,raster columns=4,sharp corners,
boxrule=3pt,
raster width=\textwidth,
raster column skip=0pt,
raster row skip=0pt,
cf3={colback=green}]
\tcbitem some text
\tcbitem some text
\tcbitem some text
\tcbitem some text
\end{tcbitemize}
\end{document}
但是排版是错误的(见附图)。那么,有人能告诉我如何实现我想要的功能吗?
答案1
您的示例缺少 ifthen 包,并且您对样式参数的使用很奇怪,但主要问题是计数器未扩展,因此您为第一列设置了所有样式。
\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usepackage{tcolorbox,ifthen}
\tcbuselibrary{skins,breakable,raster}
\begin{document}
\newcounter{loopvariable}
\setcounter{loopvariable}{5}
\whiledo{\theloopvariable > 1}{%
\addtocounter{loopvariable}{-1}
\edef\next{%
\noexpand\tcbset{cf\number\value{loopvariable}/.style ={%
raster column \number\value{loopvariable}/.style={##1}}}}
\next
}
%
\begin{tcbitemize}
[raster force size=false,raster columns=4,sharp corners,
boxrule=3pt,
raster width=\textwidth,
raster column skip=0pt,
raster row skip=0pt,
cf3={colback=green,width=5cm}]
\tcbitem some text
\tcbitem some text
\tcbitem some text
\tcbitem some text
\end{tcbitemize}
\end{document}