0

I tried to draw a following diagram using tikz.

enter image description here

I used the following commands

\draw [black, very thick] (0,0) -- (9,0);

\draw [black, very thick] (3,1/4) -- (3, -1/4);

\draw [black, very thick] (6,1/4) -- (6, -1/4);

But I don't know how to how to write numerical values at desired place and how to write +/- sign at desired place.

Please tell me how to do it?

1 Answers1

3

I make a bit change in your coordinates so that the figure fits better with your document. If it is not good, just change the coordinates in the code.

You can simply add strings to a TikZ picture by a simple \draw command:

\draw (<x>,<y>) node {<string>};

Some option can be added, for example

\draw (<x>,<y>) node[left=0.5cm] {<string>};

For example, this is your diagram:

\documentclass[tikz, border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
    \draw (0,0) -- (6,0);
    \draw (2,-0.1) -- (2,0.1);
    \draw (4,-0.1) -- (4,0.1);
    \draw (2,0) node[below=1ex] {$-3$};
    \draw (4,0) node[below=1ex] {$-6$};
    \begin{scope}[red] % For local settings -- thanks to @marmot's comment
        \draw (1,0) node[above] {$+$};
        \draw (3,0) node[above] {$-$};
        \draw (5,0) node[above] {$+$};
    \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

  • To add strings to a TikZ picture, there is no need to use the\draw command, \node is enough. – AndréC Jan 08 '19 at 04:57
  • 3
    @AndréC Yes. However, I think \draw command is more basic than \node (at least to me), and as the OP shows that he/she doesn't know how to add text, I decide to show her the simplest way. –  Jan 08 '19 at 05:02
  • Your answer induces a false representation of how TikZ works because you confuse the picture with the path. – AndréC Jan 08 '19 at 05:10
  • 3
    @AndréC I disagree with you, it's only one different way of doing things, absolutely correct. – CarLaTeX Jan 08 '19 at 05:40
  • @CarLaTeX Till Tantau is clear: the most important thing is the path. \draw is an alias for the \path[draw].[draw] is an option of the \path operation, see section 15 "Actions on Paths" of manual 3.0.1a. – AndréC Jan 08 '19 at 05:56
  • 3
    @AndréC Is there really a need to fight over this syntactic decision? It's a simple picture and JouleV shows one possible way (out of potentially \inf :)) to achieve the desired result (in his free time for zero money without any warranty). – Dr. Manuel Kuehner Jan 08 '19 at 09:21
  • @Dr.ManuelKuehner What battle? I repeat that the TikZ manual states that to add text, the appropriate operation is \node. Saying you have to write \draw ..... node is not true. When answering a question, you have to be accurate. He gives his personal opinion that there is no support in the manual. – AndréC Jan 08 '19 at 13:27