0

I have text in a node that I would like to occupy no horizontal space. (I intentionally made the text long to show how the TikZ diagram was shoved to the left margin.) I enclosed the text in a \makebox[0pt][l] command.

\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}
2
  • 1
    Not related but didn't you think of a more efficient way of drawing a board of square tiles? With a matrix of nodes, or even with a foreach loop?
    – SebGlav
    Jun 18 at 20:09
  • 1
    @SebGlav I know that this is inefficient code.
    – user143462
    Jun 18 at 20:11

2 Answers 2

1

If I understand you correctly, This is what you want.

\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}

enter image description here

3
  • I think that is exactly what I want. How did you get the space occupied by the text to be ignored? Why didn't the \makebox command work for me?
    – user143462
    Jun 18 at 19:35
  • 1
    @user143462 overlay option make the whole scope doesn't take space. \makebox make the content in the box without taking space, however the node in the tikz still occupy space
    – Tom
    Jun 18 at 19:48
  • I just compiled the code except I removed the second arrow pointing to the end of the board and I removed the text from the second node. So, I had \makebox[0pt][l]{}. It does align with the tiling obtained from my original code. This is the first time for me hearing that an empty node occupies space. Thanks for your help!
    – user143462
    Jun 18 at 20:09
1

By exploiting of TikZ librariy chains your image can be drawn on much more concise way:

\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}

enter image description here

2
  • So cute! Great job!
    – projetmbc
    Jun 19 at 8:41
  • @projetmbc, and so short and clear code ;-) [just jok 😉]
    – Zarko
    Jun 19 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.