2

I want to draw exactly the same figure attached using Tikz-PGF package in lateX. How can I do that. I appreciate any help, because I have to submit a paper, and it was kind of last minute addition. Thanksenter image description here

6

This service "do-it-for-me" ...

\begin{tikzpicture}
\draw[<->]  (-1,0.0) -- (6,0) node[below left] {$x$};
\draw[<->]  (0,-0.5) -- (0,3) node[below left] {$y$};

\draw[very thick]   (0,0) |- (5,1) -- (5,0)
                    (2,0) |- (3,2) -- (3,0);
\draw[{Bar[width=4mm].Straight Barb[]}-{Straight Barb[].Bar[width=4mm]}]
    (2,-0.4) -- node[fill=white] {$W$}  (3,-0.4);
\draw[{Bar[width=4mm].Straight Barb[]}-{Straight Barb[].Bar[width=4mm]}]
    (0,-0.8) -- node[fill=white] {$GW$} (5,-0.8);
\end{tikzpicture}

That above code will work, you need to preamble add \usetikzlibrary{arrows.meta}. Result:

enter image description here

Addendum: As request in comment below ... follows three cases of possible coloring of "rectangles":

enter image description here

Complete small document, called Minimal Working Example (MWE), which produce above images, is

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta}

\begin{document}
% colored lines
    \begin{tikzpicture}
    \draw[<->]  (-1,0.0) -- (6,0) node[below left] {$x$};
    \draw[<->]  (0,-0.5) -- (0,3) node[below left] {$y$};

\draw[red,very thick]  % <--- changed
                (0,0) |- (5,1) -- (5,0); 
\draw[blue,very thick] % <--- added 
                (2,0) |- (3,2) -- (3,0); 

    \draw[{Bar[width=4mm].Straight Barb[]}-{Straight Barb[].Bar[width=4mm]}]
        (2,-0.4) -- node[fill=white] {$W$}  (3,-0.4);
    \draw[{Bar[width=4mm].Straight Barb[]}-{Straight Barb[].Bar[width=4mm]}]
        (0,-0.8) -- node[fill=white] {$GW$} (5,-0.8);
    \end{tikzpicture}

    \begin{tikzpicture}
% colored lines and fill
    \draw[<->]  (-1,0.0) -- (6,0) node[below left] {$x$};
    \draw[<->]  (0,-0.5) -- (0,3) node[below left] {$y$};

\draw[draw=red,fill=red!30,very thick]   % <--- changed
                (0,0) |- (5,1) -- (5,0); 
\draw[draw=blue,fill=blue!30,very thick] % <--- added
                (2,0) |- (3,2) -- (3,0); 

    \draw[{Bar[width=4mm].Straight Barb[]}-{Straight Barb[].Bar[width=4mm]}]
        (2,-0.4) -- node[fill=white] {$W$}  (3,-0.4);
    \draw[{Bar[width=4mm].Straight Barb[]}-{Straight Barb[].Bar[width=4mm]}]
        (0,-0.8) -- node[fill=white] {$GW$} (5,-0.8);
    \end{tikzpicture}

    \begin{tikzpicture}
% colored lines and fill, added transparency
    \draw[<->]  (-1,0.0) -- (6,0) node[below left] {$x$};
    \draw[<->]  (0,-0.5) -- (0,3) node[below left] {$y$};

\draw[draw=red,fill=red!30,very thick,semitransparent]  % <--- changed  
                (0,0) |- (5,1) -- (5,0); 
\draw[draw=blue,fill=blue!30,very thick,semitransparent]% <--- changed
                (2,0) |- (3,2) -- (3,0); 

    \draw[{Bar[width=4mm].Straight Barb[]}-{Straight Barb[].Bar[width=4mm]}]
        (2,-0.4) -- node[fill=white] {$W$}  (3,-0.4);
    \draw[{Bar[width=4mm].Straight Barb[]}-{Straight Barb[].Bar[width=4mm]}]
        (0,-0.8) -- node[fill=white] {$GW$} (5,-0.8);
    \end{tikzpicture}
\end{document}
  • Thanks. I understand why you said that. I've never done this before. But searching for doing this took me all morning, and I couldn't find the answer. Thanks again, I appreciate it. – David Mar 10 '16 at 20:55
  • Is it possible to color each rectangular alone? – David Mar 10 '16 at 21:27
  • Yes, it is possible. just line: draw=color or fill fill=color. I add examples of three coloring. – Zarko Mar 11 '16 at 3:50

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.