TransWikia.com

Adding vertical ticks at nodes on a horizontal like drawn with TikZ

TeX - LaTeX Asked on July 1, 2021

I have the following minimal code

documentclass{article}

usepackage{tikz}

begin{document}

begin{tikzpicture}
draw[solid, thick]
(0,0) node [below]{0}
-- (2,0) node [below]{$n-k$}
-- (6,0) node [below]{$n$};
end{tikzpicture}

end{document}

This creates the image below:
enter image description here

How can I get short vertical tick marks at the nodes? By this I mean, how can I get the image to appear like the one below?
enter image description here

Note that the red colour is not necessary but it was just added to the image to make the desired result easier to understand.

2 Answers

The next code

documentclass{article}

usepackage{tikz}

begin{document}

begin{tikzpicture}
draw[solid,thick] (0,0) -- (6,0);
draw[thick] (0,0.2) -- ++ (0,-0.4) node[below] {0};
draw[thick] (2,0.2) -- ++ (0,-0.4) node[below] {$n-k$};
draw[thick] (6,0.2) -- ++ (0,-0.4) node[below] {$n$};
end{tikzpicture}

end{document}

produces:

picture

Correct answer by Luis Sibaja on July 1, 2021

You can draw tick in the foreach loop:

documentclass{article}
usepackage{tikz}

begin{document}
    begin{tikzpicture}
draw[thick] (0,0) -- (6,0);
foreach i/j in {0/0, 2/n-k, 6/n}
draw[draw=red] (i,0.2) -- ++ (0,-0.4) node[below] {$j$};
    end{tikzpicture}
end{document}

enter image description here

Answered by Zarko on July 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP