拉伸数轴

拉伸数轴

我用tikzpicture它来做事,我想创建一条拉伸的数字线。有点像 3b1b 群论视频。

我想要实现的目标示例(来自 3Blue1Brown)

我知道这样做已经相当容易了,但我还想获得像这样的自动宏:

\newcommand{\stretch}[2]{
    ???
}

我已经尝试过了,但无济于事。(准备好愚蠢的编码吧。)

\newcommand{\stretch}[2]{
    \begin{center}
        \begin{tikzpicture}
        \[\mathbf(#1\times #2)\]
        \draw[<->] (#1-2,0)--(#2+2,0);
        \draw[<->] (#1-2,-3)--(#2+2,-3);
        \foreach \x in {\number\numexpr-#1-1\relax,...,0,...\number\numexpr#1+1\relax}  
        \draw[shift={(\x,0)},color=black] (0pt,0.2pt) -- (0pt,-0.2pt) node[below] {\footnotesize $\x$};
        \foreach \x in {\number\numexpr-#1*#2\relax,...,\number\numexpr-#2\relax,0,#2...\number\numexpr#1*#2\relax}  
        \draw[shift={(\x,-3)},color=black] (0pt,0.2pt) -- (0pt,-0.2pt) node[below] {\footnotesize $\x$};
        \end{tikzpicture}
    \end{center}
}

答案1

喜欢这个吗?(我用了 2 倍磨碎机,你可以将其更改为 3 倍或任意倍数\draw[shift={(\x*2,2)},color=black]

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\draw[<->] (-7,2)--(7,2);
\foreach \x in {-3,-2,...,3}
\draw[shift={(\x*2,2)},color=black] (0pt,3pt) -- (0pt,-3pt) node[below] 
{$\x$};

\draw[->, thick,green] (0,3)--(0,2.2);

\draw[<->] (-7,0)--(7,0);
\foreach \x in {-6,-5,...,6}
\draw[shift={(\x,0)},color=black] (0pt,3pt) -- (0pt,-3pt) node[below] 
{$\x$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

编辑:如果您想要一个宏,它应该是这样的东西(但我不推荐它,因为您应该谨慎选择输入,并且输出很丑陋):

\newcommand{\mycommand}[1]{ \begin{tikzpicture}[scale=.5] \draw[<->] (-3*#1-1,2)--(3*#1+1,2); \foreach \x in {-3,-2,...,3} \draw[shift={(\x*#1,2)},color=black] (0pt,3pt) -- (0pt,-3pt) node[below] {$\x$}; \draw[->, thick,green] (0,3)--(0,2.2); \draw[<->] (-7,0)--(7,0); \foreach \x in {-6,-5,...,6} \draw[shift={(\x,0)},color=black] (0pt,3pt) -- (0pt,-3pt) node[below] {$\x$}; \end{tikzpicture}}

并将其用作\mycommand{3}

相关内容