6

How could I make the following figure?

enter image description here enter image description here

My code so far is:

\documentclass[12pt,a4paper]{article}
\usepackage[english,greek]{babel}
\usepackage{ucs} 
\usepackage[utf8x]{inputenc}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}
\draw[->, very thick](0,0)--(6,0) node[below]{$Q$};
\draw[->, very thick](0,0)--(0,6) node[left]{$P$};
\draw[-, JungleGreen] (5,0) node[below]{$200$}--(0,5) node[left] {$50$};
\draw[dotted] (0,1) node[left]{$10$}--(4,1);
\draw[dotted] (4,1)--(4,0) node[below]{$160$};
\node[above right] at (4,1) {$A$};
\draw[dotted] (0,3) node[left]{$30$}--(2,3);
\draw[dotted] (2,3)--(2,0) node[below]{$80$};
\node[above right] at (2,3) {$B$};
\end{tikzpicture}
\end{center}
\end{document}

2 Answers 2

8

Indeed, as Dror pointed out the right way to go is to exploit the library decorations.markings.

Here is a solution that provides a new style arrowed pattern (similarly to dotted pattern from Dotted lines in TikZ with round dots) that simplifies the way in which you have to use the library. Moreover, it is possible to customize the distance between arrows, the arrows' color and tip.

The code:

\documentclass[12pt,a4paper]{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}

\usetikzlibrary{decorations.markings}

\pgfkeys{/tikz/.cd,
  arrow color/.initial=black,
  arrow color/.get=\arrowcolor,
  arrow color/.store in=\arrowcolor,
  arrow distance/.initial=5mm,
  arrow distance/.get=\arrowdistance,
  arrow distance/.store in=\arrowdistance,
  arrow tip/.initial=to,
  arrow tip/.get=\arrowtip,
  arrow tip/.store in=\arrowtip,
}

\tikzset{arrowed pattern/.style args={between #1 and #2}{
   postaction=decorate,
   decoration={
    markings,
    mark=
    between positions #1 and #2 step \arrowdistance
      with
      {
       \arrow[\arrowcolor,arrow options]{\arrowtip}
      }
    }
  },
  arrowed pattern/.default={between 0 and 1},
  arrow options/.style={
    thick
  }
}

\begin{document}
\begin{tikzpicture}
\draw[->, very thick](0,0)--(6,0) node[below]{$Q$};
\draw[->, very thick](0,0)--(0,6) node[left]{$P$};

\draw[-, JungleGreen,
  arrow tip=stealth,
  arrowed pattern=between 0.25 and 0.6] (5,0) 
  node[below]{$200$}--(0,5) node[left] {$50$};

\draw[dotted,
 arrowed pattern=between 0.6 and 0.95,
 arrow color=red,
 arrow distance=2mm,
 ] (0,1) node[left](10){$10$}--(4,1);

\draw[dotted] (4,1)--(4,0) node[below](160){$160$};
\node[above right] at (4,1) {$A$};
\draw[dotted] (0,3) node[left](30){$30$}--(2,3);
\draw[dotted] (2,3)--(2,0) node[below](80){$80$};
\node[above right] at (2,3) {$B$};

% dots
\fill (2,3) circle (1.5pt);
\fill (4,1) circle (1.5pt);

% curved arrows
\draw(160.south) edge[->,bend left] (80.south);
\draw(10.west) edge[->,bend left] (30.west);
\end{tikzpicture}
\end{document}

The result:

enter image description here

6
  • What about the dot on the points A and B? The curvy arrows between 160 and 80 on x-axis?
    – Y_gr
    Commented Jul 1, 2013 at 8:23
  • The red arrows between 80-160 are just to made another example on the same graph. For the dot on A and B, please see my edit. Commented Jul 1, 2013 at 8:32
  • What I mean about the arrows between 160 and 80 on x-axis, please check out my edit in my question in the red circles.
    – Y_gr
    Commented Jul 1, 2013 at 8:36
  • 1
    My last edit should accomplish that, but please revert the question to the previous version and add the request of curved arrows. As it stands now does not reflect the original purpose, it just seem you wanted to add two curved arrows.. Commented Jul 1, 2013 at 8:50
  • Ok, I'll fix it again. Your edited code shows me: Package pgf Error: No shape named 160 is known. What should I do?
    – Y_gr
    Commented Jul 1, 2013 at 9:00
6

A good start would be to use the decorations.markings library. Consider the following example which you can tweak to get what you want:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{calc,decorations.markings}
\begin{document}
\begin{tikzpicture}
  \begin{scope}[thick,decoration={%
      markings,
      mark=% actually add a mark
      between positions 0.25 and 0.75 step 5mm
      with
      {
        \arrow{>}
      }
    }
    ]
    \coordinate (a1) at (-2,0);%
    \coordinate (a2) at (-1,1);%
    \coordinate (a3) at (0,0);%
    \coordinate (a4) at (1,1);
    \coordinate (a5) at (-0.25,0.75);%
    \draw[postaction={decorate}] (a1) -- (a2);%
    \draw[postaction={decorate}] (a2) -- (a3);%
    \draw[postaction={decorate}] (a3) -- (a4);%
    \draw[postaction={decorate}] (a4) -- (a5);%
    \foreach \i in {1,2,3,4,5}%
    \fill (a\i) circle (2pt);%
  \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

1
  • Sorry about the small lines at the edge of the image, cropping went a little fast.
    – daleif
    Commented Jul 1, 2013 at 8:18

You must log in to answer this question.

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