0

I simply modified the clock code in this link: clock

Here is my code:

\NewDocumentCommand{\Clock}{O{1cm}O{\large}O{cyan}O{\textbf{}}}{%
\def\radius{#1}%
\begin{tikzpicture}[line cap=rect,line width=0.055*\radius]
\filldraw [fill=#3] (0,0) circle [radius=\radius] node {O\textbf{}};
\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) {};
}
\foreach \angle in {0,90,180,270}
  \draw[line width=0.04*\radius] (\angle:0.82*\radius) -- (\angle:\radius);
\end{tikzpicture}%
}

I am trying to give my text as a parameter in these two lines:

\NewDocumentCommand{\Clock}{O{1cm}O{\large}O{cyan}O{\textbf{}}}
\filldraw [fill=#3] (0,0) circle [radius=\radius] node {O\textbf{}};

by using O\textbf{}

Here is how I use this code:

 \quad\Clock[0.9 cm][\footnotesize][green][\textbf{my text here}

As a result, I see this image: enter image description here

However intead of O in the middle of the clock, I want to see "my text here" How can I do that?

j.doe
  • 131
  • 1
    you want a spec of O{} or O{default text} then use the argument #4 so replace node {O\textbf{}} by node {\textbf{#4}} – David Carlisle Jan 19 '23 at 00:34
  • when I tried that, I completely lost the file and could not see anything – j.doe Jan 19 '23 at 00:39
  • OK I tried: \NewDocumentCommand{\Clock}{O{1cm}O{\large}O{cyan}O{default text}} and ```\filldraw [fill=#3] (0,0) circle [radius=\radius] node {\textbf{#4}};
    
    
    – j.doe Jan 19 '23 at 00:53

1 Answers1

1

In the definition of the command \Clock, I replace the 4th argument O{\textbf{}} simply by O{}.

As David Carlisle said in the comment to your question, replace node {O\textbf{}}; by node {\textbf{#4}}; (so the text is always bold in the clock). Here, #4 is the 4th argument used when you call \Clock

Finally, I change your text "my text here" used when you call \Clock by the text "my text", because "my text here" is too long.

\documentclass[11pt]{article}

\usepackage{tikz}

\NewDocumentCommand{\Clock}{O{1cm}O{\large}O{cyan}O{}}{% \def\radius{#1}% \begin{tikzpicture}[line cap=rect,line width=0.055\radius] \filldraw [fill=#3] (0,0) circle [radius=\radius] node [align=center] {\textbf{#4}}; \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) {}; } \foreach \angle in {0,90,180,270} \draw[line width=0.04\radius] (\angle:0.82*\radius) -- (\angle:\radius); \end{tikzpicture}% }

\begin{document}

\Clock\quad\Clock[0.9cm][\footnotesize][green][my text]

\end{document}

This code works with very recent LaTeX (before the 2022 version, please add \usepackage{xparse} in the preamble, before \NewDocumentCommand).

You obtain: enter image description here

quark67
  • 4,166