1

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: enter image description here

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

  1. use xelatex
  2. background notes are located in the tabularray environment
  3. the background fields should be as little as possible, so the background of two lines shouldn't be connected
  4. 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}

enter image description here

Y. zeng
  • 1,885

1 Answers1

1

@egreg's solution in linked question works with xelatex:

Note

MWE

\documentclass[a4paper]{article} 
\usepackage{tabularray,xcolor,tabularx} 
\usepackage{soul}

\newcommand{\ctext}[3][RGB]{% \begingroup \definecolor{hlcolor}{#1}{#2}\sethlcolor{hlcolor}% \hl{#3}% \endgroup } \begin{document} \begin{table} \begin{talltblr}[ caption={test}, label={tab:test}, remark{Note}={\ctext[RGB]{240,212,212}{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}


Added

Works with lualatex and lua-ul:

note2

MWE

\documentclass[a4paper]{article} 
\usepackage{tabularray,xcolor,ctex} 
%\usepackage{soul}
\usepackage{luacolor,lua-ul}
\UseTblrLibrary{booktabs, siunitx}

\newcommand{\ctext}[3][RGB]{% \begingroup \definecolor{hlcolor}{#1}{#2}\LuaULSetHighLightColor{hlcolor}% \highLight{#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}


Addendum 2

How about:

minipage

The data goes into a table-wide minipage, and the minipage is inside a colorbox (so, 1 item, no need for linebreaks).

MWE

\documentclass[a4paper]{article} 
\usepackage{tabularray,xcolor,ctex} 
%\usepackage{soul}
%\usepackage{luacolor,lua-ul}
\UseTblrLibrary{booktabs, siunitx}

%\newcommand{\ctext}[3][RGB]{% % \begingroup % \definecolor{hlcolor}{#1}{#2}\LuaULSetHighLightColor{hlcolor}% % \highLight{#3}% % \endgroup %} \definecolor{lightb}{RGB}{217,224,250}

\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。}}, remark{Note2}={The data \colorbox{lightb}{ \begin{minipage}{\linewidth} 测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test。 \end{minipage} }},
]{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}


Addendum the last

Interaction of tcolorbox and tabularray produces a spurious [0] from somewhere, so probably we are close to code-design limits:

tcb

MWE

\documentclass[a4paper]{article} 
\usepackage{tabularray,xcolor,ctex} 
%\usepackage{soul}
%\usepackage{luacolor,lua-ul}
\UseTblrLibrary{booktabs, siunitx}
\usepackage{tcolorbox}

%\newcommand{\ctext}[3][RGB]{% % \begingroup % \definecolor{hlcolor}{#1}{#2}\LuaULSetHighLightColor{hlcolor}% % \highLight{#3}% % \endgroup %} \definecolor{lightb}{RGB}{217,224,250}

\begin{document} \begin{table}[p] \vspace{-0.4cm} \begin{talltblr}[ caption={1}, label={tab:1}, remark{Note3}={The data, using tcolorbox: \begin{tcolorbox}[width=0.85\linewidth,colback=yellow!30] 测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test,测试,test。 \end{tcolorbox} },
]{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}

Cicada
  • 10,129
  • Thanks for your reply. Your code can run successfully. But, weird, my table can't. Could you take the time to see the questions I updated? I find the @egreg's answers sometimes work, sometimes not. – Y. zeng Sep 05 '22 at 07:57
  • @Y.zeng well you added chinese in the highlighting and that complicates it a lot. Surround all chinese with boxes: \mbox{测试,}, alternatively use lualatex and the lua-ul package for highlighting. – Ulrike Fischer Sep 05 '22 at 08:44
  • @Y.zeng I have updated answer with lua-ul. – Cicada Sep 05 '22 at 10:36
  • Hello. \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
  • Put each character or word into a box, or use \parbox or minipage environment (both can do line breaks), or use 1-cell tabular for each item. Or TikZ solution. Or import as a pdf. etc. Q: ctex calls luatexja under lualatex rather than re-invent the wheel. What prevents usage of lualatex? – Cicada Sep 05 '22 at 13:29
  • @Y.zeng I have updated answer with minipage solution. Unrelated: a tcolorbox will work better here, I think: linebreaks + background colour. – Cicada Sep 05 '22 at 14:28
  • @Cicada I am too busy for two months. I hope I am not too late to reply to you. Thanks for you reply. I try to surround all Chinese with boxes: \mbox{测试}, but when Chinese are mixed with English, you will see the height of background of Chinese and English are different if you use xelatex. If use minipage in colorbox, how to align the box with the top of the text before? If use lulatex, the error is "message": "TeX capacity exceeded, sorry [token memory size=8504848].\n ... {\str_if_eq:VnF \l__mhchem_cf_subState_tl {-}{\n", "source": "LaTeX" – Y. zeng Nov 06 '22 at 11:37
  • Ask separate questions, 1 question per question with MWE, linking back here. To make box height the same, you can use zero-width y-height \vrule so 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