3

I've managed using this stack exchange info to build the following MWE:

\documentclass{article}
\pagestyle{empty}

\usepackage{tikz}
\usepackage{geometry}
\usetikzlibrary{positioning,calc}

\geometry{papersize={20mm, 40mm}}

\def\centerarc[#1](#2)(#3:#4:#5)
    { \draw[#1] ($(#2)+({#5*cos(#3)},{#5*sin(#3)})$) arc (#3:#4:#5); }

\newcommand\lw{0.2mm}

\newcommand\dial[2]{
\begin{tikzpicture}[remember picture,overlay]
\centerarc[fill=none,draw=black,line width=\lw]($(current page.south west)+(#1,#2)$)(-60:240:8mm)
\end{tikzpicture}
}

\begin{document}
\dial{10.0mm}{20.0mm}
\end{document}

As I result I get this:

enter image description here

How do I change the dial to have tick marks like this?

enter image description here

A solution for the above dial would already help me a great deal.

Really cool would be if the code provided the flexibility for putting text on each tick mark, such as the numbers 0 to 10, or something customized for a volume knob like this:

enter image description here

Hansel
  • 417

1 Answers1

3

Like this?

\documentclass{article}
\pagestyle{empty}

\usepackage{tikz}
\usepackage{geometry}
\usetikzlibrary{positioning,calc,intersections}

\geometry{papersize={20mm, 40mm}}

\def\centerarc[#1](#2)(#3:#4:#5)
    { \draw[#1] ($(#2)+({#5*cos(#3)},{#5*sin(#3)})$) arc (#3:#4:#5); }

\newcommand\lw{0.2mm}

\newcommand\dial[2]{
\begin{tikzpicture}[remember picture,overlay]
\centerarc[name path=arcc,fill=none,draw=black,line width=\lw]($(current page.south west)+(#1,#2)$)(-60:240:8mm)
\foreach \t [count=\i from 0] in {-60,-30,...,240}{
\path [name path=\t]($(current page.south west)+(#1,#2)$)--++(\t:8.2mm);
\path [name intersections={of=arcc and \t,by={\t1}}];
\draw [line cap=round, line width=\lw](\t1)--++(\t:0.5mm);
\path (\t1)--++(\t:1.5mm)node{\scalebox{0.5}{$\i$}};
}
\end{tikzpicture}
}

\begin{document}
\dial{10.0mm}{20.0mm}
\end{document}

enter image description here

  • After compiling, I get a small white window on MikTeX. – AndréC Jan 24 '20 at 20:34
  • @AndréC, yes right. When I first compiled the OP's code, I saw a white page. It gave results in the second compiling. –  Jan 24 '20 at 20:40
  • Even with a double compilation, I don't get anything... – AndréC Jan 24 '20 at 20:49
  • Wow, this works really well. Many thanks for the code. I've studied it and I think I understand about 80% of it. The following part doesn't seem to do anything when I change the value: "--++(\t:8.2mm)". What is it supposed to do? – Hansel Jan 24 '20 at 20:52
  • @AndréC, I'm using also MikTeX. –  Jan 24 '20 at 20:52
  • For me it works just fine in TeXworks. – Hansel Jan 24 '20 at 20:54