[Tex/LaTex] drawing lines in tikz-timing

nodestikz-pgftikz-timing

I'm having some problems getting my node locations correct using tikz-timing. I'd like the double-arrow line to be at the center of the pulse on both sides, instead of from bottom to top. Also, I'd like to place the label "tw" below the center of that double arrow line.

\documentclass{article}
\usepackage{tikz-timing}
\begin{document}


\begin{tikztimingtable}[timing/slope=.005, yscale=2]
    Comparator Out & 2L  0.8H8.2L 0.8H 11.2L\\
    One-Shot Out & 2L N(A1)  4H N(A2) 5L4H 8L\\
    \extracode
    %\horlines[] {0,1,5}
    \tableheader[]{}{Case3: Two input pulses, far apart}
    \draw [<->] (A1.center) -- (A2.south);
    \node[] at (A1)  {tw};
\end{tikztimingtable}
\end{document}

[1]: https://i.stack.imgur.com/9mS

Best Answer

There are some predefined anchors for a row in a tikztimingtable, see figure 2.1 in the tikz-timing manual. You can use one of the mid anchors of row2 combined with the (a |- b) coordinate specification of TikZ, and thus draw the double arrow as

\draw [<->] (A1|-row2.mid) --node[below]{tw} (A2|-row2.mid);

The coordinate (A1|-row2.mid) is the point at the intersection of a vertical line through A1 and a horizontal line through row2.mid, i.e. it has the x-coordinate of the former and the y-coordinate of the latter.

enter image description here

\documentclass{article}
\usepackage{tikz-timing}
\begin{document}    
\begin{tikztimingtable}[timing/slope=.005, yscale=2]
    Comparator Out & 2L  0.8H8.2L 0.8H 11.2L\\
    One-Shot Out & 2L N(A1)  4H N(A2) 5L4H 8L\\
    \extracode
    %\horlines[] {0,1,5}
    \tableheader[]{}{Case3: Two input pulses, far apart}
    \draw [<->] (A1|-row2.mid) --node[below]{tw} (A2|-row2.mid);
\end{tikztimingtable}
\end{document}

Old answer

I'm not that familiar with tikz-timing, so there might be better ways of doing it, but here is one using the calc library to calculate the midpoints of the vertical lines of the pulse.

To quickly explain what ($(A1|-A2)!0.5!(A1)$) does. ($ ... $) with the calc library loaded means that what is between the dollar signs is a calculation of sorts, as described in the manual. (A1|-A2) is a coordinate specification, and it defines the coordinate that has the x-coordinate of A1, and the y-coordinate of A2, so the top left corner of the pulse. Finally the syntax $(<first coord>)!<fraction>!(<second coord>)$ means that the result of the calculation is the coordinate that is <fraction> the way from the first to the second coordinate.

And to place a node below a line, place node[below]{..} right after a -- in a path, as shown in the example below.

\documentclass{article}
\usepackage{tikz-timing}
\usetikzlibrary{calc}
\begin{document}


\begin{tikztimingtable}[timing/slope=.005, yscale=2]
    Comparator Out & 2L  0.8H8.2L 0.8H 11.2L\\
    One-Shot Out & 2L N(A1)  4H N(A2) 5L4H 8L\\
    \extracode
    %\horlines[] {0,1,5}
    \tableheader[]{}{Case3: Two input pulses, far apart}
    \draw [<->] ($(A1|-A2)!0.5!(A1)$) -- node[below] {tw} ($(A2|-A1)!0.5!(A2)$);
\end{tikztimingtable}
\end{document}