[Tex/LaTex] highlight several successive paragraphs, including tables

colorhighlightingtables

I want to do s.t. which seems like it ought to be trivial, but I've tried for two days without success (much of the time trying methods I found here).

Conceptually, I want to highlight an arbitrarily long region of text. This may include multiple paragraphs, font changes, tables, and page breaks; and it may start at an arbitrary point on a page (so it's not necessarily entire pages). The highlight could take several forms, in descending order of preference:
1. Background color
2. Foreground (font, lines…) color
3. Change bars

I can get method (3) (= change bars) to work (using the changebar package), but I'd rather have (1) or (2), since those are more noticeable. Also, I'm using XeLaTeX, and that requires a specially munged version of changebar.sty.

I've tried to do method (1) (= background color) with the following packages (as suggested in various postings here at stackexchange):
– soul (error = "Reconstruction failed")
– highlight, mdframed, framed, tcolorbox (error = "Not in outer par mode")
– todonotes (error = "Paragraph ended before \reserved@a was complete")

Method (2) (foreground color) gets most of the way, but doesn't color tables (I'd have to repeat the \color{} command inside the table–since the latex is auto-converted from XML, that won't easily work). My minimal example (but without a page break) of this, is as follows (works with pdfLatex or xelatex):

\documentclass{report}
\usepackage[table]{xcolor}

\begin{document}
Some black text

{\color{red}

Some red text

\begin{table}[h]
 Text that ought\\
 to be red\\
\end{table}
More red text
}

More black text
\end{document}

But this fails to change the font color in the "table" (not much of a table, I know, but sufficient to show the problem). That is, the words in the table come out in black, not red.

Like I say, it seems like this should be easy. But.

Best Answer

If you really need this you can do

enter image description here

\documentclass{report}
\usepackage[table]{xcolor}

\begin{document}
Some black text

{\color{red}\makeatletter\let\default@color\current@color\makeatother

Some red text

\begin{table}[h]
 Text that ought\\
 to be red\\
\end{table}
More red text
}

More black text
\end{document}

Although this is semantically dubious, as a table environment is not part of the main text flow and is explictly designed not to inherit the current settings. A table that is part of the text flow should be encoded just as a tabular, not wrapped in table.