2

I want to create a table with the long text content. Each word in the text is color boxed. But when this is done, the text does not wrap and there is no line break. Below is sample code:

\begin{table}[h!]
\begin{tabular}{|c|c|}
    1 & {\colorbox[HTML]{f6faff}{this}\colorbox[HTML]{f5f9fe}{is}\colorbox[HTML]{e8f1fa}{an}\colorbox[HTML]{08306b}{apple}\colorbox[HTML]{bad6eb}{that}\colorbox[HTML]{bad6eb}{fell}\colorbox[HTML]{f0f6fd}{from}\colorbox[HTML]{f6faff}{should}\colorbox[HTML]{f6faff}{tree}\colorbox[HTML]{f4f9fe}{and}\colorbox[HTML]{5fa6d1}{broke}\colorbox[HTML]{d5e5f4}{which}\colorbox[HTML]{57a0ce}{made}\colorbox[HTML]{d6e5f4}{me}\colorbox[HTML]{c4daee}{very}\colorbox[HTML]{c4daef}{badly}\colorbox[HTML]{c4daee}{sad}}
\end{tabular}
\end{table}

I tried the solution given here, but that did not work.

Any suggestions on resolving this issue would be much appreciated. Thank you.

Foshiba
  • 123

1 Answers1

1

A column of type c is never broken. You should use a column of type p{...}.

Moreover, you should add spaces between the \colorbox.

\documentclass{article}

\usepackage{array} \usepackage{xcolor}

\begin{document} \begin{table}[h!] \begin{tabular}{|c|p{6cm}|} 1 & { \colorbox[HTML]{f6faff}{this} \colorbox[HTML]{f5f9fe}{is} \colorbox[HTML]{e8f1fa}{an} \colorbox[HTML]{08306b}{apple} \colorbox[HTML]{bad6eb}{that} \colorbox[HTML]{bad6eb}{fell} \colorbox[HTML]{f0f6fd}{from} \colorbox[HTML]{f6faff}{should} \colorbox[HTML]{f6faff}{tree} \colorbox[HTML]{f4f9fe}{and} \colorbox[HTML]{5fa6d1}{broke} \colorbox[HTML]{d5e5f4}{which} \colorbox[HTML]{57a0ce}{made} \colorbox[HTML]{d6e5f4}{me} \colorbox[HTML]{c4daee}{very} \colorbox[HTML]{c4daef}{badly} \colorbox[HTML]{c4daee}{sad}} \end{tabular} \end{table} \end{document}

Output of the above code

F. Pantigny
  • 40,250
  • or if you don't like visible spaces between the boxes you can add an explicit penalty there so that breaking is allowed, e.g. \colobox{...}\allowbreak\colorbox{...} – Frank Mittelbach Apr 20 '21 at 07:13