5

I want to shade an area of of picture I have created in the environment \picture. Is there anyway I can shade this by setting it between co-ordinates? i.e. could I shade in blue the area between (1,1), (1,4), (3,1), (3,4) etc?

3 Answers 3

10

You mean colored rectangular boxes, something like the following?

\documentclass{article}
\usepackage{xcolor}

\begin{document}
\setlength{\unitlength}{1cm}
\fbox{%
  \begin{picture}(5,5)(0,0)
    \put(1,1){\textcolor{blue}{\rule{2\unitlength}{3\unitlength}}}
  \end{picture}%
}
\end{document}

Result

6

It seems to me---from all the talk on this page---that people seem to prefer tikZ. I'm not all that familiar with that package, so I'll let someone else give a tikZ solution.

But, if you're using a picture environment, then rewriting your code to work with pstricks shouldn't be so hard.

If you're using pstricks, you could create a custom environment

\pscustom[linewidth=0.2pt,fillstyle=solid,fillcolor=blue]{
    \pspolygon(1,1)(1,4)(3,1)(3,4)
}

Here's a fuller example

\documentclass{article}
\usepackage{pstricks}
\psset{unit=0.5cm}
\begin{document}

Based upon the order of your coordinates \vspace{\baselineskip}

\begin{pspicture}(4,4)
    \pscustom[linewidth=0.2pt,fillstyle=solid,fillcolor=blue]{
        \pspolygon(1,1)(1,4)(3,1)(3,4)
    }
\end{pspicture}

But perhaps you meant, \vspace{\baselineskip}

\begin{pspicture}(4,4)
    \pscustom[linewidth=2pt,fillstyle=solid,fillcolor=gray]{
        \pspolygon(1,1)(1,4)(3,4)(3,1)
    }
\end{pspicture}


\end{document}

enter image description here

5

For what it's worth, here's a solution that uses tikz together with the picture environment:

\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\tikzstyle{every picture}+=[remember picture]
\setlength{\unitlength}{0.5cm}

\begin{document}
If you just want a rectangle, \vspace{\baselineskip}

\begin{picture}(4,4)(0,0)
    \put(1,1){\tikz \coordinate (botleft);}
    \put(3,4){\tikz \coordinate (topright);}
    \put(0,0){\tikz[overlay] \fill[blue] (botleft) rectangle (topright);}
\end{picture}

Based upon the order of your coordinates \vspace{\baselineskip}

\begin{picture}(4,4)(0,0)
    \put(1,1){\tikz \coordinate (point1);}
    \put(1,4){\tikz \coordinate (point2);}
    \put(3,1){\tikz \coordinate (point3);}
    \put(3,4){\tikz \coordinate (point4);}
    \put(0,0){\tikz[overlay] \fill[blue] (point1) -- (point2)%
             -- (point3) -- (point4) -- cycle;}
\end{picture}

But perhaps you meant, \vspace{\baselineskip}

\begin{picture}(4,4)(0,0)
    \put(1,1){\tikz \coordinate (point5);}
    \put(1,4){\tikz \coordinate (point6);}
    \put(3,1){\tikz \coordinate (point8);}
    \put(3,4){\tikz \coordinate (point7);}
    \put(0,0){\tikz[overlay] \fill[blue] (point5) -- (point6)%
             -- (point7) -- (point8) -- cycle;}
\end{picture}


\end{document}

You may have to run it twice to get it to turn out right. Here's what you get when you do:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .