Watermark for table row
Using Tikz, you can define the \NEWROW
command as follows:
\newcommand{\NEWROW}{%
\noalign{%
\dimen0=\dimexpr\prevdepth+\ht\strutbox\relax%
\begin{tikzpicture}[remember picture, overlay]%
\pgfsetfillopacity{0.5}
\node[draw,minimum height=\the\dimen0, minimum width=3cm+2\tabcolsep, rectangle, anchor=south west, color=red] at (-2.5\tabcolsep,0) {NEW};
\end{tikzpicture}%
}%
}
The height seams to be a little bit off on the lower rows. I just took the code from @egreg, I didn't know how to get the rowheight. The draw is on the node to show the box it creates so you can see the difference with the actual height. The example would look like this:
Edit: Obviously the difference in the single row column is due to the fact that I used caps in the watermark text, which are higher than the row dimensions. As long as you don't use a watermark that doesn't fit in the row, you will be fine.
Update: To rotate the text is not completely trivial. I don't know of any way to rotate just the text and not the accompanying box. If you turn off the draw
option it won't show the box anymore (you probably don't want that anyway) so then you would say it's not a problem, we can just rotate by adding rotate=x
to the options. This is a problem though, since this kind of rotation uses the anchor to rotate around. In our case this means the box is rotated around the bottom left corner, which means that the text will move away from the center. For this, TikZ
has the rotate around
option which takes an argument like {angle:(x,y)}
and rotates the node angle
degrees around (x,y)
. Unfortunately, this means we have to calculate the center and use that, this is not very hard though.
Alternatively, we could draw two nodes, one with an empty text and one with just the text in it, but not the same size (we have to calculate the placement of course, again not extremely difficult). The only real advantage this has is that it allows you to keep the box! Again, you probably don't care about the box :)
(if you don't care about the box, use the first option, less nodes=more better!). The two methods are demonstrated in the following \NEWROW
command, take your pick:
\newcommand{\NEWROW}{%
\noalign{%
\dimen0=\dimexpr\prevdepth+\ht\strutbox\relax%
\begin{tikzpicture}[remember picture, overlay]%
\pgfsetfillopacity{0.5}
\pgfmathsetlengthmacro{\mydim}{(3cm+2\tabcolsep)/2}
\pgfmathsetlengthmacro{\myht}{height("NEW")/2}
\node[minimum height=\the\dimen0, minimum width=3cm+2\tabcolsep, rectangle, anchor=south west, color=blue, rotate around={10:(\mydim-2.5\tabcolsep,.5*\the\dimen0+\myht)}] (a) at (-2.5\tabcolsep,0) {NEW};
\node[minimum height=\the\dimen0, rectangle, anchor=center, color=red, rotate=10] at (\mydim-2.5\tabcolsep,.5*\the\dimen0+\myht) {NEW};
\end{tikzpicture}%
}%
}
The placement of the text isn't completely equivalent, I suspect there is an inner sep
running foul somewhere, or I have just made a mistake in the calculations... Regardless, it's close as makes no difference.
You can use the old trusted picture environment to position the text behind the row.
\documentclass{article}
\usepackage{xcolor}
\newcommand{\NEWROW}{%
\noalign{\dimen0=\dimexpr\prevdepth+\ht\strutbox\relax
\vbox to 0pt{\vskip-.5\dimen0
\llap{\smash{$\vcenter{\hbox{\Huge NEW}}$}}\vss}}}
\def\watermark#1{%
\setlength{\unitlength}{1pt}
\begin{picture}(0,0)
\put(50,-35){\textcolor{red!50!white}{\Huge #1}}
\end{picture} }
\begin{document}
\begin{tabular}{p{3cm}p{3cm}l}
\watermark{Revised}
abc def abc def abc def abc def abc def abc def abc def
abc def abc def abc def abc def abc def abc def abc def
&
abc def abc def abc def abc def abc def abc def abc def
abc def abc def abc def abc def abc def abc def abc def
& x\\
\hline
abc def abc def abc def abc def abc def abc def abc def
&
abc def abc def abc def abc def abc def abc def abc def
& x\\
\hline
abc def abc def
&
abc def abc def
& x\\
\hline
abc def abc def abc def abc def abc def abc def abc def
&
abc def abc def abc def abc def abc def abc def abc def
& x
\end{tabular}
\end{document}
How to position the text exactly in the middle and center of the row can be automated, but I am not sure if it is worth the trouble. I am also not sure, if it looks right though; I tend to agree with @egreg that at the margin it may look better, especially with a right pointing arrow or small graphic.
It will look better if the background text is rotated a bit. For this you can use the rotatebox
from the graphicx package
Just include the package and change the code as follows:
\rotatebox[origin=c]{15}{\watermark{Revised}}
TeX doesn't know the width of a table until it has ended processing it. It's possible to put a watermark in the left margin of a tabular row:
\newcommand{\NEWROW}{%
\noalign{\dimen0=\dimexpr\prevdepth+\ht\strutbox\relax
\vbox to 0pt{\vskip-.5\dimen0
\llap{\smash{$\vcenter{\hbox{\Huge NEW}}$}}\vss}}}
\begin{document}
\begin{tabular}{p{3cm}p{3cm}l}
abc def abc def abc def abc def abc def abc def abc def
abc def abc def abc def abc def abc def abc def abc def
&
abc def abc def abc def abc def abc def abc def abc def
abc def abc def abc def abc def abc def abc def abc def
& x\\
\NEWROW
\hline
abc def abc def abc def abc def abc def abc def abc def
&
abc def abc def abc def abc def abc def abc def abc def
& x\\
\NEWROW
\hline
abc def abc def
&
abc def abc def
& x\\
\NEWROW
\hline
abc def abc def abc def abc def abc def abc def abc def
&
abc def abc def abc def abc def abc def abc def abc def
& x
\end{tabular}
By changing \llap{
to \hbox to 4cm{\hss
the word "NEW" will be printed over the row, but horizontal centering is quite difficult to achieve.
Notice that \NEWROW
must go after the \\
terminating the row.
If the width is known in advance, for instance the tabular is
\begin{tabular}{*{4}{p{3cm}}}
then you can define
\newcommand{\NEWROW}{%
\noalign{\dimen0=\dimexpr\prevdepth+\ht\strutbox\relax
\vbox to 0pt{\vskip-.5\dimen0
\hbox to\dimexpr 12cm+8\tabcolsep{%
\hss\smash{$\vcenter{\hbox{\Huge NEW}}$}\hss}\vss}}}
since 12cm+8\tabcolsep
is the table width. Of course \hbox{\Huge NEW}
can be changed into something more sensible, say a word in grey color.