帮助使用 TikZ 绘制一条非常简单的数字线

帮助使用 TikZ 绘制一条非常简单的数字线

我想画一条非常简单的数字线,我找到了一些可以帮助我入门的代码这里。我修改了代码,得到下面的图片

在此处输入图片描述

问题是我希望线下方的数字显示为 {-3,2,1,0,1,2,3},但我不知道如何修改下面的代码来做到这一点。

\usetikzlibrary{arrows}
\begin{tikzpicture}
\draw[latex-] (-6.5,0) -- (6.5,0) ;
\draw[-latex] (-6.5,0) -- (6.5,0) ;
\foreach \x in  {-6,-4,-2,0,2,4,6}
\draw[shift={(\x,0)},color=black] (0pt,3pt) -- (0pt,-3pt);
\foreach \x in {-6,-4,-2,0,2,4,6}
\draw[shift={(\x,0)},color=black] (0pt,0pt) -- (0pt,-3pt) node[below] 
{$\x$};
\draw[*-o] (0.92,0) -- (2.08,0);
\draw[very thick    ] (0.92,0) -- (1.92,0);

\end{tikzpicture}

\x如果我能用2 代替就好了node[below] {$\x$},但我不知道怎么做。谢谢!

答案1

请参阅以下 MWE:

在此处输入图片描述

\documentclass[letterpaper]{article}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}
\draw[latex-latex] (-3.5,0) -- (3.5,0) ; %edit here for the axis
\foreach \x in  {-3,-2,-1,0,1,2,3} % edit here for the vertical lines
\draw[shift={(\x,0)},color=black] (0pt,3pt) -- (0pt,-3pt);
\foreach \x in {-3,-2,-1,0,1,2,3} % edit here for the numbers
\draw[shift={(\x,0)},color=black] (0pt,0pt) -- (0pt,-3pt) node[below] 
{$\x$};
\draw[*-o] (0.92,0) -- (2.08,0);
\draw[very thick] (0.92,0) -- (1.92,0);
\end{tikzpicture}
\end{document}

以下是目前可以通过缩放来实现的功能:

\begin{tikzpicture}[scale=2.5]
\draw[very thick] (1,0) -- (2,0);
\path [draw=black, fill=black] (1,0) circle (2pt);
\path [draw=black, fill=white, thick] (2,0.0) circle (2pt);
\draw[latex-latex] (-3.5,0) -- (3.5,0) ;
\foreach \x in  {-3,-2,-1,0,1,2,3}
\draw[shift={(\x,0)},color=black] (0pt,3pt) -- (0pt,-3pt);
\foreach \x in {-3,-2,-1,0,1,2,3}
\draw[shift={(\x,0)},color=black] (0pt,0pt) -- (0pt,-3pt) node[below] 
{$\x$};
\end{tikzpicture}

答案2

\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{pst-plot}
\psset{xunit=15mm}
\begin{document}
\begin{pspicture}(-3,-.5)(3,.5)
    \psaxes[yAxis=false,ticksize=0 -4pt]{<->}(0,0)(-3,-1)(3,1)
    \psline[linecolor=blue,arrowscale=1.25]{o-*}(.5,0)(2,0)
\end{pspicture}
\end{document}

在此处输入图片描述

相关内容