# highlight several successive paragraphs, including tables

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.

• \color would colour tabular that are in the text flow. The whole point of the table environment is to mark that environment as a floating insert that is not in the text flow, so it does not pick up the current colour or font etc. – David Carlisle Mar 1 '16 at 22:15

If you really need this you can do

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

• Amazing, how do you come up with these! As for the semantics, we're using this to mark "technical" sections of a document as we edit. These tech sxns will (or will not) be shown in the final doc, depending on who the audience is, but the authors wanted a way to track this in the PDF. Since tables can be part of the "technical" sections, it seems entirely appropriate to color them as well as the rest of the text in the tech sxns. – Mike Maxwell Mar 1 '16 at 23:14
• @MikeMaxwell I did write the color package;-) – David Carlisle Mar 1 '16 at 23:14
• But that explains only part of it. I tried to figure out how the table environment (and also the figure env) was turning off the font color, but I couldn't. Now that I know it uses \default@color, I can at least find it in the color package, but I'm still not clear where tables use that. Anyway, thanks! – Mike Maxwell Mar 1 '16 at 23:32
• @MikeMaxwell yes well that's my code as well (most of the work in adding colour support was making the commands in the format aware of such things, rather than the colour package itself:-) the float is saved with \global \setbox\@currbox \color@vbox \normalcolor and \normalcolor just sets \default@color. Fonts are similarly reset \reset@font \normalsize so that a float in an italic or bold section does not inherit those properties. – David Carlisle Mar 1 '16 at 23:40