忽略 TikZ 图中节点中文本所占用的空间

忽略 TikZ 图中节点中文本所占用的空间

我不希望节点中的文本占据水平空间。(我故意将文本写得很长,以显示 TikZ 图表如何被推到左边距。)我将文本括在命令中\makebox[0pt][l]

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}

\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc,intersections,positioning,quotes,decorations.pathreplacing,arrows.meta}
    
\begin{document}

\noindent \hspace*{\fill}
\begin{tikzpicture}

%The board of length 17 is filled with square tiles.
\path (0,0) coordinate (A_1_of_17_board) (0.5,0) coordinate (B_1_of_17_board) (1,0) coordinate (C_1_of_17_board) (1.5,0) coordinate (D_1_of_17_board) (2,0) coordinate (E_1_of_17_board) (2.5,0) coordinate (F_1_of_17_board) (3,0) coordinate (G_1_of_17_board)
(3.5,0) coordinate (H_1_of_17_board) (4,0) coordinate (I_1_of_17_board) (4.5,0) coordinate (J_1_of_17_board) (5,0) coordinate (K_1_of_17_board)
(5.5,0) coordinate (L_1_of_17_board) (6,0) coordinate (M_1_of_17_board) (6.5,0) coordinate (N_1_of_17_board)
(7,0) coordinate (O_1_of_17_board) (7.5,0) coordinate (P_1_of_17_board) (8,0) coordinate (Q_1_of_17_board) (8.5,0) coordinate (R_1_of_17_board)
(0,0.5) coordinate (A_2_of_17_board) (0.5,0.5) coordinate (B_2_of_17_board) (1,0.5) coordinate (C_2_of_17_board)
(1.5,0.5) coordinate (D_2_of_17_board) (2,0.5) coordinate (E_2_of_17_board) (2.5,0.5) coordinate (F_2_of_17_board)
(3,0.5) coordinate (G_2_of_17_board) (3.5,0.5) coordinate (H_2_of_17_board) (4,0.5) coordinate (I_2_of_17_board)
(4.5,0.5) coordinate (J_2_of_17_board) (5,0.5) coordinate (K_2_of_17_board) (5.5,0.5) coordinate (L_2_of_17_board)
(6,0.5) coordinate (M_2_of_17_board) (6.5,0.5) coordinate (N_2_of_17_board) (7,0.5) coordinate (O_2_of_17_board)
(7.5,0.5) coordinate (P_2_of_17_board) (8,0.5) coordinate (Q_2_of_17_board) (8.5,0.5) coordinate (R_2_of_17_board);
\path[fill=yellow] (A_1_of_17_board) -- (B_1_of_17_board) -- (B_2_of_17_board) -- (A_2_of_17_board) -- cycle;
\path[fill=yellow] (B_1_of_17_board) -- (C_1_of_17_board) -- (C_2_of_17_board) -- (B_2_of_17_board) -- cycle;
\path[fill=yellow] (C_1_of_17_board) -- (D_1_of_17_board) -- (D_2_of_17_board) -- (C_2_of_17_board) -- cycle;
\path[fill=yellow] (D_1_of_17_board) -- (E_1_of_17_board) --  (E_2_of_17_board) -- (D_2_of_17_board) -- cycle;
\path[fill=Cyan!40!blue, fill opacity=0.4] (E_1_of_17_board) -- (G_1_of_17_board) -- (G_2_of_17_board) -- (E_2_of_17_board) -- cycle;
\path[fill=yellow] (G_1_of_17_board) -- (H_1_of_17_board) -- (H_2_of_17_board) -- (G_2_of_17_board) -- cycle;
\path[fill=yellow] (H_1_of_17_board) -- (I_1_of_17_board) -- (I_2_of_17_board) -- (H_2_of_17_board) -- cycle;
\path[fill=yellow] (I_1_of_17_board) -- (J_1_of_17_board) -- (J_2_of_17_board) -- (I_2_of_17_board) -- cycle;
\path[fill=yellow] (J_1_of_17_board) -- (K_1_of_17_board) -- (K_2_of_17_board) -- (J_2_of_17_board) -- cycle;
\path[fill=Cyan!40!blue, fill opacity=0.4] (K_1_of_17_board) -- (M_1_of_17_board) -- (M_2_of_17_board) -- (K_2_of_17_board) -- cycle;
\path[fill=yellow] (M_1_of_17_board) -- (N_1_of_17_board) -- (N_2_of_17_board) -- (M_2_of_17_board) -- cycle;
\path[fill=yellow] (N_1_of_17_board) -- (O_1_of_17_board) -- (O_2_of_17_board) -- (N_2_of_17_board) -- cycle;
\path[fill=yellow] (O_1_of_17_board) -- (P_1_of_17_board) -- (P_2_of_17_board) -- (O_2_of_17_board) -- cycle;
\path[fill=yellow] (P_1_of_17_board) -- (Q_1_of_17_board) -- (Q_2_of_17_board) -- (P_2_of_17_board) -- cycle;
\path[fill=yellow] (Q_1_of_17_board) -- (R_1_of_17_board) -- (R_2_of_17_board) -- (Q_2_of_17_board) -- cycle;
\draw (A_1_of_17_board) -- (R_1_of_17_board) -- (R_2_of_17_board) -- (A_2_of_17_board) -- cycle;
\draw (B_1_of_17_board) -- (B_2_of_17_board);
\draw (C_1_of_17_board) -- (C_2_of_17_board);
\draw (D_1_of_17_board) -- (D_2_of_17_board);
\draw (E_1_of_17_board) -- (E_2_of_17_board);
\draw[loosely dash dot] (F_1_of_17_board) -- (F_2_of_17_board);
\draw (G_1_of_17_board) -- (G_2_of_17_board);
\draw (H_1_of_17_board) -- (H_2_of_17_board);
\draw (I_1_of_17_board) -- (I_2_of_17_board);
\draw (J_1_of_17_board) -- (J_2_of_17_board);
\draw (K_1_of_17_board) -- (K_2_of_17_board);
\draw[loosely dash dot] (L_1_of_17_board) -- (L_2_of_17_board);
\draw (M_1_of_17_board) -- (M_2_of_17_board);
\draw (N_1_of_17_board) -- (N_2_of_17_board);
\draw (O_1_of_17_board) -- (O_2_of_17_board);
\draw (P_1_of_17_board) -- (P_2_of_17_board);
\draw (Q_1_of_17_board) -- (Q_2_of_17_board);


%Arrows are drawn to the right side of the fifth cell and the eleventh cell to indicate the tiling of the 17-board is not breakable
%immediately after 6 - 1 = 5 cells nor immediately after 2(6) - 1 = 11 cells.
\path node[anchor=south, text width=0.4\linewidth, align=center, inner sep=0.15] at ($(I_2_of_17_board) +(0,1.75+0.15)$){unbreakable};
\draw[fill] ($(I_2_of_17_board) +(0,1.75)$) circle (1.5pt);
\draw[->, >={Stealth[scale=1.5]}] ($(I_2_of_17_board) +(0,1.75)$) {[rounded corners=10pt] -- ++(0,-1) -- ++(-1.5,0)} -- ($(F_2_of_17_board) +(0,0.1)$);
\draw[->, >={Stealth[scale=1.5]}] ($(I_2_of_17_board) +(0,1.75)$) {[rounded corners=10pt] -- ++(0,-1) -- ++(1.5,0)} -- ($(L_2_of_17_board) +(0,0.1)$);
%
\path node[anchor=south, text width=0.4\linewidth, align=center, inner sep=0.15] at ($(R_2_of_17_board) +(0,0.75+0.15)$){\makebox[0pt][l]{end of the board; so, the tiling is breakable}};
\draw[->, >={Stealth[scale=1.5]}] ($(R_2_of_17_board) +(0,0.75)$) -- ($(R_2_of_17_board) +(0,0.1)$);
\end{tikzpicture}
\hspace{\fill}

\end{document}

答案1

如果我理解正确的话,这就是你想要的。

\documentclass{amsart}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage[dvipsnames]{xcolor}

\usepackage{tikz}
\usetikzlibrary{calc,intersections,positioning,quotes,decorations.pathreplacing,arrows.meta}
\usepackage{showframe}
\begin{document}

\noindent \hspace*{\fill}
\begin{tikzpicture}

%The board of length 17 is filled with square tiles.
\path (0,0) coordinate (A_1_of_17_board) (0.5,0) coordinate (B_1_of_17_board) (1,0) coordinate (C_1_of_17_board) (1.5,0) coordinate (D_1_of_17_board) (2,0) coordinate (E_1_of_17_board) (2.5,0) coordinate (F_1_of_17_board) (3,0) coordinate (G_1_of_17_board)
(3.5,0) coordinate (H_1_of_17_board) (4,0) coordinate (I_1_of_17_board) (4.5,0) coordinate (J_1_of_17_board) (5,0) coordinate (K_1_of_17_board)
(5.5,0) coordinate (L_1_of_17_board) (6,0) coordinate (M_1_of_17_board) (6.5,0) coordinate (N_1_of_17_board)
(7,0) coordinate (O_1_of_17_board) (7.5,0) coordinate (P_1_of_17_board) (8,0) coordinate (Q_1_of_17_board) (8.5,0) coordinate (R_1_of_17_board)
(0,0.5) coordinate (A_2_of_17_board) (0.5,0.5) coordinate (B_2_of_17_board) (1,0.5) coordinate (C_2_of_17_board)
(1.5,0.5) coordinate (D_2_of_17_board) (2,0.5) coordinate (E_2_of_17_board) (2.5,0.5) coordinate (F_2_of_17_board)
(3,0.5) coordinate (G_2_of_17_board) (3.5,0.5) coordinate (H_2_of_17_board) (4,0.5) coordinate (I_2_of_17_board)
(4.5,0.5) coordinate (J_2_of_17_board) (5,0.5) coordinate (K_2_of_17_board) (5.5,0.5) coordinate (L_2_of_17_board)
(6,0.5) coordinate (M_2_of_17_board) (6.5,0.5) coordinate (N_2_of_17_board) (7,0.5) coordinate (O_2_of_17_board)
(7.5,0.5) coordinate (P_2_of_17_board) (8,0.5) coordinate (Q_2_of_17_board) (8.5,0.5) coordinate (R_2_of_17_board);
\path[fill=yellow] (A_1_of_17_board) -- (B_1_of_17_board) -- (B_2_of_17_board) -- (A_2_of_17_board) -- cycle;
\path[fill=yellow] (B_1_of_17_board) -- (C_1_of_17_board) -- (C_2_of_17_board) -- (B_2_of_17_board) -- cycle;
\path[fill=yellow] (C_1_of_17_board) -- (D_1_of_17_board) -- (D_2_of_17_board) -- (C_2_of_17_board) -- cycle;
\path[fill=yellow] (D_1_of_17_board) -- (E_1_of_17_board) --  (E_2_of_17_board) -- (D_2_of_17_board) -- cycle;
\path[fill=Cyan!40!blue, fill opacity=0.4] (E_1_of_17_board) -- (G_1_of_17_board) -- (G_2_of_17_board) -- (E_2_of_17_board) -- cycle;
\path[fill=yellow] (G_1_of_17_board) -- (H_1_of_17_board) -- (H_2_of_17_board) -- (G_2_of_17_board) -- cycle;
\path[fill=yellow] (H_1_of_17_board) -- (I_1_of_17_board) -- (I_2_of_17_board) -- (H_2_of_17_board) -- cycle;
\path[fill=yellow] (I_1_of_17_board) -- (J_1_of_17_board) -- (J_2_of_17_board) -- (I_2_of_17_board) -- cycle;
\path[fill=yellow] (J_1_of_17_board) -- (K_1_of_17_board) -- (K_2_of_17_board) -- (J_2_of_17_board) -- cycle;
\path[fill=Cyan!40!blue, fill opacity=0.4] (K_1_of_17_board) -- (M_1_of_17_board) -- (M_2_of_17_board) -- (K_2_of_17_board) -- cycle;
\path[fill=yellow] (M_1_of_17_board) -- (N_1_of_17_board) -- (N_2_of_17_board) -- (M_2_of_17_board) -- cycle;
\path[fill=yellow] (N_1_of_17_board) -- (O_1_of_17_board) -- (O_2_of_17_board) -- (N_2_of_17_board) -- cycle;
\path[fill=yellow] (O_1_of_17_board) -- (P_1_of_17_board) -- (P_2_of_17_board) -- (O_2_of_17_board) -- cycle;
\path[fill=yellow] (P_1_of_17_board) -- (Q_1_of_17_board) -- (Q_2_of_17_board) -- (P_2_of_17_board) -- cycle;
\path[fill=yellow] (Q_1_of_17_board) -- (R_1_of_17_board) -- (R_2_of_17_board) -- (Q_2_of_17_board) -- cycle;
\draw (A_1_of_17_board) -- (R_1_of_17_board) -- (R_2_of_17_board) -- (A_2_of_17_board) -- cycle;
\draw (B_1_of_17_board) -- (B_2_of_17_board);
\draw (C_1_of_17_board) -- (C_2_of_17_board);
\draw (D_1_of_17_board) -- (D_2_of_17_board);
\draw (E_1_of_17_board) -- (E_2_of_17_board);
\draw[loosely dash dot] (F_1_of_17_board) -- (F_2_of_17_board);
\draw (G_1_of_17_board) -- (G_2_of_17_board);
\draw (H_1_of_17_board) -- (H_2_of_17_board);
\draw (I_1_of_17_board) -- (I_2_of_17_board);
\draw (J_1_of_17_board) -- (J_2_of_17_board);
\draw (K_1_of_17_board) -- (K_2_of_17_board);
\draw[loosely dash dot] (L_1_of_17_board) -- (L_2_of_17_board);
\draw (M_1_of_17_board) -- (M_2_of_17_board);
\draw (N_1_of_17_board) -- (N_2_of_17_board);
\draw (O_1_of_17_board) -- (O_2_of_17_board);
\draw (P_1_of_17_board) -- (P_2_of_17_board);
\draw (Q_1_of_17_board) -- (Q_2_of_17_board);


%Arrows are drawn to the right side of the fifth cell and the eleventh cell to indicate the tiling of the 17-board is not breakable
%immediately after 6 - 1 = 5 cells nor immediately after 2(6) - 1 = 11 cells.
\path node[anchor=south, text width=0.4\linewidth, align=center, inner sep=0.15] at ($(I_2_of_17_board) +(0,1.75+0.15)$){unbreakable};
\draw[fill] ($(I_2_of_17_board) +(0,1.75)$) circle (1.5pt);
\draw[->, >={Stealth[scale=1.5]}] ($(I_2_of_17_board) +(0,1.75)$) {[rounded corners=10pt] -- ++(0,-1) -- ++(-1.5,0)} -- ($(F_2_of_17_board) +(0,0.1)$);
\draw[->, >={Stealth[scale=1.5]}] ($(I_2_of_17_board) +(0,1.75)$) {[rounded corners=10pt] -- ++(0,-1) -- ++(1.5,0)} -- ($(L_2_of_17_board) +(0,0.1)$);
%
\begin{scope}[overlay]
\path node[anchor=south, text width=0.4\linewidth, align=center, inner sep=0.15] at ($(R_2_of_17_board) +(0,0.75+0.15)$){end of the board; so, the tiling is breakable};
\end{scope}
\draw[->, >={Stealth[scale=1.5]}] ($(R_2_of_17_board) +(0,0.75)$) -- ($(R_2_of_17_board) +(0,0.1)$);
\end{tikzpicture}
\hspace{\fill}

\end{document}

在此处输入图片描述

答案2

利用 TiZ 库chains可以以更简洁的方式绘制您的图像:

\documentclass{amsart}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains}

\begin{document}
    \begin{tikzpicture}[
node distance = 17mm and 0mm,
  start chain = n going right,
   arr/.style = {-Stealth, rounded corners=4mm, shorten >=2pt},
   box/.style = {draw, fill=#1, minimum size=6mm, 
                 inner sep=0pt, outer sep=0pt, 
                 node contents = {},
                 on chain},
   dsh/.style = {dash pattern=on 2pt off 4pt, cyan, thick},
   dot/.style = {circle, draw, fill, inner sep=2pt,
                 node contents={}}
                        ]
\foreach \i in  {yellow, yellow, yellow, yellow,
                cyan, cyan,
                yellow, yellow, yellow, yellow,
                cyan, cyan,
                yellow, yellow, yellow, yellow, yellow}
\node[box=\i];
\draw[dsh]  (n-5.north east) -- (n-5.south east);
\draw[dsh]  (n-11.north east) -- (n-11.south east);

\node (d) [dot, label=unbreakable,
           above=of n-8.north east];           
%
\draw[arr]  (d.south) -- ++ (0,-0.7) -| (n-5.north east);
\draw[arr]  (d.south) -- ++ (0,-0.7) -| (n-11.north east);
\draw[arr]  (n-17.north east) ++ (0,1) node[above right,
                                           align=left] {end of the board;\\ 
                                                        so, the tiling is breakable}
                              -- (n-17.north east);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容