# How to fill this region with color?

I have the following very simple graph:

\begin{center}
\begin{tikzpicture}
\draw[thick,->] (0,-1)--(0,1) node[anchor=south east] {};
\draw[thick,->] (-1,0)--(1,0) node[anchor=north west] {};
\draw (-2,-2)--(2,2) node[anchor=north west] {};
\draw (-2,2)--(2,-2) node[anchor=north west] {};
\end{tikzpicture}
\end{center}


This gives two cones on the x-y plane. How can I color these two regions?

• Please, can be more specific? Which two region you like to fill? I don't see any cone ... – Zarko Nov 3 '16 at 17:49
• Also please explain, what is purpose of empty nodes? – Zarko Nov 3 '16 at 17:51
• A complete compilable document would make it easier for people to help. meta.tex.stackexchange.com/questions/228/… – Thruston Nov 3 '16 at 18:18
• Do you mean something like \fill[red] (-2,-2) -- (0,0) -- (-2,2) -- cycle; ? – Thruston Nov 3 '16 at 18:23
• Sorry for not being more precise, I was in a hurry. The empty nodes are not needed. Also, the answer below is exactly what I need. Thanks a lot. – Marion Nov 3 '16 at 23:34

## 1 Answer

As Thruston says in the comments you can use the \fill command together with a closed path to colour a region. You can also use \draw[fill=<colour>] and many other tikz commands accept fill=... as an argument.

To add text to the picture you can use the \node command, which uses the syntax

\node at (x,y)[options]{text};


Alternatively, and almost equivalently, you can use:

\draw[draw options] (x,y) node[node options]{text};


For the various options for \node and \draw see the tikz manual.

It's not clear which regions you want to colour, so the following code does all of them:

\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\foreach \ang/\col in {0/red,1/green,2/blue,3/yellow} {
\fill[\col!20] (45+90*\ang:2.8)--(0,0)--(45+90*\ang+90:2.8)--cycle;
}
\draw[thick,->] (0,-1)--(0,1);
\draw[thick,->] (-1,0)--(1,0);
\draw (-2,-2)--(2,2);
\draw (-2,2)--(2,-2);
\node at (0,1.5)[blue]{Some nice text};
\end{tikzpicture}

\end{document}


Note that you want to colour the region first so that the colours are "underneath" the rest of your drawing. For more complicated drawings you might need the tikz backgrounds library.

The code above gives: • Thanks a lot for the answer. May I kindly ask how to include text, say, in the red region? – Marion Nov 3 '16 at 23:38
• The easiest way to add text is using the \node command. I'll add an example. – Andrew Nov 4 '16 at 1:19