2

Could some one help me to draw the following picture with Latex ( using only 1 picture) ? Thank you SO MUCH for your help.

enter image description here

  • 8
    Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. – erik Apr 28 '15 at 20:52
  • Dear Erik, I am pretty new with Latex and to bo honest I don't know where to start beside searching on Google but I cannot not find an answer on it. – duy nguyen Apr 28 '15 at 21:18
  • What you need is called TikZ. Your simple drawing is covered in the tutorial of the manual: texample.net/media/pgf/builds/pgfmanualCVS2012-11-04.pdf – hpekristiansen Apr 28 '15 at 21:24
  • Although the tikz manual makes 800 pages, you should get to the point easily by looking at chapter 19. Trees are commons in tikz, see for instance texample.net/tikz/examples/feature/trees . – Clément Apr 28 '15 at 21:27
3

Here's an example of how to get started. I think it should make it clear enough how to continue to get the diagram you want.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}

\begin{tikzpicture}[my midway label/.style={midway,yshift=1.5in}]

  %% case 1
  \node[anchor=east] (A/left)         at (0,0)                  {$x$};
  \node[anchor=west] (A/right)        at ($(A/left)+(1in,0)$)   {$x$};
  \node[anchor=west] (A/right/up/1)   at ($(A/right)+(0,1in)$)  {$x+dx$};
  \node[anchor=west] (A/right/down/1) at ($(A/right)+(0,-1in)$) {$x-dx$};

  \path (A/left) -- (A/right) node [my midway label] {Case 1};

  \draw[blue] (A/left) -- (A/right);
  \draw[red]  (A/left) -- (A/right/up/1.west);
  \draw[red]  (A/left) -- (A/right/down/1.west);

  %% case 2
  \node[anchor=east] (B/left)         at ($(A/right)+(1in,0)$) {$x$};
  \node[anchor=west] (B/right)        at ($(B/left)+(1in,0)$)  {$x$};

  \path (B/left) -- (B/right) node [my midway label] {Case 2};

  \draw[blue] (B/left) -- (B/right);
\end{tikzpicture}

\end{document}

enter image description here

There are other ways of doing this as suggested by @clement . But this approach will help familiarize yourself with some basics of TikZ.

I'll explain a few of the details here:

node syntax

\node[<optional arguments>] (<optional node name>) at (<position>) {<content>};

The one part of this syntax that you cannot omit is the content.

I use the power of the calc library to help place nodes relative to each other. That's what's happening when I write:

at ($(<previously defined node name>)+(<vector>)$)

When I opened the tikzpicture environment, I defined my own private style. This is a way of helping manage the picture. The idea is that I'm going to define a node between two points along a path and then shift it in the $y$ direction.

In this case, I used a particular instance of path syntax:

\path (<1st node name>) -- (<2nd node name>) node[<optional argument] {<content>};

Note that in this case node is not a control sequence but just a bare word.

  • 1
    +1 for the long vary gracious tikz introduction for a newbie. – Ethan Bolker Apr 29 '15 at 0:16

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.