enter image description here

The following MWE yields the diagram above but I would like to find a better way of showing the shaded region.

        \draw[fill=black!20!white] (0,2)--(2,0)--(3,0)--(3,2)--cycle;
        \draw (0,0) --node[below] {$2x$}(2,0)--node[below] {$\vphantom{2}x$}(3,0)--(3,2)--(0,2)-- node[left] {$x-7$}cycle;

Note that the top left corner does not look pretty. Am thinking about clipping but seems a bit too much.


You can exploit the path picture key of the nodes:

    \draw[fill=black!20!white] (0,2)--(2,0)--(3,0)--(3,2)--cycle;
    \draw (0,0) --node[below] {$2x$}(2,0)--node[below] {$\vphantom{2}x$}(3,0)--(3,2)--(0,2)-- node[left] {$x-7$}cycle;

    \node[rectangle, minimum width=3cm, minimum height=2cm, inner sep=0pt, fill=white,draw, path picture={%
        \fill[black!20]($(path picture bounding box.south)!.35!(path picture bounding box.south east)$) coordinate(a)--
        (path picture bounding box.north west)--
        (path picture bounding box.north east)|-
        (path picture bounding box.south); % filling
        \draw (a)--(path picture bounding box.north west);% line
    }] (x) at (0,0){};
    \node[left=2pt] at (x.west){$x-7$};
    \node[below] at ($(x.south)!.35!(x.south west)$){$2x$};
    \node[below] at ($(x.south)!.65!(x.south east)$){$\vphantom{2}x$};

The result:

enter image description here

|improve this answer|||||
  • Quite interesting! Thought clipping was the only way although I didn't do it that way. – azetina Apr 25 '16 at 21:49
  • 1
    @azetina: of course, but clipping is too simple and not much esoteric ;) – Claudio Fiandrino Apr 25 '16 at 21:51

A PSTricks solution:


\psset{linejoin = 1}

  \pcline[linestyle = none, offset = #1](#2)(#3)

% parameters


  \pnodes{P}(0,0)(0,\height)(\width,\height)(\width,0)(!2 3 div \width\space mul 0)
    fillstyle = solid,
    fillcolor = gray!50
  \Label[15pt](P0)(P1){$x - 7$}



All you have to do is change the values of the parameters and the drawing will by adjusted accordingly.

|improve this answer|||||
  • 1
    But you have the same problem with the top left corner as the OP – JMP Apr 26 '16 at 20:47
  • @JMP Just corrected; I noticed it immediately after I posted my answer. (I missed \psset{linejoin = 1}.) – Svend Tveskæg Apr 26 '16 at 20:48

For comparison with Metapost and luamplib. Compile with lualatex.

enter image description here

u = 1mm;
x = 20u;

path box, shade;
box = unitsquare xscaled 3x yscaled 2x;
shade = subpath (2/3,3) of box -- cycle;

fill shade withcolor .8 white;
draw subpath (3,4) of shade;
draw box;

label.bot("$2x$",  point 1/3 of box);
label.bot("$x$",   point 5/6 of box);
label.lft("$x-7$", point 7/2 of box);



  • The built-in path unitsquare has four "points" corresponding to the the four corners and numbered clockwise from zero starting at the bottom left. Hence point 2/3 of box is 2/3 of the way along the bottom edge, and point 7/2 of box is halfway down the left hand edge.

  • subpath (x,y) of path runs from point x of path to point y of path.

  • It's tempting to "correct" the diagram to draw it to scale. If you replace the line defining the box with

    box = unitsquare xscaled 3x yscaled (x-7u);

    then you get this slightly more believable figure.

enter image description here

|improve this answer|||||

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.