4

I'm trying to define a citebox style using tcolorbox. The style is made up of two boxes side by side that should have the exact same height. To do that, I need to use equal height group=XXX (otherwise there's a noticeable difference as shown in the screenshot). The Problem is that it is inside another command, and the id would need to be "dynamic" or local for each use of the command. Or maybe there is a better way to achieve the same result?

I'm also trying to reduce the font/box by a given factor with regards to the surrounding font size, but I'm not sure how to do it.

Minimal working example:

\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 screenshots

Updated code (answer):

\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}

enter image description here

1
  • This looks nice. I do not get whether you still have questions? From the screenshots, it seems like it works? If you solved this already, I would suggest to post an answer for your own question and accept it.
    – Arne
    Commented Aug 7, 2023 at 14:58

1 Answer 1

0

Solution

The trick is to use before upper={\strut} in each box.

\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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .