两个高度相等且具有动态 ID 的框

两个高度相等且具有动态 ID 的框

我正在尝试使用 定义 citebox 样式tcolorbox。该样式由两个并排的框组成,它们的高度应完全相同。为此,我需要使用equal height group=XXX(否则会出现明显的差异,如屏幕截图所示)。问题是它在另一个命令内,并且每次使用该命令时,id 都需要是“动态”或本地的。或者也许有更好的方法来实现相同的结果?

我也试图根据周围字体大小按给定的倍数缩小字体/框,但我不确定如何做到这一点。

最小工作示例:

\documentclass{article}
\usepackage{biblatex}
\addbibresource{biblatex-examples.bib}

\usepackage[most]{tcolorbox}

\newtcbox{\citeboxleft}{%
  nobeforeafter, box align=base,
  boxsep=0pt,arc=1pt, boxrule=0.5pt,
  top=2pt, bottom=2pt, right=2pt, left=2pt,
  %% equal height group=A,
  colframe=black, coltext=white, colback=black,
  sharp corners=east}

\newtcbox{\citeboxright}{%
  nobeforeafter, box align=base,
  boxsep=0pt, arc=1pt, boxrule=0.5pt,
  top=2pt, bottom=2pt, right=2pt, left=2pt,
  %% equal height group=A,
  colframe=black, coltext=black, colback=white,
  sharp corners=west}

\newcommand\citebox[1]{%
  \AtNextCite{\defcounter{maxnames}{1}}%
  \citeboxleft{\sffamily\citeauthor{#1}}%
  \citeboxright{\sffamily\citeyear{#1}}}

\begin{document}
\noindent
{\small This is a test for the citebox style \citebox{kastenholz} using different size.}\\
{\footnotesize This is a test for the citebox style \citebox{kastenholz} using different size.}\\
{\scriptsize This is a test for the citebox style \citebox{kastenholz} using different size.}
\end{document}

citebox 截图

更新代码(回答):

\documentclass{article}
\usepackage{relsize}
\usepackage{biblatex}
\addbibresource{biblatex-examples.bib}

\usepackage[most]{tcolorbox}

\newtcbox{\refboxleft}{%
  nobeforeafter,  box align=base, before upper={\strut},
  boxsep=0pt, arc=0.1em, boxrule=0.05em,
  top=0pt, bottom=-0.15em, right=0.3em, left=0.3em,
  colframe=black, coltext=white, colback=black,
  sharp corners=east}

\newtcbox{\refboxright}{%
  nobeforeafter, box align=base, before upper={\strut},
  boxsep=0pt, arc=0.1em, boxrule=0.05em,
  top=0pt, bottom=-0.15em, right=0.3em, left=0.3em,
  colframe=black, coltext=black, colback=white,
  sharp corners=west}

\newcommand\refbox[2]{%
  \textsmaller[1]{%
    \refboxleft{\sffamily #1}%
    \refboxright{\sffamily #2}}}

%% Regular box    
%% \newcommand\citebox[1]{%
%% \AtNextCite{\defcounter{maxnames}{1}}%
%% \refbox{\citeauthor{#1}}{\citeyear{#1}}}

%% New cite command version
\DeclareCiteCommand{\citebox}
{}{\bibhyperref{\refbox{\printnames{labelname}}{\printfield{year}}}}{}{}


\begin{document}
\noindent
{\small This is a test for the citebox style \citebox{kastenholz} using different size.}\\
{\footnotesize This is a test for the citebox style \citebox{kastenholz} using different size.}\\
{\scriptsize This is a test for the citebox style \citebox{kastenholz} using different size.}
\end{document}

在此处输入图片描述

答案1

解决方案

诡计before upper={\strut}在每个盒子里使用的。

\documentclass{article}
\usepackage{relsize}
\usepackage{biblatex}
\addbibresource{biblatex-examples.bib}

\usepackage[most]{tcolorbox}

\newtcbox{\refboxleft}{%
  nobeforeafter,  box align=base, before upper={\strut},
  boxsep=0pt, arc=0.1em, boxrule=0.05em,
  top=0pt, bottom=-0.15em, right=0.3em, left=0.3em,
  colframe=black, coltext=white, colback=black,
  sharp corners=east}

\newtcbox{\refboxright}{%
  nobeforeafter, box align=base, before upper={\strut},
  boxsep=0pt, arc=0.1em, boxrule=0.05em,
  top=0pt, bottom=-0.15em, right=0.3em, left=0.3em,
  colframe=black, coltext=black, colback=white,
  sharp corners=west}

\newcommand\refbox[2]{%
  \textsmaller[1]{%
    \refboxleft{\sffamily #1}%
    \refboxright{\sffamily #2}}}

%% Regular box    
%% \newcommand\citebox[1]{%
%% \AtNextCite{\defcounter{maxnames}{1}}%
%% \refbox{\citeauthor{#1}}{\citeyear{#1}}}

%% New cite command version
\DeclareCiteCommand{\citebox}
{}{\bibhyperref{\refbox{\printnames{labelname}}{\printfield{year}}}}{}{}


\begin{document}
\noindent
{\small This is a test for the citebox style \citebox{kastenholz} using different size.}\\
{\footnotesize This is a test for the citebox style \citebox{kastenholz} using different size.}\\
{\scriptsize This is a test for the citebox style \citebox{kastenholz} using different size.}
\end{document}

相关内容