如何安排 \tcbcolorbox 以适应两个可选的长度参数?

如何安排 \tcbcolorbox 以适应两个可选的长度参数?
%------------------------------------------------------------------------------------------------------ %
\documentclass[english]{book}
%------------------------------------------------------------------------------------------------------ %
%
%\usepackage[fleqn]{amsmath} %
%\usepackage{amsthm,amssymb}
\usepackage[skins,theorems,most]{tcolorbox} %
\usepackage{newtxtext} %
\usepackage{setspace} %
\usepackage{xcolor} %
\usepackage{colortbl} %
\usepackage[paperwidth=170mm,paperheight=240mm,textwidth=132mm,lmargin=12.5mm,rmargin=12.5mm,bindingoffset=12.5mm,noheadfoot,nomarginpar,showframe,showcrop]{geometry} %
\usepackage[a4,frame,cam,center]{crop} %
\usepackage{layout} %
\usepackage{graphicx} %
\usepackage[skins,theorems,most]{tcolorbox} %
\usepackage[T1]{fontenc}

\setlength{\unitlength}{1mm} %

\noindent Can this be modified to allow \newtcbox{\mybox}[2]...  with bottom=2.4pt changed to bottom=#2 ?

\newtcbox{\mybox}[1][2.4pt]{on line, arc=0pt, outer arc=0pt, colback=yellow!10!white, colframe=red!50!white,
boxrule=0pt, bottomrule=1pt, toprule=1pt, boxsep=0pt, left=1pt, right=1pt,
top=#1, bottom=2.4pt}


\begin{document}

\setstretch{1.00}

\noindent \,----------------------------------------------------------------- %

\noindent The \,\mybox{quick brown fox} \,jumped over \,\mybox[8pt]{the very lazy dog}\,.
\vspace{12pt}

\end{document}

答案1

默认情况下,您有无限数量的带有 pgf 键的可选参数。也就是说,我只需执行

%------------------------------------------------------------------------------------------------------ %
\documentclass[english]{book}
%------------------------------------------------------------------------------------------------------ %
%
%\usepackage[fleqn]{amsmath} %
%\usepackage{amsthm,amssymb}
\usepackage{newtxtext} %
\usepackage{setspace} %
\usepackage[paperwidth=170mm,paperheight=240mm,textwidth=132mm,lmargin=12.5mm,rmargin=12.5mm,bindingoffset=12.5mm,noheadfoot,nomarginpar,showframe,showcrop]{geometry} %
\usepackage[a4,frame,cam,center]{crop} %
\usepackage{layout} %
\usepackage[skins,theorems,most]{tcolorbox} %
\usepackage[T1]{fontenc}

\setlength{\unitlength}{1mm} %
%\noindent Can this be modified to allow \newtcbox{\mybox}[2]...  with bottom=2.4pt changed to bottom=#2 ?

\newtcbox{\mybox}[1][]{on line, arc=0pt, outer arc=0pt, colback=yellow!10!white, colframe=red!50!white,
boxrule=0pt, bottomrule=1pt, toprule=1pt, boxsep=0pt, left=1pt, right=1pt,
bottom=2.4pt,top=2.4pt,#1}


\begin{document}

\setstretch{1.00}

\noindent \,----------------------------------------------------------------- %

\noindent The \,\mybox{quick brown fox} \,jumped over \,\mybox[top=8pt]{the very lazy dog}\,.
\vspace{12pt}

\noindent The \,\mybox{quick brown fox} \,jumped over \,\mybox[bottom=8pt]{the very lazy dog}\,.
\vspace{12pt}

\end{document}

在此处输入图片描述

虽然可以编写带有两个可选参数的宏,例如xparse,但我不会这样做。您必须始终记住这些可选参数的顺序。此外,如果您想添加更多选项,则必须更改宏。在这里,您可以任意添加许多选项而不会失去向后兼容性。

相关内容