使用 tcolorbox,如何创建一个可变长度的框以紧密贴合段落标题?

使用 tcolorbox,如何创建一个可变长度的框以紧密贴合段落标题?
%
\documentclass[english,11pt]{book}
\usepackage[fleqn]{amsmath} %
\usepackage{amsthm} %
\usepackage{amssymb} 
\usepackage[explicit]{titlesec}
\usepackage{titletoc} %
\usepackage[skins,theorems,most]{tcolorbox} %

\newtcolorbox{parabox}{
boxsep=0pt,
boxrule=0.7pt,
width=\textwidth, % to vary with length of text
right=2pt,
colframe=black,
colback=yellow}

\titleformat{\paragraph}{}{}{0pt} %
{\begin{parabox}
{#1} %
\end{parabox}}

\renewcommand{\theparagraph}{[\hspace{0.9pt}\roman{paragraph}\hspace{1.0pt}]} %
\titlespacing{name=\paragraph}{4pt}{2pt}{0pt}[0pt] % from left, before (vert), after (vert), [0pt]

\begin{document}

\paragraph{The box to be of variable length and stop here {\color{red}$|||$}}

\vspace{-6pt}
\noindent A full length line of ordinary text - extended to the full width of the page $>$

\end{document}

答案1

使用

\newtcolorbox{parabox}{
    hbox, % added <<<<<<<<<<<<<<<<<<<<<<<<<
    boxsep=0pt,
    boxrule=0.7pt,
    width=\textwidth, % to vary with length of text
    right=2pt,
    colframe=black,
    colback=yellow}

A

相关内容