As I write the article that contains Chinese characters, so I need to use xelatex engine, even lualatex engine sometimes will not work. I also insert some tables by tabularray package which has a lot of functions. The notes after the table will often be inserted. When I try to insert the notes after the table I find that the background of the note can't be broken:

\documentclass[a4paper]{article}
\usepackage{tabularray,xcolor,tabularx}
\begin{document}
\begin{table}
\begin{talltblr}[
caption={test},
label={tab:test},
remark{Note}={\colorbox{gray9}{notestest, notestest, notestest, notestest, notestest, notestest, notestest, notestest, notestest, notestest, notestest, notestest, notestest, notestest, notestest, notestest, notestest, notestest, notestest, notestest, }}
]{colspec={X[c] X[c] X[c]}
}
& 2 & 2& 3\
\end{talltblr}
\end{table}
\end{document}
I tried to find ways to solve this problem as in the site. However, if it need to satisfy several conditions, I can't find the right way:
- use xelatex
- background notes are located in the tabularray environment
- the background fields should be as little as possible, so the background of two lines shouldn't be connected
- the space between the start of the background and the start of the text of the background should be deleted
What should I do to meet these four conditions?
As someone say that the answers of @egreg is useful, I test my table and find it can't. What cause the problem?
\documentclass[a4paper]{article}
\usepackage{tabularray,xcolor,tabularx,ctex}
\usepackage{soul}
\UseTblrLibrary{booktabs, siunitx}
\newcommand{\ctext}[3][RGB]{%
\begingroup
\definecolor{hlcolor}{#1}{#2}\sethlcolor{hlcolor}%
\hl{#3}%
\endgroup
}
\begin{document}
\begin{table}[p]
\vspace{-0.4cm}
\begin{talltblr}[
caption={1},
label={tab:1},
remark{Note}={The data\ctext[RGB]{240,212,212}{测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test。}}
]{colspec={X[r,3em] X[c,3em] *{7}{X[c,si={table-format={2,2}}]}}
}
\toprule
& 年 & \SetCell[c=4]{c}{{{\makebox[13em][s]{t e s t}}}} & & & & \SetCell[c=3]{c}{{{\makebox[8.5em][s]{T E s t}}}} & 2021 & 2021 \
\bottomrule
\end{talltblr}
\end{table}
\end{document}





\mbox{测试,}, alternatively use lualatex and the lua-ul package for highlighting. – Ulrike Fischer Sep 05 '22 at 08:44\ctext[RGB]{240,212,212}{测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test。}This code can't be surrounded by boxes. Am I right? So, the only way is to use lualatex? – Y. zeng Sep 05 '22 at 12:53\parboxorminipageenvironment (both can do line breaks), or use 1-celltabularfor each item. Or TikZ solution. Or import as a pdf. etc. Q:ctexcallsluatexjaunder lualatex rather than re-invent the wheel. What prevents usage of lualatex? – Cicada Sep 05 '22 at 13:29tcolorboxwill work better here, I think: linebreaks + background colour. – Cicada Sep 05 '22 at 14:28\mbox{测试}, but when Chinese are mixed with English, you will see the height of background of Chinese and English are different if you usexelatex. If useminipageincolorbox, how to align the box with the top of the text before? If uselulatex, the error is "message": "TeX capacity exceeded, sorry [token memory size=8504848].\n\vruleso it is invisible but makes the box taller, or use\strut, or set height with\parbox(link). For vertical alignment, need an example MWE to look at. For error message, infinite loop usually indicates logic error or typing error - again, need (small) example code that produces the issue. – Cicada Nov 06 '22 at 11:58