具有垂直测量的均匀间距网格

具有垂直测量的均匀间距网格

我有以下代码在 tikz 中创建三个网格。

  • 我想用双箭头指示第一个网格的侧面,表示网格的高度,应该是 $2^{Q(n)+\lceil \log_2(s) \rceil}$。

  • 我还想均匀分布这三个网格,使它们之间的间距都相同。

预期结果如下图所示。表格中间的点不是必需的。

\begin{figure}[H]
\centering
\begin{minipage}{.3\textwidth}
\begin{tikzpicture}[scale=0.5, y=-1cm]
\draw[xstep=1,ystep=-1] (0,8) grid (3,0);
\node[label=$q_1$] at (0.5,0.15) {};
\node[label=$\ldots$] at (1.5,0.15) {};
\node[label=$q_s$] at (2.5,0.15) {};
\end{tikzpicture}
\end{minipage}
\hspace{1em}
\begin{minipage}{.3\textwidth}
\begin{tikzpicture}[scale=0.5, y=-1cm]
\draw[xstep=1,ystep=-1] (0,8) grid (5,0);
\node[label=$c_1$] at (0.5,0.15) {};
\node[label=$\ldots$] at (1.5,0.15) {};
\node[label=$\ldots$] at (2.5,0.15) {};
\node[label=$\ldots$] at (3.5,0.15) {};
\node[label=$c_{Q(n)}$] at (4.5,0.15) {};
\end{tikzpicture}
\end{minipage}
\hspace{1em}
\begin{minipage}{.3\textwidth}
\begin{tikzpicture}[scale=0.5, y=-1cm]
\draw[xstep=1,ystep=-1] (0,8) grid (5,0);
\node[label=$d_1$] at (0.5,0.15) {};
\node[label=$\ldots$] at (1.5,0.15) {};
\node[label=$\ldots$] at (2.5,0.15) {};
\node[label=$\ldots$] at (3.5,0.15) {};
\node[label=$d_{Q(n)}$] at (4.5,0.15) {};
\end{tikzpicture}
\end{minipage}
\end{figure}

在此处输入图片描述

答案1

您应该提供一个平均能量损失下次。这是带有报告文档类的工作示例。我稍微调整了网格顶部的标签绘图,将它们放在一个节点中。这样格式看起来更一致。我在左侧添加了箭头,并将标签置于 90 度。因此,它不会占用太多水平空间。希望这是你想要的。

代码:

\documentclass{report}
\usepackage{tikz}
\usepackage{float}
\usepackage{showframe} % show the margin boundary
\usepackage{lipsum} % Create dummy text
\begin{document}
\begin{figure}[H]
\centering
\begin{minipage}{.3\textwidth}
\centering\begin{tikzpicture}[scale=0.5, y=-1cm]
\draw[xstep=1,ystep=-1] (0,8) grid (3,0);
\node [anchor=south west] at (0,0) {$q_1~\ldots~q_s$};
\draw (-0.5,0) -- (-1.2,0); %top rule
\draw (-0.5,8) -- (-1.2,8); %bottom rule
\draw [latex-latex] (-1,0) --node[rotate=90,above] {$2^{Q(n)+\lceil \log_2(s) \rceil}$} (-1,8); %arrows and label in 90 degree
\end{tikzpicture}
\end{minipage}
\hspace{1em}
\begin{minipage}{.3\textwidth}
\centering\begin{tikzpicture}[scale=0.5, y=-1cm]
\draw[xstep=1,ystep=-1] (0,8) grid (5,0);
\node[anchor=south west] at (0,0) {$c_1~\ldots\ldots\ldots~c_{Q(n)}$};
\end{tikzpicture}
\end{minipage}
\hspace{1em}
\begin{minipage}{.3\textwidth}
\centering\begin{tikzpicture}[scale=0.5, y=-1cm]
\draw[xstep=1,ystep=-1] (0,8) grid (5,0);
\node[anchor=south west] at (0,0) {$d_1~\ldots\ldots\ldots~d_{Q(n)}$};
\end{tikzpicture}
\end{minipage}
\end{figure}
\lipsum[1]
\end{document}

输出: 在此处输入图片描述

答案2

我建议将所有三个网格放在一张图片中以确保良好的对齐。

我制作了一个新的节点样式,名为 ,mygrid以便于放置网格。该样式绘制节点并将网格添加为path picture。此外,还有一种样式block可以用点覆盖网格。

在此处输入图片描述

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning, arrows.meta}

\tikzset{
    block/.style={fill=white, minimum width=2.1cm, minimum height=2.1cm, inner sep=0pt, path picture={\draw[very thick, loosely dotted](path picture bounding box.east)--(path picture bounding box.west);}},
    mygrid/.style={draw, minimum width=2cm, minimum height=6cm, path picture={\draw[step=.5](path picture bounding box.south east)grid(path picture bounding box.north west); \node[fill=white, minimum width=2.1cm, minimum height=2.1cm]{};}}
}

\begin{document}

\[
\begin{tikzpicture}[node distance=2cm]
\node[mygrid, label=above:$g_0\quad\dots\quad g_s$](A){}; \node[block]{};
\node[mygrid, right=of A, label=above:$\quad c_1\ \ \dots\ c_{Q(n)}$](B){}; \node[block] at (B){};
\node[mygrid, right=of B, label=above:$\quad d_1\ \ \dots\ d_{Q(n)}$](C){}; \node[block] at (C){};
\draw[<->] ([xshift=-5mm]A.south west)--node[above, sloped]{$2^{Q(n)+\lceil \log_2(s) \rceil}$}([xshift=-5mm]A.north west);
\end{tikzpicture}
\]

\end{document}

相关内容