1

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

6

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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