TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I convinced my girlfriend to write her thesis with Latex, so now whenever she gets stuck I'm the go to guy. Sadly she has requested something of me which I don't know either. She needs a table in which some of the cells are colored as it can be seen in the following image.enter image description here

I created this using paint, but obviously I would rather use a correct way of doing it. I found both examples of how to get the diagonal lines into a cell and how to get colored cells, but I haven't been able to combine the two.

Does anyone know a solution to this? The other alternative I thought of would be to create the table using latex, convert to pdf, load it into inkscape, add the lines and the colors and include it as a figure again. This would mean that I need to redo it every time the table changes though. I'm hoping this can be done in a more elegant way!

share|improve this question
Welcome to TeX.SE. It would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem. While solving problems is fun, setting them up is not. Then those trying to help can simply cut/paste your MWE and get started on solving problem. In this case it is fairly simple, but if you can save those trying to help sometime that would be nice. – Peter Grill Oct 9 '12 at 21:14
Well there is always the tikz overkill solution... but perhaps others will come up with a simpler solution. – Peter Grill Oct 9 '12 at 21:17
Aaah, sorry for that. I had just finished my MWE when I saw the two answers. I will know this for the next time. Thank you for the valuable hint! – Pandoro Oct 9 '12 at 21:44
up vote 9 down vote accepted

Here's a solution using matrix of nodes from TikZ:






    \matrix (magic) [matrix of nodes,nodes={minimum width=3cm,minimum height=1cm,draw,very thin},draw,inner sep=0]
    {   8 & 1 & 6 \\
        3 & |[limon]| 5 & |[limon]| 7 \\
        4 & 9 & 2 \\
        \fill[lime,draw=black] (magic-2-1.north east) -- (magic-2-1.west) -- (magic-2-1.south east) -- cycle;




enter image description here

share|improve this answer
Thank you a lot! That looks great :D – Pandoro Oct 9 '12 at 21:45
You're welcome. I don't know how familiar you are with TikZ, so don't hesitate to ask if anything is unclear. – Tom Bombadil Oct 9 '12 at 21:49

Here's one of the the overkill TikZ solutions mentioned by Peter Grill. I used a modification of this solution to Gradient color in one cell of a table.



% Andrew Stacey's code from
% http://tex.stackexchange.com/a/50054/3954
  remember picture with id/.style={%
    remember picture,
    save picture id=#1,
  save picture id/.code={%
  if picture id/.code args={#1#2#3}{%

  \expandafter\gdef\csname save@pt@#1\endcsname{#2}%


  \pgfsys@getposition{\csname save@pt@\tmk@label\endcsname}\save@orig@pic%
  \advance\pgf@x by -\pgf@xa
  \advance\pgf@y by -\pgf@ya


\tikz[remember picture with id=#2] {#1;}}

  \begin{tikzpicture}[overlay,remember picture]%
    \fill[mycolor] ( $ (pic cs:#1) + (0pt,0.5ex) $ ) --  ( $ (pic cs:#2) + (0pt,1.9ex) $ ) -- ( $ (pic cs:#2) + (0pt,-0.8ex) $ ) --cycle ;


some text & some text & some text & some text \\
\multicolumn{1}{!{\vrule\tikzmark{start1}} c !{\vrule\tikzmark{end1}}}{some text} & \cellcolor{mycolor}some text & \cellcolor{mycolor}some text & \cellcolor{mycolor}some text \\
some text & some text & some text & some text \\


enter image description here

share|improve this answer
Thank you :) I would accept both answers if I could, but I like the other one just a bit more since it seems simpler to me. Thank you for the effort though :) – Pandoro Oct 9 '12 at 21:46
@Pandoro You're welcome! No problem about accepting the other answer; I agree that it might be simpler if you're not interested in preserving the settings from a standard tabular. – Gonzalo Medina Oct 9 '12 at 21:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.