0

Que: See the attached figure how can I achieve it? I want to draw arrows on both sides of the real lines with some text inside it.

enter image description here

MWE:

\documentclass[12pt]{article}
\usepackage[bindingoffset=0.2in,left=0.5in,right=0.5in,top=0.5in,bottom=0.5in,footskip=.25in]{geometry}
\usepackage[centertags]{amsmath}
\usepackage{latexsym}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{newlfont}
\usepackage{enumerate}
\usepackage{makeidx}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{xparse}
\usetikzlibrary{backgrounds,intersections}
\begin{document}    
    \begin{tikzpicture}[xscale=1.5]
        \draw[thick,latex-latex] (-5,0) -- (6,0)node[right]{};
        \foreach \x in {-4,-3,-2,-1,0,1,2,3,4}{
            \node[fill,circle,inner sep=1.20pt,label=below:$\x$] at (\x,0) {};
        };
    \end{tikzpicture}
\end{document}
SandyM
  • 2,757
  • Take a look at this post https://tex.stackexchange.com/questions/153922/how-to-draw-shape-as-curved-arrows-with-text-with-tikz – pascal974 Mar 30 '24 at 13:01

1 Answers1

2

Here's a way to do it, by changing the shape of a node. See the comments in the code. See chapters 71.5 and 17.2.3 in the tikzmanual.

result

\documentclass[12pt]{article}
\usepackage[bindingoffset=0.2in,left=0.5in,right=0.5in,top=0.5in,bottom=0.5in,footskip=.25in]{geometry}
% ~~~ commented out all that's not needed here ~~~~~~~~~
%\usepackage[centertags]{amsmath}
%\usepackage{latexsym}
%\usepackage{amsfonts}
%\usepackage{amssymb}
%\usepackage{amsthm}
%\usepackage{newlfont}
%\usepackage{enumerate}
%\usepackage{makeidx}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
%\usepackage{xparse}
%\usetikzlibrary{backgrounds,intersections}

\usetikzlibrary{shapes.arrows}

\begin{document}
\begin{tikzpicture}[ xscale=1.5, dots/.style={fill,circle,inner sep=1.20pt}, ] \draw[thick,latex-latex] (-5,0) -- (6,0)node[right]{}; % \foreach \x in {-4,-3,-2,-1,0,1,2,3,4}{% can be shortened \foreach \x in {-4,-3,...,4}{ \node[dots,label=below:$\x$] at (\x,0) {}; };

    % ~~~ arrows ~~~~~~~~~~~~~~
    \node[  single arrow,       % node shaped like an arrow
            anchor=west,        % i.e. the postion below
            fill=green!40,draw=blue
        ] 
            at (0.3,1) {Some text};

    \node[  single arrow,
            anchor=east,
            fill=red!40,draw=purple,
            shape border rotate=180,    % rotates shape, not text
          ] 
            at (-0.3,1) {Some more text};
\end{tikzpicture}

\end{document}

P.S. For colored dots just split the loop and do:

        \foreach \x in {-4,-3,-2,-1}{
            \node[dots,,fill=red,label=below:$\x$] at (\x,0) {};
        };
        \foreach \x in {1,2,3,4}{
            \node[dots,fill=green,label=below:$\x$] at (\x,0) {};
        };

colored

MS-SPO
  • 11,519
  • 1
    Thanks a lot for replying. One small doubt how to increase length of arrow. I mean how to control thickness and length. – SandyM Mar 30 '24 at 15:31
  • 1
    One more question how can I give red colors to all negative numbers, green to all positive numbers and yellow to zero. – SandyM Mar 30 '24 at 15:44
  • For the colored dots see "P.S". // Because the arrows are just the shape of nodes, AND nodes adjust their size according to their textual content, to a large degree length is no problem. If you want to do more, kindly read about the parameter options here https://tikz.dev/library-shapes#sec-71.5 and here https://tikz.dev/tikz-shapes#sec-17.2 . // You may also use a \makebox inside the node, like: \node at (-0.3,1) {\makebox[7cm]{Some more text}}; , where the width of the box resizes the node. See e.g. https://en.wikibooks.org/wiki/LaTeX/Boxes#makebox_and_mbox . – MS-SPO Mar 30 '24 at 16:00
  • For valuable suggestions and corrections, thank you so much. Along with dots is it possible to give colors to numbers. I think zero is missing on number line – SandyM Mar 31 '24 at 00:25
  • Fine. Yes to both. You‘ll find both answers in the manual, like how to place a third colored node, and how to impact its text color. We try to help, not to free from joy or burden of learning. – MS-SPO Mar 31 '24 at 03:37
  • Agree with you. Kindly share the pdf file link of manual. I will go through and try to achieve whatever I want for this question – SandyM Mar 31 '24 at 05:15
  • Just see my first comment, or try your search engine on packages like tikz ;-) – MS-SPO Mar 31 '24 at 05:22
  • Can you modify codes for above said question? – SandyM Mar 31 '24 at 05:45
  • Yes, I can. No, I won't, it's not that difficult. BTW, I get this warning while typing: Please avoid extended discussions in comments. – MS-SPO Mar 31 '24 at 07:51