可扩展版本:

可扩展版本:

我正在尝试生成一个类似于问题中的时钟这里

但我希望对面部进行编号。这个包或其他包可以实现吗?

答案1

对 PGF 文档中的示例进行了细微的改动(第83 重复的事情:Foreach 语句,版本 3.0 的第 912 页):

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[line cap=rect,line width=3pt]
\filldraw [fill=cyan] (0,0) circle [radius=2cm];
\foreach \angle [count=\xi] in {60,30,...,-270}
{
  \draw[line width=1pt] (\angle:1.8cm) -- (\angle:2cm);
  \node[font=\large] at (\angle:1.36cm) {\textsf{\xi}};
}
\foreach \angle in {0,90,180,270}
  \draw[line width=2pt] (\angle:1.6cm) -- (\angle:2cm);
\draw (0,0) -- (120:0.8cm);
\draw (0,0) -- (90:1cm);
\end{tikzpicture}

\end{document}

在此处输入图片描述

也许可以定义一个命令来控制一些属性;下面是一个例子,允许指定数字的颜色、半径和字体大小:

\documentclass{article}
\usepackage{tikz}
\usepackage{xparse}

\NewDocumentCommand{\Clock}{O{2cm}O{\large}O{cyan}}{%
\def\radius{#1}%
\begin{tikzpicture}[line cap=rect,line width=0.055*\radius]
\filldraw [fill=#3] (0,0) circle [radius=\radius];
\foreach \angle [count=\xi] in {60,30,...,-270}
{
  \draw[line width=1pt] (\angle:0.9*\radius) -- (\angle:\radius);
  \node[font=#2] at (\angle:0.68*\radius) {\textsf{\xi}};
}
\foreach \angle in {0,90,180,270}
  \draw[line width=0.04*\radius] (\angle:0.82*\radius) -- (\angle:\radius);
\draw (0,0) -- (120:0.4*\radius);
\draw (0,0) -- (90:0.5*\radius);
\end{tikzpicture}%
}

\begin{document}

\Clock\quad\Clock[1cm][\footnotesize][orange]

\end{document}

在此处输入图片描述

答案2

我们可以将 Gonzalo 的优秀答案转换为宏,以便我们可以像这样使用它:

\clock{<hour>}{<minute>}{<seconds>}

可以进一步美化,并留作家庭作业;-)

\documentclass[dvipsnames]{article}
\usepackage{tikz}

\begin{document}
\newcommand\clock[3]{%
\begin{tikzpicture}[line cap=round,line width=3pt]
\filldraw [fill=Goldenrod!30] (0,0) circle (2cm);
\foreach \angle / \label in
{0/3, 30/2, 60/1, 90/12, 120/11, 150/10, 180/9,
210/8, 240/7, 270/6, 300/5, 330/4}
{
\draw[line width=1pt] (\angle:1.8cm) -- (\angle:2cm);
\draw (\angle:1.4cm) node{\textsf{\label}};
}
\foreach \angle in {0,90,180,270}
\draw[line width=2pt] (\angle:1.6cm) -- (\angle:2cm);
\node[draw=none,font=\tiny,text=red] at (0,.9cm) {TICK-TOCK};
\draw[rotate=90,line width=2pt] (0,0) -- (-#1*30-#2*30/60:0.7cm); % hours
\draw[rotate=90,line width=1.5pt] (0,0) -- (-#2*6:1cm); % minutes
\draw[rotate=90,thin,red] (0,0) -- (-#3*6:1.2cm); % seconds
\path [fill=red] (0,0) circle (2pt);
%
\end{tikzpicture}%
}
%%\syntax
%% \clock{<hour>}{<minute>}{<seconds>}
\noindent\clock{1}{15}{30} \clock{2}{25}{15}
\clock{12}{58}{10} \clock{6}{10}{45}


\end{document}

在此处输入图片描述

可扩展版本:

\documentclass[dvipsnames]{article}
\usepackage{tikz}

\begin{document}
\newcommand\clock[4][2]{%
\begin{tikzpicture}[scale=#1,line cap=round,line width=#1*3pt]
\filldraw [fill=Goldenrod!20] (0,0) circle (2cm);
\foreach \angle / \label in
{0/3, 30/2, 60/1, 90/12, 120/11, 150/10, 180/9,
210/8, 240/7, 270/6, 300/5, 330/4}
{
\draw[line width=#1*1pt] (\angle:1.8cm) -- (\angle:2cm);
\draw (\angle:1.4cm) node[scale=#1]{\textsf{\label}};
}
\foreach \angle in {0,90,180,270}
\draw[line width=#1*2pt] (\angle:1.6cm) -- (\angle:2cm);
\node[draw=none,font=\tiny,text=red,scale=#1] at (0,.9cm) {TICK-TOCK};
\draw[rotate=90,line width=#1*2pt] (0,0) -- (-#2*30-#3*30/60:0.7cm); % hours
\draw[rotate=90,line width=#1*1.5pt] (0,0) -- (-#3*6:1cm); % minutes
\draw[rotate=90,line width=#1*.6pt,red] (0,0) -- (-#4*6:1.2cm); % seconds
\path [fill=black] (0,0) circle (3pt);
\path [fill=red] (0,0) circle (1.5pt);
%
\end{tikzpicture}%
}
%%\syntax
%% \clock[<optional scaling dim>]{<hour>}{<minute>}{<seconds>}
\noindent\clock{9}{35}{55}\clock[1.2]{1}{15}{30} \clock[.9]{2}{25}{15}
\clock[.7]{12}{58}{10} \clock[.5]{6}{10}{55}
\clock[.3]{12}{20}{22} \clock[.2]{8}{0}{5}


\end{document}

在此处输入图片描述

这是一个极简动画。我不敢加入秒针/使间隔变小。

\documentclass[preview,border={10pt 0pt 10pt 10pt}]{standalone}

\usepackage{filecontents}
\begin{filecontents*}{clock.tex}
\documentclass[tikz,border=0pt,dvipsnames]{standalone}
\usepackage{tikz}

\begin{document}
\foreach \hdeg / \mdeg in {0/0,2/24,4/48,6/72,8/96,10/120,12/144,14/168,
16/192,18/216,20/240,22/264,24/288,26/312,28/336,30/360}{%
\begin{tikzpicture}[line cap=round,line width=3pt]
\filldraw [fill=Goldenrod!30] (0,0) circle (2cm);
\foreach \angle / \label in
{0/3, 30/2, 60/1, 90/12, 120/11, 150/10, 180/9,
210/8, 240/7, 270/6, 300/5, 330/4}
{
\draw[line width=1pt] (\angle:1.8cm) -- (\angle:2cm);
\draw (\angle:1.4cm) node{\textsf{\label}};
}
\foreach \angle in {0,90,180,270}
\draw[line width=2pt] (\angle:1.6cm) -- (\angle:2cm);
\node[draw=none,font=\tiny,text=red] at (0,.9cm) {TICK-TOCK};
\draw[rotate=90,line width=2pt] (0,0) -- (-\hdeg:0.7cm); % hours
\draw[rotate=90,line width=1.5pt] (0,0) -- (-\mdeg:1cm); % minutes
\path [fill=black] (0,0) circle (3pt);
\path [fill=red] (0,0) circle (2pt);
%
\end{tikzpicture}%
%}
}

\end{document}
\end{filecontents*}
%
\immediate\write18{pdflatex clock}

% convert to GIF animation
\immediate\write18{convert -delay 200 -loop 0 -density 400 -alpha remove clock.pdf clock.gif}

\usepackage{animate}
\begin{document}
See the gif file in the same folder as this file.
\end{document}

在此处输入图片描述

答案3

有点题外,有一次我做了一个“数学钟”作为生日礼物。结果被打印出来,我用它替换了真实时钟的数字牌:

\documentclass[landscape,a3paper,extrafontsizes,12pt]{memoir}
\usepackage[a3paper,margin=0.2cm]{geometry} 
\usepackage{tikz}
\usepackage{amsmath}
\begin{document}
\begin{center}
\vspace*{\fill}

\begin{tikzpicture}
    \foreach \x in {0,30,...,360} {
        \draw [line width = 0.1cm] (\x:9cm) -- (\x:10.5cm);
    };
    \foreach \x in {0,6,...,360} {
        \draw [line width = 0.05cm] (\x:10cm) -- (\x:10.5cm);
    };
    \draw (0:0cm) circle [radius = 0.2cm];

    \node (1) at (60:7cm) {\Large $\boldsymbol{9^{9-9}}$};
    \node (2) at (30:7cm) {\Large $\boldsymbol{\dfrac{9+9}{9}}$};
    \node (3) at (0:7cm) {\Huge $\boldsymbol{\sqrt{\log_{9}{9^9}}}$};
    \node (4) at (-30:7cm) {\Large $\boldsymbol{\sqrt{9}+\log_{9}9}$};
    \node (5) at (-60:7cm) {\Large $\boldsymbol{\sqrt{9}!-\log_{9}9}$};
    \node (6) at (-90:7cm) {\Huge $\boldsymbol{9 - \dfrac{9}{\sqrt{9}}}$};
    \node (7) at (-120:7cm) {\Large $\boldsymbol{\sqrt{9}!+\dfrac{9}{9}}$};
    \node (8) at (-150:7cm) {\Large $\boldsymbol{9 - \dfrac{9}{9}}$};
    \node (9) at (-180:7cm) {\Huge $\boldsymbol{\sqrt[9]{9^9}}$};
    \node (10) at (-210:7cm) {\Large $\boldsymbol{9 + \log_{9}{9}}$};
    \node (11) at (-240:7cm) {\Large $\boldsymbol{\dfrac{99}{9}}$};
    \node (12) at (-270:7cm) {\Huge $\boldsymbol{9 + \dfrac{9}{\sqrt{9}}}$};
\end{tikzpicture}
\vspace*{\fill}
\end{center}
\end{document}

(这是摘录,原文中每一行的分钟数也有 0-59 的数字)

结果:

LaTeX 结果

没有指针,因为指针是由真正的时钟提供的

答案4

使用 Metapost。这比它应该的要复杂得多,因为它需要小心标记每一分钟,并且五分钟刻度与一分钟刻度使用不同的宽度和长度,但它仍然非常简单:

beginfig(1);

diameter=160;
radius=diameter/2;

pickup pencircle scaled 0.5;

z0 = (radius,radius);
z50 = (radius,diameter);

pair r[];
r[12]  = z50 shifted (0,-radius/4.5);
for i=12 downto 1:
    r[i] = r[i+1] rotatedaround (z0,30);
    z[i] = r[i];
endfor
defaultfont := "cmr17";
defaultscale := 1.5;
label("12",z12);
label("6",z6);
label("9",z9);
label("3",z3);
label("1",z1);
label("5",z5);
label("7",z7);
label("11",z11 shifted (0,-1pt));
label("2",z2);
label("4",z4);
label("8",z8);
label("10",z10 shifted (1pt,0));

pair p[];
pair q[];
numeric circangle;
circangle := 0;
p[0] = z50;
for i=0 step 1 until 60:
    p[i] = p[i-1] rotatedaround (z0,6);
    if (i mod 5 = 0):
        q[i] = 1/12[p[i],z0];
        pickup pencircle scaled 2;
        draw p[i]--q[i];
        pickup pencircle scaled 0.5;
    else:
        q[i] = 1/30[p[i],z0];
        pickup pencircle scaled 0.5;
        draw p[i]--q[i];
    fi
    draw p[i-1]..p[i];
endfor

endfig;
end;

我一直偏爱 Metapost,因为我发现它比 tikZ 更容易编程。然而,tikZ 确实具有能够被放入宏的好处,正如 Harish Kumar 上述出色的回答所证明的那样。

我知道,严格来说,这不是一个 TeX 答案;但 Metapost 在 TeXnicians 中享有盛誉(据说,甚至 Knuth 本人也用它来制作他的图表),所以对我来说这似乎是一个公平的答案。

相关内容