2

There is a very nice TikZ code to visualize the cantor set such as

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{lindenmayersystems}
\pgfdeclarelindenmayersystem{cantor set}{
  \rule{F -> FfF}
  \rule{f -> fff}
}
\begin{document}
\begin{tikzpicture}
  \foreach \order in {0,...,4}
    \draw[yshift=-\order*10pt]  l-system[l-system={cantor set, axiom=F, order=\order, step=100pt/(3^\order)}];
\end{tikzpicture}
\end{document}

enter image description here

from https://tex.stackexchange.com/a/386251/128042

I am wondering if there is an easy way to add annotations to each line. E.g., write $A_{\order}$ next to each line. I.e., write $A_0$ in front of the 1st line, $A_1$ in front of the 2nd line, and so on.

Jakob
  • 993

1 Answers1

4

Like this?

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{lindenmayersystems}
\pgfdeclarelindenmayersystem{cantor set}{
  \rule{F -> FfF}
  \rule{f -> fff}
}
\begin{document}
\begin{tikzpicture}
  \foreach \order in {0,...,4}
    \draw[yshift=-\order*10pt] l-system [l-system={cantor set, axiom=F, order=\order, step=100pt/(3^\order)}]
      node[anchor=east, pos=0] {\footnotesize $A_{\order}$};
\end{tikzpicture}
\end{document}

enter image description here

  • Great, do you also have an idea of how to visualize that each interval is closed on the left and open on the right? I.e., each interval is of the form [a,b). (In the original Cantor set it is closed on both sides. So you can also visualize it being closed on both sides, i.e., [a,b], then I can adapt it myself to my fractal set which is slightly different.) – Jakob Mar 07 '24 at 16:40
  • @Jakob If you tell me what I should write where, I can add this to my solution. I am no mathematician, so I can't help you with the right syntax here. – Jasper Habicht Mar 07 '24 at 16:44
  • Can you put a $[$ on the left end of each black segment? and a $]$ to the right end of each black segment? (Then the total number of brackets double in each line.) – Jakob Mar 07 '24 at 16:47
  • @Jakob I fear it is not straight-forward to add text at the end of the segments, because they are probably part of the same path. It is possible to add text at the left or right of the whole system though. If you want to only draw a few lines like this and add text to it, I suggest that you just draw these using a \foreach command. – Jasper Habicht Mar 07 '24 at 16:52