如何使 9 x 9 的表格旋转?

如何使 9 x 9 的表格旋转?

如何使下表按顺时针方向旋转九十度?

\documentclass[a4]{article}
\usepackage{tikz}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=.4]
\draw[ultra thick] 
    (0,0)--(9,0)
    (0,1)--(9,1) 
    (0,2)--(9,2)
    (0,3)--(9,3)
    (0,4)--(9,4)
    (0,5)--(9,5)
    (0,6)--(9,6)
    (0,7)--(9,7)
    (0,8)--(9,8)
    (0,9)--(9,9);
\draw[ultra thick]
    (0,0)--(0,9)
    (1,0)--(1,9)
    (2,0)--(2,9)
    (3,0)--(3,9)
    (4,0)--(4,9)
    (5,0)--(5,9)
    (6,0)--(6,9)
    (7,0)--(7,9)
    (8,0)--(8,9)
    (9,0)--(9,9);

\node at (0.5,0.5) {6};
\node at (0.5,1.5) {3};
\node at (0.5,2.5) {0};
\node at (0.5,3.5) {6};
\node at (0.5,4.5) {3};
\node at (0.5,5.5) {0};
\node at (0.5,6.5) {6};
\node at (0.5,7.5) {3};
\node at (0.5,8.5) {0};
\node at (1.5,0.5) {7};
\node at (1.5,1.5) {4};
\node at (1.5,2.5) {1};
\node at (1.5,3.5) {7};
\node at (1.5,4.5) {4};
\node at (1.5,5.5) {1};
\node at (1.5,6.5) {7};
\node at (1.5,7.5) {4};
\node at (1.5,8.5) {1};
\node at (2.5,0.5) {8};
\node at (2.5,1.5) {5};
\node at (2.5,2.5) {2};
\node at (2.5,3.5) {8};
\node at (2.5,4.5) {5};
\node at (2.5,5.5) {2};
\node at (2.5,6.5) {8};
\node at (2.5,7.5) {5};
\node at (2.5,8.5) {2};
\node at (3.5,0.5) {0};
\node at (3.5,1.5) {6};
\node at (3.5,2.5) {3};
\node at (3.5,3.5) {0};
\node at (3.5,4.5) {6};
\node at (3.5,5.5) {3};
\node at (3.5,6.5) {0};
\node at (3.5,7.5) {6};
\node at (3.5,8.5) {3};
\node at (4.5,0.5) {1};
\node at (4.5,1.5) {7};
\node at (4.5,2.5) {4};
\node at (4.5,3.5) {1};
\node at (4.5,4.5) {7};
\node at (4.5,5.5) {4};
\node at (4.5,6.5) {1};
\node at (4.5,7.5) {7};
\node at (4.5,8.5) {4};
\node at (5.5,0.5) {2};
\node at (5.5,1.5) {8};
\node at (5.5,2.5) {5};
\node at (5.5,3.5) {2};
\node at (5.5,4.5) {8};
\node at (5.5,5.5) {5};
\node at (5.5,6.5) {2};
\node at (5.5,7.5) {8};
\node at (5.5,8.5) {5};
\node at (6.5,0.5) {3};
\node at (6.5,1.5) {0};
\node at (6.5,2.5) {6};
\node at (6.5,3.5) {3};
\node at (6.5,4.5) {0};
\node at (6.5,5.5) {6};
\node at (6.5,6.5) {3};
\node at (6.5,7.5) {0};
\node at (6.5,8.5) {6};
\node at (7.5,0.5) {4};
\node at (7.5,1.5) {1};
\node at (7.5,2.5) {7};
\node at (7.5,3.5) {4};
\node at (7.5,4.5) {1};
\node at (7.5,5.5) {7};
\node at (7.5,6.5) {4};
\node at (7.5,7.5) {1};
\node at (7.5,8.5) {7};
\node at (8.5,0.5) {5};
\node at (8.5,1.5) {2};
\node at (8.5,2.5) {8};
\node at (8.5,3.5) {5};
\node at (8.5,4.5) {2};
\node at (8.5,5.5) {8};
\node at (8.5,6.5) {5};
\node at (8.5,7.5) {2};
\node at (8.5,8.5) {8};

\end{tikzpicture} 
\end{document}

答案1

两个选项:

  1. 使用\rotatebox{-90}{....}

    \documentclass[a4paper]{article}
    \usepackage{tikz}
    \begin{document}
    \rotatebox{-90}{%
    \begin{tikzpicture}[scale=.4]
    \draw[ultra thick]
        (0,0)--(9,0)
        (0,1)--(9,1)
        (0,2)--(9,2)
        (0,3)--(9,3)
        (0,4)--(9,4)
        (0,5)--(9,5)
        (0,6)--(9,6)
        (0,7)--(9,7)
        (0,8)--(9,8)
        (0,9)--(9,9);
    \draw[ultra thick]
        (0,0)--(0,9)
        (1,0)--(1,9)
        (2,0)--(2,9)
        (3,0)--(3,9)
        (4,0)--(4,9)
        (5,0)--(5,9)
        (6,0)--(6,9)
        (7,0)--(7,9)
        (8,0)--(8,9)
        (9,0)--(9,9);
    
    \node at (0.5,0.5) {6};
    \node at (0.5,1.5) {3};
    \node at (0.5,2.5) {0};
    \node at (0.5,3.5) {6};
    \node at (0.5,4.5) {3};
    \node at (0.5,5.5) {0};
    \node at (0.5,6.5) {6};
    \node at (0.5,7.5) {3};
    \node at (0.5,8.5) {0};
    \node at (1.5,0.5) {7};
    \node at (1.5,1.5) {4};
    \node at (1.5,2.5) {1};
    \node at (1.5,3.5) {7};
    \node at (1.5,4.5) {4};
    \node at (1.5,5.5) {1};
    \node at (1.5,6.5) {7};
    \node at (1.5,7.5) {4};
    \node at (1.5,8.5) {1};
    \node at (2.5,0.5) {8};
    \node at (2.5,1.5) {5};
    \node at (2.5,2.5) {2};
    \node at (2.5,3.5) {8};
    \node at (2.5,4.5) {5};
    \node at (2.5,5.5) {2};
    \node at (2.5,6.5) {8};
    \node at (2.5,7.5) {5};
    \node at (2.5,8.5) {2};
    \node at (3.5,0.5) {0};
    \node at (3.5,1.5) {6};
    \node at (3.5,2.5) {3};
    \node at (3.5,3.5) {0};
    \node at (3.5,4.5) {6};
    \node at (3.5,5.5) {3};
    \node at (3.5,6.5) {0};
    \node at (3.5,7.5) {6};
    \node at (3.5,8.5) {3};
    \node at (4.5,0.5) {1};
    \node at (4.5,1.5) {7};
    \node at (4.5,2.5) {4};
    \node at (4.5,3.5) {1};
    \node at (4.5,4.5) {7};
    \node at (4.5,5.5) {4};
    \node at (4.5,6.5) {1};
    \node at (4.5,7.5) {7};
    \node at (4.5,8.5) {4};
    \node at (5.5,0.5) {2};
    \node at (5.5,1.5) {8};
    \node at (5.5,2.5) {5};
    \node at (5.5,3.5) {2};
    \node at (5.5,4.5) {8};
    \node at (5.5,5.5) {5};
    \node at (5.5,6.5) {2};
    \node at (5.5,7.5) {8};
    \node at (5.5,8.5) {5};
    \node at (6.5,0.5) {3};
    \node at (6.5,1.5) {0};
    \node at (6.5,2.5) {6};
    \node at (6.5,3.5) {3};
    \node at (6.5,4.5) {0};
    \node at (6.5,5.5) {6};
    \node at (6.5,6.5) {3};
    \node at (6.5,7.5) {0};
    \node at (6.5,8.5) {6};
    \node at (7.5,0.5) {4};
    \node at (7.5,1.5) {1};
    \node at (7.5,2.5) {7};
    \node at (7.5,3.5) {4};
    \node at (7.5,4.5) {1};
    \node at (7.5,5.5) {7};
    \node at (7.5,6.5) {4};
    \node at (7.5,7.5) {1};
    \node at (7.5,8.5) {7};
    \node at (8.5,0.5) {5};
    \node at (8.5,1.5) {2};
    \node at (8.5,2.5) {8};
    \node at (8.5,3.5) {5};
    \node at (8.5,4.5) {2};
    \node at (8.5,5.5) {8};
    \node at (8.5,6.5) {5};
    \node at (8.5,7.5) {2};
    \node at (8.5,8.5) {8};
    
    \end{tikzpicture}%
    }
    \end{document} 
    
  2. 使用包rotating\begin{turn}{-90}...\end{turn}

    \documentclass[a4paper]{article}
    \usepackage{tikz,rotating}
    \begin{document}
    \begin{turn}{-90}
    \begin{tikzpicture}[scale=.4]
    \draw[ultra thick]
        (0,0)--(9,0)
        (0,1)--(9,1)
        (0,2)--(9,2)
        (0,3)--(9,3)
        (0,4)--(9,4)
        (0,5)--(9,5)
        (0,6)--(9,6)
        (0,7)--(9,7)
        (0,8)--(9,8)
        (0,9)--(9,9);
    \draw[ultra thick]
        (0,0)--(0,9)
        (1,0)--(1,9)
        (2,0)--(2,9)
        (3,0)--(3,9)
        (4,0)--(4,9)
        (5,0)--(5,9)
        (6,0)--(6,9)
        (7,0)--(7,9)
        (8,0)--(8,9)
        (9,0)--(9,9);
    
    \node at (0.5,0.5) {6};
    \node at (0.5,1.5) {3};
    \node at (0.5,2.5) {0};
    \node at (0.5,3.5) {6};
    \node at (0.5,4.5) {3};
    \node at (0.5,5.5) {0};
    \node at (0.5,6.5) {6};
    \node at (0.5,7.5) {3};
    \node at (0.5,8.5) {0};
    \node at (1.5,0.5) {7};
    \node at (1.5,1.5) {4};
    \node at (1.5,2.5) {1};
    \node at (1.5,3.5) {7};
    \node at (1.5,4.5) {4};
    \node at (1.5,5.5) {1};
    \node at (1.5,6.5) {7};
    \node at (1.5,7.5) {4};
    \node at (1.5,8.5) {1};
    \node at (2.5,0.5) {8};
    \node at (2.5,1.5) {5};
    \node at (2.5,2.5) {2};
    \node at (2.5,3.5) {8};
    \node at (2.5,4.5) {5};
    \node at (2.5,5.5) {2};
    \node at (2.5,6.5) {8};
    \node at (2.5,7.5) {5};
    \node at (2.5,8.5) {2};
    \node at (3.5,0.5) {0};
    \node at (3.5,1.5) {6};
    \node at (3.5,2.5) {3};
    \node at (3.5,3.5) {0};
    \node at (3.5,4.5) {6};
    \node at (3.5,5.5) {3};
    \node at (3.5,6.5) {0};
    \node at (3.5,7.5) {6};
    \node at (3.5,8.5) {3};
    \node at (4.5,0.5) {1};
    \node at (4.5,1.5) {7};
    \node at (4.5,2.5) {4};
    \node at (4.5,3.5) {1};
    \node at (4.5,4.5) {7};
    \node at (4.5,5.5) {4};
    \node at (4.5,6.5) {1};
    \node at (4.5,7.5) {7};
    \node at (4.5,8.5) {4};
    \node at (5.5,0.5) {2};
    \node at (5.5,1.5) {8};
    \node at (5.5,2.5) {5};
    \node at (5.5,3.5) {2};
    \node at (5.5,4.5) {8};
    \node at (5.5,5.5) {5};
    \node at (5.5,6.5) {2};
    \node at (5.5,7.5) {8};
    \node at (5.5,8.5) {5};
    \node at (6.5,0.5) {3};
    \node at (6.5,1.5) {0};
    \node at (6.5,2.5) {6};
    \node at (6.5,3.5) {3};
    \node at (6.5,4.5) {0};
    \node at (6.5,5.5) {6};
    \node at (6.5,6.5) {3};
    \node at (6.5,7.5) {0};
    \node at (6.5,8.5) {6};
    \node at (7.5,0.5) {4};
    \node at (7.5,1.5) {1};
    \node at (7.5,2.5) {7};
    \node at (7.5,3.5) {4};
    \node at (7.5,4.5) {1};
    \node at (7.5,5.5) {7};
    \node at (7.5,6.5) {4};
    \node at (7.5,7.5) {1};
    \node at (7.5,8.5) {7};
    \node at (8.5,0.5) {5};
    \node at (8.5,1.5) {2};
    \node at (8.5,2.5) {8};
    \node at (8.5,3.5) {5};
    \node at (8.5,4.5) {2};
    \node at (8.5,5.5) {8};
    \node at (8.5,6.5) {5};
    \node at (8.5,7.5) {2};
    \node at (8.5,8.5) {8};
    
    \end{tikzpicture}
    \end{turn}
    \end{document} 
    

结果是一样的:

在此处输入图片描述

相反,如果您打算旋转数字组合,而不是数字形状,请添加rotate=-90以下tikzpicture选项:

\documentclass[a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=.4,rotate=-90]
\draw[ultra thick]
    (0,0)--(9,0)
    (0,1)--(9,1)
    (0,2)--(9,2)
    (0,3)--(9,3)
    (0,4)--(9,4)
    (0,5)--(9,5)
    (0,6)--(9,6)
    (0,7)--(9,7)
    (0,8)--(9,8)
    (0,9)--(9,9);
\draw[ultra thick]
    (0,0)--(0,9)
    (1,0)--(1,9)
    (2,0)--(2,9)
    (3,0)--(3,9)
    (4,0)--(4,9)
    (5,0)--(5,9)
    (6,0)--(6,9)
    (7,0)--(7,9)
    (8,0)--(8,9)
    (9,0)--(9,9);

\node at (0.5,0.5) {6};
\node at (0.5,1.5) {3};
\node at (0.5,2.5) {0};
\node at (0.5,3.5) {6};
\node at (0.5,4.5) {3};
\node at (0.5,5.5) {0};
\node at (0.5,6.5) {6};
\node at (0.5,7.5) {3};
\node at (0.5,8.5) {0};
\node at (1.5,0.5) {7};
\node at (1.5,1.5) {4};
\node at (1.5,2.5) {1};
\node at (1.5,3.5) {7};
\node at (1.5,4.5) {4};
\node at (1.5,5.5) {1};
\node at (1.5,6.5) {7};
\node at (1.5,7.5) {4};
\node at (1.5,8.5) {1};
\node at (2.5,0.5) {8};
\node at (2.5,1.5) {5};
\node at (2.5,2.5) {2};
\node at (2.5,3.5) {8};
\node at (2.5,4.5) {5};
\node at (2.5,5.5) {2};
\node at (2.5,6.5) {8};
\node at (2.5,7.5) {5};
\node at (2.5,8.5) {2};
\node at (3.5,0.5) {0};
\node at (3.5,1.5) {6};
\node at (3.5,2.5) {3};
\node at (3.5,3.5) {0};
\node at (3.5,4.5) {6};
\node at (3.5,5.5) {3};
\node at (3.5,6.5) {0};
\node at (3.5,7.5) {6};
\node at (3.5,8.5) {3};
\node at (4.5,0.5) {1};
\node at (4.5,1.5) {7};
\node at (4.5,2.5) {4};
\node at (4.5,3.5) {1};
\node at (4.5,4.5) {7};
\node at (4.5,5.5) {4};
\node at (4.5,6.5) {1};
\node at (4.5,7.5) {7};
\node at (4.5,8.5) {4};
\node at (5.5,0.5) {2};
\node at (5.5,1.5) {8};
\node at (5.5,2.5) {5};
\node at (5.5,3.5) {2};
\node at (5.5,4.5) {8};
\node at (5.5,5.5) {5};
\node at (5.5,6.5) {2};
\node at (5.5,7.5) {8};
\node at (5.5,8.5) {5};
\node at (6.5,0.5) {3};
\node at (6.5,1.5) {0};
\node at (6.5,2.5) {6};
\node at (6.5,3.5) {3};
\node at (6.5,4.5) {0};
\node at (6.5,5.5) {6};
\node at (6.5,6.5) {3};
\node at (6.5,7.5) {0};
\node at (6.5,8.5) {6};
\node at (7.5,0.5) {4};
\node at (7.5,1.5) {1};
\node at (7.5,2.5) {7};
\node at (7.5,3.5) {4};
\node at (7.5,4.5) {1};
\node at (7.5,5.5) {7};
\node at (7.5,6.5) {4};
\node at (7.5,7.5) {1};
\node at (7.5,8.5) {7};
\node at (8.5,0.5) {5};
\node at (8.5,1.5) {2};
\node at (8.5,2.5) {8};
\node at (8.5,3.5) {5};
\node at (8.5,4.5) {2};
\node at (8.5,5.5) {8};
\node at (8.5,6.5) {5};
\node at (8.5,7.5) {2};
\node at (8.5,8.5) {8};

\end{tikzpicture}
\end{document} 

在此处输入图片描述

答案2

这是一个foreach使用了一些mod函数的双精度浮点数grid

\documentclass[varwidth,border=7mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
  \begin{tikzpicture}[line cap=round,scale=.4]
    \draw[ultra thick] (0,0) grid (9,9);
    \foreach \i in {0,...,8}
      \foreach \j in {0,...,8}
        \path let \n1={int(mod((3*mod(11-\i,3)+\j,9))} in (.5+\i,8.5-\j) node{\n1};
  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容