如何在 Latex 中绘制以下数字线

如何在 Latex 中绘制以下数字线

在此处输入图片描述

因此,我尝试在 Latex 中绘制以下内容,但遇到了麻烦,我尝试了以下内容,但没有成功:

\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 {x_{1/2},x_{3/2},...,x_{i-1/2},x_{i+1/2},...,x_{N+1/2}} % edit here for the numbers
\draw[shift={(\x,0)},color=black] (0pt,0pt) -- (0pt,-3pt) node[below] 
{$\x$};
\end{tikzpicture}

答案1

欢迎来到 TEX -看看答案是否满足您的要求

\documentclass[tikz, margin=1cm]{standalone}
\usepackage{siunitx, makecell}
\usetikzlibrary{positioning,calc, arrows.meta}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}

\begin{tikzpicture}
    \draw[latex-latex] (-3.5,0) -- (3.5,0) ; %edit here for the axis

    \foreach \x [count=\i] in  {-3,-2,-1,0,1,2,3} % edit here for the vertical lines
    \draw[shift={(\x,0)},color=red, line width=1pt] (0pt,3pt) node(X\i){}-- (0pt,-3pt);

    \node[below=1pt of X1] (a) {a};
    \node[below=1pt of X7] (b) {b}; 
    
    \node[below=1em of X1] (x1) {\tiny$X_{1/2}$};   
    \node[below=1em of X2] (x2) {\tiny$X_{2/2}$};   
    
    \node[yshift=1pt](1)at ($(X1)!0.5!(X2)$){\tiny 1};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容