我正在使用 tikz-timing 绘制时序图。我的最后一个图有点大,所以我在寻找分隔符来提高可读性。一些 HDL 模拟器和波形查看器支持该功能来对信号进行分组。
我当前的实现是硬编码的,我正在寻找一些关于如何概括此功能的建议。
我当前的代码如下所示:
\documentclass[convert={density=600,size=2000x800,outext=.png}]{standalone}
% Document encoding, language, hyphenation, bibliography, ...
\usepackage[utf8]{inputenc} % UTF-8 tex file input incoding
\usepackage[T1]{fontenc} % Type1 font encoding
\usepackage[ngerman]{babel} % new german writing rules; must be loaded before microtype
% general packages
\usepackage{courier} % set courier font as default for teletype writer (texttt, ttfamily, ...)
\usepackage[usenames,svgnames,table]{xcolor} % load colors and color-names
% ext. includes, graphics, drawings, diagrams, timing
\usepackage{pgf} % primitive drawing library
\usepackage{tikz} % PGF frontend, drawing macros
\usetikzlibrary{arrows.meta} % sublibrary extended arrows
\usepackage{tikz-timing} % spezial TikZ library for waveform/timing diagrams
\usetikztiminglibrary{advnodes} % sublibrary for advanced anchor nodes
\usetikztiminglibrary{counters} % sublibrary for automated content generation
\usetikztiminglibrary{clockarrows} % sublibrary for for arrows on rising/falling edges
\usetikztiminglibrary{either} % sublibrary for new either symbol
\usetikztiminglibrary{columntype} % sublibrary for
\usetikztiminglibrary{overlays} % sublibrary for overlay generation
\usetikztiminglibrary{nicetabs} % sublibrary for better looking timingtables
\makeatletter % setting math codes
\mathcode`,="013B % set margin for integer to fractional part delimiter sign in numbers; don't interpret comma as list delimiter
\makeatother
\begin{document}
\begin{tikztimingtable}[
timing/table/header/.style={font=\bf},
timing/wscale=2,
timing/nice tabs,
>=Latex, % override tikz arrows to LaTeX default arrows
]
\\ % empty line for time scale
% section A
RefClock\_150MHz & h 58{c} 13c 92{c} \\
\\ % empty line for divider
% section B
PowerDown & [thick,violet] lN(BA1)h 36H hN(BA2)l 44L \\
PowerDownDone & [thick,orange] 28L N(BB1) 8H 8H N(BB2) 38L \\
\\ % empty line for time scale
\extracode
\makeatletter
\tableheader{Signalname}{Signalverlauf}
\tablerules
% time scale
\pgfmathsetmacro\twidthnew{\twidth/2}
\pgfmathsetmacro\nrowsnew{76}
\draw[->,thick] (0,0) -- +(\twidth+1,0);
\draw[->,thick] (0,-\nrowsnew-1) -- +(\twidth+1,0);
\foreach \n in {0,1,...,30}
\pgfmathsetmacro\nnew{int(\n*2)}
\draw(\nnew,-0.2) -- +(0,.4) node[above,inner sep=2pt] {\scalebox{0.75}{\n}}
(\nnew,-\nrowsnew-1+0.2) -- +(0,-.4) node[below,inner sep=2pt] {\scalebox{0.75}{\n}};
\foreach \n in {36,37,...,\twidthnew}
\pgfmathsetmacro\nnew{int(\n*2)}
\draw(\nnew,-0.2) -- +(0,.4) node[above,inner sep=2pt] {\scalebox{0.75}{\n}}
(\nnew,-\nrowsnew-1+0.2) -- +(0,-.4) node[below,inner sep=2pt] {\scalebox{0.75}{\n}};
% background help lines
\begin{background}[gray,semitransparent,semithick]
\horlines{2,4,5,...,11,13,14,15,17,18,...,21,23,24,...,30,32,33,...,40,42,43,...,46}
\vertlines{0,2,...,60,72,74,...,\twidth}
\shade[right color=bgred,left color=bgred] (-18,-2.3) rectangle +(\twidth+18,-1.2);
\shade[right color=bgred,left color=bgred] (-18,-17.5) rectangle +(\twidth+18,-1.2);
\shade[right color=bgred,left color=bgred] (-18,-24.3) rectangle +(\twidth+18,-1.2);
\shade[right color=bgred,left color=bgred] (-18,-34.3) rectangle +(\twidth+18,-1.2);
\shade[right color=bgred,left color=bgred] (-18,-49.6) rectangle +(\twidth+18,-1.2);
\shade[right color=bgred,left color=bgred] (-18,-66.4) rectangle +(\twidth+18,-1.2);
\end{background}
\begin{pgfonlayer}{background}
\node[anchor=north west,inner sep=.5pt,fgred] at (-18,-2.3) {Transceiver Interface};
\node[anchor=north west,inner sep=.5pt,fgred] at (-18,-17.5) {Synchronized Interface};
\node[anchor=north west,inner sep=.5pt,fgred] at (-18,-24.3) {PowerDown Control};
\node[anchor=north west,inner sep=.5pt,fgred] at (-18,-34.3) {ClockNet / CPLL Control};
\node[anchor=north west,inner sep=.5pt,fgred] at (-18,-49.6) {GTX Reset Control};
\node[anchor=north west,inner sep=.5pt,fgred] at (-18,-66.4) {UserLogic / FSM Control};
\end{pgfonlayer}
\end{tikztimingtable}
\end{document}
最后 16 行描述了分隔线。我想使用锚点来计算矩形框和文本节点,但我无法找到获取正确坐标的方法。
最好的解决办法是什么?
我认为最好的解决方案是有一个\divider{text}
可以像这样放入空行的宏。
\\ % empty line for time scale
RefClock\_150MHz & h 58{c} 13c 92{c} \\
\divider{Transceiver Interface} \\
PowerDown & [thick,violet] lN(BA1)h 36H hN(BA2)l 44L \\
PowerDownDone & [thick,orange] 28L N(BB1) 8H 8H N(BB2) 38L \\
第二最佳的解决方案是什么?
我认为拥有一个\divider[linenumber]{text}
环境宏\begin{background}
也可以解决这个问题:)。
\begin{background}[gray,semitransparent,semithick]
\horlines{2,4,5,...,11,13,14,15,17,18,...,21,23,24,...,30,32,33,...,40,42,43,...,46}
\vertlines{0,2,...,60,72,74,...,\twidth}
\divider[color=bgred](2){Transceiver Interface};
\end{background}
PS
如果还有这样的时间尺度宏,那就锦上添花了:)
答案1
更新
现在\divider{text}
执行以下操作:
- 创建一个名为的节点
text
; - 创建一个名为
left
共享 y 坐标的节点(text)
; - 创建一个名为
right
共享 y 坐标的节点(text)
; banner
创建一个名为span the table from(left)
to 的节点(right)
;- 在里面创建一个节点
(banner)
并排版text
。 - 由于在表完成之前我们不知道它的宽度,因此除 之外的所有节点
(text)
都是在 之后创建的\extracode
。 - 如果有多个
\divider
,则相应地创建节点,并与相应的母节点。
\documentclass[border=60,tikz]{standalone}
\usepackage{tikz-timing}
\usetikzlibrary{fit}
\begin{document}
\makeatletter\gdef\dividers{}
\def\divider#1{
N(#1)@{
\g@addto@macro\dividers{
\path(#1)-|node(left){}(all labels.west)(#1)-|node[shift={(0,1)}](right){}(all rows.east)
node(banner)[fill=red,opacity=.2,inner sep=0,fit=(left.center)(right.center)]{}
(banner.west)node[red!80!black,right](text){\scriptsize #1};
}
}
}
\begin{tikztimingtable}[timing/wscale=2]
\\
RefClock\_150MHz & h58{c}13c92{c} \\
& \divider{Transceiver Interface} \\
PowerDown & [thick,violet]lN(BA1)h36HhN(BA2)l44L \\
PowerDownDone & [thick,orange]28LN(BB1)8H8HN(BB2)38L \\
& \divider{Synchronized Interface} \\
CC\_Power Down & [thick,orange]2LN(CA1)37HN(CA2)43L \\
\\
\extracode
\tableheader{Signalname}{Signalverlauf}\tablerules
\draw[blue,->](BA1)to[out=0,in=180](CA1);
\fulltablegrid
\dividers
\end{tikztimingtable}
\end{document}
旧答案
让我们开始吧。
\documentclass[border=60,tikz]{standalone}
\usepackage{tikz-timing}
\begin{document}
\def\strut{\large\vphantom{/}}
\begin{tikztimingtable}[timing/wscale=2]
\\
RefClock\_150MHz & h58{c}13c92{c} \\
& [opacity=0]0D{[fill=red,text=white,opacity=1,xshift=-8cm,right,text width=80cm]\strut\Large Transceiver Interface} \\
PowerDown & [thick,violet]lN(BA1)h36HhN(BA2)l44L \\
PowerDownDone & [thick,orange]28LN(BB1)8H8HN(BB2)38L \\
& [opacity=0]0D{[fill=red,text=white,opacity=1,xshift=-8cm,right,text width=80cm]\strut\Large Synchronized Interface} \\
CC\_Power Down & [thick,orange]2LN(CA1)37HN(CA2)43L \\
\\
\extracode
\tableheader{Signalname}{Signalverlauf}\tablerules
\draw[blue,->](BA1)to[out=0,in=180](CA1);
\begin{background}[gray,semitransparent,semithick]
\horlines{1,...,8}\vertlines{0,2,...,60,72,74,...,\twidth}
\end{background}
\end{tikztimingtable}
\end{document}