Loving tikz-timing for preparing timing diagrams for my teaching. One thing I've not been able to find, though, is how I might add a numbered time axis to a timing diagram. This is useful when showing the basics of testbench design, and wanting to indicate the correspondence in the diagram with a line in the Verilog source. I imagine a TikZ overlay could work, but I'm not that much of a pro, and would prefer something where the numbers are added automatically. I am using the vertical help lines, so somehow adding numbers above or below those would be great.


There is no dedicated macro provided by tikz-timing, but it is possible to draw such a labeled axis using the size macros and nodes provided.

The number of rows is given by \nrows and the widest row by \twidth. The rows are also provided as nodes called row<number> and the last row node is also named last row. To draw extra material place the drawing code in an extracode environment after the last row as shown in the example below. Please see the manual of tikz-timing for more details.

 clk  &  20{C}   \\
 sig  &   5{HLZD{}}  \\
  \vertlines[help lines]{}
  \horlines[help lines]{}
  \draw [->,>=latex] (0,-\nrows-1) -- (\twidth+1,-\nrows-1);
  \foreach \n in {0,1,...,\twidth}
    \draw (\n,-\nrows-1+.1) -- +(0,-.2)
        node [below,inner sep=2pt] {\scalebox{.75}{\tiny\n}};


If you need this more often you could define an own macro:


  \draw [timing/table/axis] (0,-\nrows-1) -- (\twidth+1,-\nrows-1);
  \foreach \n in {0,1,...,\twidth} {
    \draw [timing/table/axis ticks]
        (\n,-\nrows-1+.1) -- +(0,-.2)
        node [below,inner sep=2pt] {\scalebox{.75}{\tiny\n}};
    timing/table/axis ticks/.style={},

 clk  &  20{C}   \\
 sig  &   5{HLZD{}}  \\

Here is another possible way, using pgfplots and the axis environment; it would look like this:


... using this MWE:

\usetikzlibrary{intersections} %% named intersections

% http://tex.stackexchange.com/questions/33703/extract-x-y-


\begin{axis}[clip=false,ymin = 0, ymax = 2, xmin = 0, xmax = 5]

 %\addplot [] node [] (origin) at (0,0) {}; %no
\addplot [] coordinates {(0,0)};
\node[] (refsize) at ({axis cs:1,1}) {};

\pgfplotsextra{ % must have, else \gettikzxy will not work!
% re-convert \rx back to length, so can scale it directly in style= below:
\typeout{rx \rx - \the\trx, ry \ry}

\timing[very thick,style={x=0.5\trx,y=\ry},name=tgraph1] at ({axis cs:1,0.5}) { HLHLHL };

% debug:
% add frame border around tgraph1
\node[fit=(tgraph1), draw, color=gray] {};
% indicate origin of tgraph1 (is lower left corner):
\node[fill,circle,color=gray] at (tgraph1.origin) {};
} % end \pgfplotsextra



Note that one needs to do a bit of arithmetic, so as to scale the units of the \timing graph to those units shown on the graph - maybe my example above won't be pixel-perfect aligned, but at least it doesn't look all that difficult to set up...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.