TeX - LaTeX Asked by 0TickPulse on January 30, 2021
I’m using tikzpicture
to do things, and I want to create a number line that is stretched. Kinda like the 3b1b group theory video.
I know it’s already pretty easy to do this, but I also want to get an automated macro like this:
newcommand{stretch}[2]{
???
}
I’ve already tried, but to no avail. (Prepare for dumb coding.)
newcommand{stretch}[2]{
begin{center}
begin{tikzpicture}
[mathbf(#1times #2)]
draw[<->] (#1-2,0)--(#2+2,0);
draw[<->] (#1-2,-3)--(#2+2,-3);
foreach x in {numbernumexpr-#1-1relax,...,0,...numbernumexpr#1+1relax}
draw[shift={(x,0)},color=black] (0pt,0.2pt) -- (0pt,-0.2pt) node[below] {footnotesize $x$};
foreach x in {numbernumexpr-#1*#2relax,...,numbernumexpr-#2relax,0,#2...numbernumexpr#1*#2relax}
draw[shift={(x,-3)},color=black] (0pt,0.2pt) -- (0pt,-0.2pt) node[below] {footnotesize $x$};
end{tikzpicture}
end{center}
}
Like this? ( I've used 2 times grater and you can change it to 3 or any in 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}
Edit: If you want a macro it should be something like this (but I don't recommend it because you should choose input carefully and the output is a but ugly):
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}}
and use it as mycommand{3}
.
Answered by user108724 on January 30, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP