当文本切换到新行时,如何打破“在线”tcolorbox?

当文本切换到新行时,如何打破“在线”tcolorbox?

如果我将其tcolorbox用作荧光笔,则如何在切换到新行时打破该框:

\documentclass[11pt]{article}
\usepackage[dvipsnames]{xcolor}
\usepackage[most]{tcolorbox}

\newtcbox{\hlbox}[1][cyan]{enhanced jigsaw,on line, arc=0pt,outer arc=0pt,colback=#1!10!white,colframe=#1!80!black, boxsep=0pt,left=3pt,right=3pt,top=2pt,bottom=2pt, boxrule=0pt,bottomrule=1pt,toprule=1pt,breakable}

\begin{document}
The Canton System was a trade policy implemented by the Qing Dynasty in the 18th and 19th centuries that \hlbox[LimeGreen]{restricted foreign trade to the port of Canton (now Guangzhou) in southern China}.
\end{document}

在此处输入图片描述

答案1

我刚刚收到一个很棒的解决方案穆兹穆奇来自 Github。

我们可以将soulpos包与一起使用\tcbox

\documentclass{article}
\usepackage{lipsum}
\usepackage{multicol}
\usepackage{soulpos}
\usepackage{tcolorbox}

\colorlet{ul}{red}
\newtcbox{\mybox}{
  on line,
  arc=0pt, outer arc=0pt,
  colback=ul!10!white, colframe=ul!50!black,
  boxsep=0pt, left=1pt, right=1pt, top=2pt, bottom=1pt,
  boxrule=0pt, bottomrule=1pt, toprule=1pt
}

\makeatletter
\newcommand\myul[1][red]{%
  \UseName{str_if_eq:nnF}{#1}{red}{\colorlet{ul}{#1}}
  \myul@}

\ulposdef\myul@[xoffset-start=1pt]{%
  \mybox{\vphantom{AHpgjy}\rule{\ulwidth}{0pt}}}
\makeatother

\begin{document}
\begin{multicols}{2}
  Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
  eiusmod tempor incididunt ut labore et dolore magna aliqua.
  \newcolumn
  
  Lorem ipsum dolor sit amet, consectetur \myul{adipiscing elit, sed do
  eiusmod tempor} incididunt ut labore et dolore
  \myul[green]{magna aliqua.}
\end{multicols}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc facilisis vitae massa nec cursus. Fusce faucibus gravida dolor. Cras egestas eget nulla ut consequat. Nulla eu mi at mauris feugiat ornare. Etiam a efficitur sem, et scelerisque massa. Sed ipsum justo, posuere vitae leo vitae, fermentum dictum lacus. Morbi et ipsum vel neque congue elementum. In dolor orci, hendrerit vitae sagittis sit amet, pellentesque a magna.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc facilisis vitae massa nec cursus. Fusce faucibus gravida dolor. Cras egestas eget nulla ut consequat. Nulla eu mi at mauris feugiat ornare. \myul[orange]{Etiam a efficitur sem, et scelerisque massa. Sed ipsum justo, posuere vitae leo vitae, fermentum dictum lacus.} Morbi et ipsum vel neque congue elementum. In dolor orci, hendrerit vitae sagittis sit amet, pellentesque a magna.
\end{document}

生成结果: 在此处输入图片描述

参考 Github这里

相关内容