Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I used the following code to draw a picture. I want to make the region insde (0,7), (0,11),(3,8),(3,4) to be red, and the region above it to be gray, but I don't know how to do this.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[scale=0.5]

\draw (1.05cm,2pt) node[above];
 %  {$\displaystyle\int_0^{3/2} \!\!x^2\mathrm{d}x$};

\draw[style=help lines] (0,0) grid (3.9,11.9);
  % [step=0.25cm]      (1,2) grid +(1,1);

\draw[->] (-1,0) -- (4,0) node[right] {$i$};
\draw[->] (0,-1) -- (0,12) node[above] {$j$};

\foreach \x/\xtext in {1/1, 2/2, 3/3}
\draw[shift={(\x,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {$\xtext$};

\foreach \y/\ytext in {1/, 2/, 3/,4/,5/,6/,7/7,8/, 9/, 10/, 11/11}
\draw[shift={(0,\y)}] (2pt,0pt) -- (-2pt,0pt) node[left] {$\ytext$};

\draw  {(0,11) -- (3,8)} node[below right] ;
\draw  {(0,7) -- (3,4)} node[below right] ;
\draw  {(3,8) -- (3,4)} node[below right] ;
\end{tikzpicture}

\end{document}

enter image description here

share|improve this question
2  
dublicate: tex.stackexchange.com/questions/17300/how-to-color-a-region even though the solution is above the complexity level, it is of good value –  zeroth Feb 4 '12 at 15:43
add comment

1 Answer

up vote 5 down vote accepted

For the red shape you could try this. I am not sure what you mean by "above" in this case.

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

\begin{tikzpicture}[scale=0.5]

\draw (1.05cm,2pt) node[above]{};
 %  {$\displaystyle\int_0^{3/2} \!\!x^2\mathrm{d}x$};

\draw[style=help lines] (0,0) grid (3.9,11.9);
  % [step=0.25cm]      (1,2) grid +(1,1);

\draw[->] (-1,0) -- (4,0) node[right] {$i$};
\draw[->] (0,-1) -- (0,12) node[above] {$j$};

\foreach \x/\xtext in {1/1, 2/2, 3/3}
\draw[shift={(\x,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {$\xtext$};

\foreach \y/\ytext in {1/, 2/, 3/,4/,5/,6/,7/7,8/, 9/, 10/, 11/11}
\draw[shift={(0,\y)}] (2pt,0pt) -- (-2pt,0pt) node[left] {$\ytext$};

\draw[fill=red]  (0,11) -- (3,8) -- (3,4) -- (0,7) -- cycle;
\fill[gray!20,nearly transparent] (0,11) -- (0,12) -- (3,12) -- (3,8) -- cycle;
% \fill[gray!20] (0,11) -- (0,12) -- (3,12) -- (3,8) -- cycle; %without transparency
\end{tikzpicture}

\end{document}

red

Instead of nearly transparent you use the opacity key, for example opacity=0.3. See pgfmanual Ch. 20.2 for more details.

share|improve this answer
add comment

Your Answer

 
discard

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.