tikz - 用矩形压平/平齐线

tikz - 用矩形压平/平齐线

下面我画了下面的图。

为了扩展正方形,我在角角处附加了线,即 node.45。虽然很难看出来,但它们并不完全在一条线上。如何用线条齐平/压平矩形?有没有简单的方法?正方形矩形是自定义节点,我复制了代码。

tikz 图片

我使用了以下操作:

\node[square, draw, anchor = west, minimum width=2em, minimum height=2.6em] (w) at (v.east) {$s_{t-3}$};
\draw (w.45) -- ++  (2.6em,0em);

谢谢你的提示

答案1

使用chainsfitpositioning库:

\documentclass[border=2mm]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{chains,
                fit,
                positioning}

\begin{document}
    \begin{tikzpicture}[
node distance = 0mm,
  start chain = going right,
     M/.style = {minimum size=11mm, on chain},
     N/.style = {M, draw, inner sep=0mm, fit=#1},
   FIT/.style = {draw, thick, inner sep=0mm, fit=#1},
                        ]
\foreach \i [count=\j] 
            in {s_t,s_{t-1},s_{t-2},s_{t-3}, ,\dotsm, ,
                s_{t-k},s_{t-1},s_{t-2},s_{t-3}, ,\dotsm, ,s_{t-k}} 
\node (m\j) [M] {$\i$};

\foreach \i in {1,...,4,8,9,10,11,15}
\node       [N=(m\i)] {};

\node   [FIT=(m1) (m15)] {};
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容