
授業用のタイミング図を作成するのに tikz-timing が気に入っています。ただし、タイミング図に番号付きの時間軸を追加する方法がわかりません。これは、テストベンチ設計の基本を示し、図の対応を Verilog ソースの線で示したい場合に便利です。TikZ オーバーレイが機能すると思いますが、私はそれほどプロではないので、数字が自動的に追加されるものを好みます。垂直の補助線を使用しているので、その上または下に何らかの方法で数字を追加できればすばらしいと思います。
答え1
では専用のマクロは提供されていませんtikz-timing
が、提供されているサイズ マクロとノードを使用して、このようなラベル付き軸を描画することは可能です。
行数は で指定され\nrows
、最も幅の広い行は で指定されます\twidth
。行は と呼ばれるノードとしても提供されrow<number>
、最後の行ノードも という名前が付けられますlast row
。追加のマテリアルを描画するには、以下の例に示すように、最後の行の後の 環境に描画コードを配置します。詳細については、extracode
のマニュアルを参照してください。tikz-timing
\documentclass[border=2mm]{standalone}
\usepackage{tikz-timing}
\begin{document}
\begin{tikztimingtable}
clk & 20{C} \\
sig & 5{HLZD{}} \\
\begin{extracode}
\begin{background}
\vertlines[help lines]{}
\horlines[help lines]{}
\show\horlines
\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}};
\end{background}
%\tablegrid
\end{extracode}
\end{tikztimingtable}%
\end{document}
これをより頻繁に必要とする場合は、独自のマクロを定義できます。
\documentclass[border=2mm,png]{standalone}
\usepackage{tikz-timing}
\newcommand{\timingaxis}[1][]{%
\begin{scope}[#1]
\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}};
}
\end{scope}
}
\tikzset{%
timing/table/axis/.style={->,>=latex},
timing/table/axis ticks/.style={},
}
\begin{document}
\begin{tikztimingtable}
clk & 20{C} \\
sig & 5{HLZD{}} \\
\begin{extracode}
\timingaxis\relax
\end{extracode}
\end{tikztimingtable}%
\end{document}
答え2
pgfplots
環境を使用した別の可能な方法はaxis
次のようになります。
...この MWE を使用します:
\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{tikz-timing}
\usetikzlibrary{intersections} %% named intersections
\usetikzlibrary{fit}
\usetikzlibrary{calc}
\makeatletter
% http://tex.stackexchange.com/questions/33703/extract-x-y-
\newcommand{\gettikzxy}[3]{%
\tikz@scan@one@point\pgfutil@firstofone#1\relax
\edef#2{\the\pgf@x}%
\edef#3{\the\pgf@y}%
}
\makeatother
\begin{document}
\begin{tikzpicture}[timing/picture]%,timing/nodes/advanced]
\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!
\gettikzxy{(refsize)}{\rx}{\ry}
% re-convert \rx back to length, so can scale it directly in style= below:
\newlength{\trx}
\setlength{\trx}{\rx}
\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
\end{axis}
\end{tikzpicture}
\end{document}
グラフの単位をグラフに表示されている単位に合わせるために、少し計算を行う必要があることに注意してください\timing
。上記の例はピクセル単位で完璧に揃えられないかもしれませんが、少なくとも設定はそれほど難しくないように見えます...