I'm trying to create a tabular
and I'm facing the following small issue.
I would like to make the background of one cell a gradient color. Is it easy to do that in LaTeX? And if so, how to do it?
colortables
I'm trying to create a tabular
and I'm facing the following small issue.
I would like to make the background of one cell a gradient color. Is it easy to do that in LaTeX? And if so, how to do it?
Best Answer
Here's one option using the improved version of
\tikzmark
exposed by Andrew Stacey in his answer to tikzmark to have different behaviour if first run (and mark locations not yet available). The idea is to use\multicolumn
and the!{...}
syntax from thearray
package to place the marks at the beginning and at the end of the cell; then\shade
(from theTikZ
package) was used to place the shade.A little example showing some shading effects (one of them using the
shadings
library) when having various cells associated to the different column types (l
,c
,p{<length>}
and merged cells):A brief explanation on how to use the code
For each cell that will receive the shading you need to do the following:
Use
\multicolumn{<number of columns>}{<format specification>}{<text>}
specifying the second argument in the formwhere
<name1>
and<name2>
can be quite arbitrary strings not previously used; I suggest using something likestart<number>
,end<number>
, but you can use any other strings (valid for naming nodes in TikZ). If you need to add vertical rules to the cell, you must use\vrule
inside!{...}
; for example, to have vertical rules on both sides of the cell you can sayUse the
\ShadeCell
command in the following way:where
<name1>
and<name2>
are the strings you used in the previous step, and<shade specification>
is a valid shade according to TikZ syntax. If the contents of the cell spans more than one line (when using ap{<length>}
columns, for example), then you can use the optional argument of\ShadeCell
with the proper value to make the shade cover the cell vertically; for example; if the text of the cell spans 5 lines then you need to use something like(The optional argument is the number
n-1
, wheren
is the number of lines that the text spans).