How can I make `\newtcbox{}` expand to the end of the line?
A tcbox
can't change its width apart from specifying right=...
etc. or enlarge left by=...
etc.
However, a wrapped tcolorbox
inside a command will work too, see the lower example.
Here are two versions -- with tcbraster
and a normal tcolorbox
way.
The raster
version is the cleaner one and most likely, the tcbitemize
should be used for the outer itemize/enumerate
structure.
\documentclass[a4paper,10pt]{article}
\usepackage{showframe}
\usepackage{calc}
\usepackage{multicol}
\usepackage{enumitem}
\usepackage[most]{tcolorbox}
\newcommand{\GrayColor}{gray!30}
\makeatletter
\newtcolorbox{InlineAnswerBox}[1][]{%
%top=0mm,
%bottom=0mm,
%left=0mm,
%right=0mm,
valign=center,
halign=center,
% capture=fitbox,
%arc=0pt,
%outer arc=0pt,
nobeforeafter,
boxsep=5pt,
% boxrule=0.0pt,
% colback=\GrayColor,
% colframe=white,
#1,
}
\makeatother
\newcommand{\InlineAnswer}[2][]{%
\begin{InlineAnswerBox}[#1]
#2
\end{InlineAnswerBox}%
}
\newtcolorbox{answertextbox}[1][]{%
valign=center,
size=minimal,
enhanced jigsaw,
boxrule=0pt,
sharp corners,
colback=white,
nobeforeafter,
left skip=0pt,
right skip=0pt,
#1
}
\renewcommand{\columnseprule}{2pt}
\newcommand{\typeABinline}[2]{%
\item #1 \\
\begin{tcbraster}[nobeforeafter,raster halign=center,raster columns=3,raster equal height group, raster column skip=0pt]
\begin{answertextbox}[raster multicolumn=1,fontupper={\bfseries}]
Answer:
\end{answertextbox}
\begin{InlineAnswerBox}[raster multicolumn=2,fontupper={\bfseries}] % Use 2 fake columns!!
#2
\end{InlineAnswerBox}
\end{tcbraster}
}
\begin{document}
\begin{multicols}{2}
\begin{enumerate}[resume,label=\textbf{\arabic*.}]
\typeABinline{Question text blah blah} {pe}
\typeABinline{Question text blah blah} {asd}
\typeABinline{Question text blah blah} {g}
\typeABinline{Question text blah blah} {ka}
\end{enumerate}
\end{multicols}
\end{document}
\documentclass[a4paper,10pt]{article}
\usepackage{calc}
\usepackage{multicol}
\usepackage{enumitem}
\usepackage[most]{tcolorbox}
\newlength{\AnswerLength}
\settowidth{\AnswerLength}{\textbf{Answer:~\null}}
\newcommand{\GrayColor}{gray!30}
\makeatletter
\newtcolorbox{InlineAnswerBox}[1][]{%
%top=0mm,
%bottom=0mm,
%left=0mm,
%right=0mm,
valign=center,
halign=center,
box align=center,
baseline={\the\dimexpr\tcb@height/2-\kvtcb@top@rule\relax},
width=\dimexpr\linewidth-\AnswerLength-\labelwidth-\labelsep\relax,
% capture=fitbox,
%arc=0pt,
%outer arc=0pt,
nobeforeafter,
boxsep=5pt,
%boxrule=0.0pt,
%colback=\GrayColor,
%colframe=white,
#1,
}
\makeatother
\newcommand{\InlineAnswer}[2][]{%
\begin{InlineAnswerBox}[#1]
#2
\end{InlineAnswerBox}%
}
\newcommand{\typeABinline}[2]{%
\item #1 \\
\textbf{Answer:} \InlineAnswer{\textbf{#2}}
}
\begin{document}
\begin{multicols}{2}
\begin{enumerate}[resume,label=\textbf{\arabic*.}]
\typeABinline{Question text blah blah} {pe}
\typeABinline{Question text blah blah} {asd}
\typeABinline{Question text blah blah} {g}
\typeABinline{Question text blah blah} {ka}
\end{enumerate}
\end{multicols}
\end{document}
Another solution would be to shrink the box to give room for the Anwer: text and to insert this text using a \makebox
:
\documentclass[a4paper,10pt]{article}
\usepackage{calc}
\usepackage{multicol}
\usepackage{enumitem}
\usepackage[most]{tcolorbox}
\newcommand{\typeABinline}[2]{%
\item #1\\
\setbox0=\hbox{\textbf{Answer: }}%
\begin{tcolorbox}[nobeforeafter,left skip=\wd0]
\makebox[0mm][r]{\box0\hspace{5.5mm}}\strut\textbf{#2}
\end{tcolorbox}%
}
\begin{document}
\begin{multicols}{2}
\begin{enumerate}[resume,label=\textbf{\arabic*.}]
\typeABinline{Question text blah blah} {pe}
\typeABinline{Question text blah blah} {asd}
\typeABinline{Question text blah blah} {g}
\typeABinline{Question text blah blah} {ka}
\typeABinline{Question text blah blah} {ka xx xx xx xx xx xx xx xx xx}
\end{enumerate}
\end{multicols}
\end{document}
This gives: