我正在尝试使用 LibreOffice Draw 创建此表的 TikZ 版本。
我对 TikZ 还很陌生,不太清楚自己在做什么,但一直关注这里有一个例子并建立了下表:
\usepackage{xcolor,array}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{matrix,positioning}
\tikzset{
table/.style={
matrix of nodes,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={rectangle,draw=black,text width=2ex,align=center},
text depth=0.25ex,
text height=1ex,
nodes in empty cells
},
texto/.style={font=\footnotesize\sffamily},
title/.style={font=\small\sffamily}
}
\newcommand\CellText[2]{%
\node[texto,left=of mat#1,anchor=east]
at (mat#1.west)
{#2};
}
\newcommand\SlText[2]{%
\node[texto,left=of mat#1,anchor=south]
at ([xshift=3ex]mat#1.north)
{#2};
}
\newcommand\SIundertext[2]{%
\node[texto,left=of mat#1,anchor=east]
at ([xshift=3ex]mat#1.south)
{#2};
}
\newcommand\RowTitle[2]{%
\node[title,left=6.3cm of mat#1,anchor=west]
at (mat#1.north west)
{#2};
}
\begin{tikzpicture}[node distance =0pt and 0.5cm]
\matrix[table] (mat11)
{
& & |[fill=gray]| & |[fill=gray]|& & &|[fill=gray]|\\
};
\SlText{11-1-1}{0}
\SlText{11-1-2}{\ldots}
\SlText{11-1-3}{$h-1$}
\SlText{11-1-4}{$h$}
\SlText{11-1-5}{$h+1$}
\SlText{11-1-6}{\ldots}
\SlText{11-1-7}{$b$}
\SIundertext{11-1-1}{0}
\SIundertext{11-1-1}{0}
\SIundertext{11-1-2}{$\epsilon$}
\SIundertext{11-1-3}{$(h-2)\epsilon$}
\SIundertext{11-1-4}{$(h-1)\epsilon$}
\SIundertext{11-1-5}{$h\epsilon$}
\SIundertext{11-1-6}{$(h+1)\epsilon$}
\SIundertext{11-1-7}{$\xi\epsilon$}
\RowTitle{11}{Time bin};
\CellText{11-1-1}{Coverage};
\end{tikzpicture}
\end{document}
我想我的问题是:1. 我怎样才能使上面的文本垂直排列?2. 我怎样才能标记上面的文本?(Bin)3. 我怎样才能标记下面的文本?(Time)4. 我怎样才能修复下面的文本?
非常感谢您的帮助。
编辑,附加问题:我想您不知道有什么方法可以创建“破碎的桌子”之类的效果,其中省略号在哪里,或者有其他方法可以更明显地显示时间被打断了?
答案1
这是经过整理后的代码,更接近您想要的样子。
\documentclass{article}
\usepackage{xcolor,array}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\usetikzlibrary{calc}
\tikzset
{
table/.style={matrix of nodes,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={rectangle,
draw=black,
text width=2ex,
align=center,
minimum width=1.5cm
},
text depth=0.25ex,
text height=1ex,
nodes in empty cells
},
texto/.style={font=\footnotesize\sffamily},
title/.style={font=\small\sffamily},
my top text/.style={font=\small\sffamily},
my bottom text/.style={font=\sffamily\footnotesize}
}
\newcommand\CellText[2]{%
\node[texto,left=of mat#1,anchor=east]
at (mat#1.west)
{#2};
}
\newcommand\SlText[2]{\node[my top text,anchor=base] at ($(mat#1.north)+(0,1.0ex)$) {#2};}
\newcommand\SIundertext[2]{\node[my bottom text,anchor=base] at ($(mat#1.south west)-(0,2.0ex)$) {#2};}
\newcommand\RowTitle[2]{%
\node[title,left=6.3cm of mat#1,anchor=west]
at (mat#1.north west)
{#2};
}
\begin{document}
\begin{tikzpicture}[node distance=0pt and 0.5cm]
\matrix[table] (mat11) { & & |[fill=gray]| & |[fill=gray]| & & & |[fill=gray]| \\ };
\foreach \x/\y in {1/$0$,
2/$\ldots$,
3/$h-1$,
4/$h$,
5/$h+1$,
6/$\ldots$,
7/$b$}
{ \SlText{11-1-\x}{\y} }
\foreach \x/\y in {1/$0$,
2/$\epsilon$,
3/$(h-2)\epsilon$,
4/$(h-1)\epsilon$,
5/$h\epsilon$,
6/$(h+1)\epsilon$,
7/$\xi\epsilon$}
{ \SIundertext{11-1-\x}{\y} }
\node[my bottom text] at ($(mat11-1-7.south east)-(0,1.5ex)$) { $(\xi+1)\epsilon$ };
\node[my top text,anchor=base east] at ($(mat11-1-1.north west)-(2ex,0)+(0,1.0ex)$) {Bin};
\node[my bottom text,anchor=base east] at ($(mat11-1-1.south west)-(2ex,0)-(0,2.0ex)$) {Time};
\node[title,anchor=east] at ($(mat11-1-1.west)-(2cm,0)$) {Coverage};
\end{tikzpicture}
\end{document}
我做了一些更改。我建议您为自己的样式创建名称,以帮助传达它们的用途:例如my top text
vs. textto
。此外,您可以使用循环来迭代您想要与其文本配对的位置,而不是多次编写\SlText
或。(此外,为与包无关的宏编写可能会有点令人困惑。)我过去常常放大构成时间线的节点。\SIundertext
\foreach
\SI...
siunitx
minimum width=1.5cm
我使用该calc
库来帮助将文本定位在矩阵中节点的上方和下方。通常,对 TikZ 库的调用应该发生在序言中。
更新中断的时间线
我修改了代码轻微地在省略号处给人一种虚线的感觉:
\documentclass{article}
\usepackage{xcolor,array}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathmorphing}
\tikzset
{
table/.style={matrix of nodes,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={rectangle,
draw=black,
text width=2ex,
align=center,
minimum width=1.5cm
},
text depth=0.25ex,
text height=1ex,
nodes in empty cells
},
texto/.style={font=\footnotesize\sffamily},
title/.style={font=\small\sffamily},
my top text/.style={font=\small\sffamily},
my bottom text/.style={font=\sffamily\footnotesize}
}
\newcommand\CellText[2]{%
\node[texto,left=of mat#1,anchor=east]
at (mat#1.west)
{#2};
}
\newcommand\SlText[2]{\node[my top text,anchor=base] at ($(mat#1.north)+(0,1.0ex)$) {#2};}
\newcommand\SIundertext[2]{\node[my bottom text,anchor=base] at ($(mat#1.south west)-(0,2.0ex)$) {#2};}
\newcommand\RowTitle[2]{%
\node[title,left=6.3cm of mat#1,anchor=west]
at (mat#1.north west)
{#2};
}
\begin{document}
\begin{tikzpicture}[node distance=0pt and 0.5cm]
\matrix[table] (mat11) { & |[draw=none,alias=gap A]| & |[fill=gray]| & |[fill=gray]| & & |[draw=none,alias=gap B]| & |[fill=gray]| \\ };
\foreach \x/\y in {1/$0$,
3/$h-1$,
4/$h$,
5/$h+1$,
7/$b$}
{ \SlText{11-1-\x}{\y} }
\foreach \x/\y in {1/$0$,
2/$\epsilon$,
3/$(h-2)\epsilon$,
4/$(h-1)\epsilon$,
5/$h\epsilon$,
6/$(h+1)\epsilon$,
7/$\xi\epsilon$}
{ \SIundertext{11-1-\x}{\y} }
\node at (mat11-1-2.center) {$\ldots$};
\node at (mat11-1-6.center) {$\ldots$};
\node[my bottom text] at ($(mat11-1-7.south east)-(0,1.5ex)$) { $(\xi+1)\epsilon$ };
%% create ragged edges for ellipsis in time line
\coordinate (intrusion for box) at (2.75ex, 0 );
\coordinate (vertical border adj) at ( 0 , 0.2pt);
\coordinate (horizontal border adj) at (0.2pt, 0 );
\foreach \x in {A,B}{
\draw ($(gap \x.south west)+(intrusion for box)+(vertical border adj)$) --
($(gap \x.south west)+(horizontal border adj)+(vertical border adj)$) --
($(gap \x.north west)+(horizontal border adj)-(vertical border adj)$) --
($(gap \x.north west)+(intrusion for box)-(vertical border adj)$);
% \draw [decorate,decoration={random steps,segment length=1pt,amplitude=0.5pt}]
\draw [decorate,decoration={zigzag,segment length=4pt,amplitude=2pt}]
($(gap \x.north west)+(intrusion for box)-(vertical border adj)$) --
($(gap \x.south west)+(intrusion for box)+(vertical border adj)$);
\draw ($(gap \x.south east)-(intrusion for box)+(vertical border adj)$) --
($(gap \x.south east)-(horizontal border adj)+(vertical border adj)$) --
($(gap \x.north east)-(horizontal border adj)-(vertical border adj)$) --
($(gap \x.north east)-(intrusion for box)-(vertical border adj)$);
\draw [decorate,decoration={zigzag,segment length=4pt,amplitude=2pt}]
($(gap \x.north east)-(intrusion for box)-(vertical border adj)$) --
($(gap \x.south east)-(intrusion for box)+(vertical border adj)$);
}
\node[my top text,anchor=base east] at ($(mat11-1-1.north west)-(2ex,0)+(0,1ex)$) {Bin};
\node[my bottom text,anchor=base east] at ($(mat11-1-1.south west)-(2ex,0)-(0,2.0ex)$) {Time};
\node[title,anchor=east] at ($(mat11-1-1.west)-(2cm,0)$) {Coverage};
\end{tikzpicture}
\end{document}
产生
不是特别优雅,而且我敢肯定这不是您想要的效果。我会再努力一下。