我在用 LaTeX 格式化表格时遇到了一些问题。我尝试格式化一个表格以进行整数模 9 的加法运算,但结果却不正常。
这是我目前拥有的:
\begin{center}
\begin{tabular}{ c|c c c c c c c c c }
$+_9$ & [0] & [1] & [2] & [3] & [4] & [5] & [6] & [7] & [8] \\
\hline
[0] & [0] & [1] & [2] & [3] & [4] & [5] & [6] & [7] & [8] \\
[1] & [1] & [2] & [3] & [4] & [5] & [6] & [7] & [8] & [0] \\
[2] & [2] & [3] & [4] & [5] & [6] & [7] & [6] & [0] & [1] \\
[3] & [3] & [4] & [5] & [6] & [7] & [8] & [6] & [1] & [2] \\
[4] & [4] & [5] & [6] & [7] & [8] & [0] & [6] & [2] & [3] \\
[5] & [5] & [6] & [7] & [8] & [0] & [1] & [6] & [3] & [4] \\
[6] & [6] & [7] & [8] & [0] & [1] & [2] & [3] & [4] & [5] \\
[7] & [7] & [8] & [0] & [1] & [2] & [3] & [6] & [5] & [6] \\
[8] & [8] & [0] & [1] & [2] & [3] & [4] & [5] & [6] & [7] \\
\end{tabular}
\end{center}
由于我无法弄清楚的原因,这个方法不起作用。但是,如果我只处理前两行,如下所示:
\begin{center}
\begin{tabular}{ c|c c c c c c c c c }
$+_9$ & [0] & [1] & [2] & [3] & [4] & [5] & [6] & [7] & [8] \\
\hline
[0] & [0] & [1] & [2] & [3] & [4] & [5] & [6] & [7] & [8] \\
\end{tabular}
\end{center}
一切运行正常。有人知道哪里出了问题吗?
答案1
换行符认为[1]
后面的(或其他内容)是一个可选参数,除非您告诉它停止。
\documentclass{article}
\begin{document}
\begin{center}
\begin{tabular}{ c|c c c c c c c c c }
$+_9$ & [0] & [1] & [2] & [3] & [4] & [5] & [6] & [7] & [8] \\
\hline
[0] & [0] & [1] & [2] & [3] & [4] & [5] & [6] & [7] & [8] \\\relax
[1] & [1] & [2] & [3] & [4] & [5] & [6] & [7] & [8] & [0] \\\relax
[2] & [2] & [3] & [4] & [5] & [6] & [7] & [6] & [0] & [1] \\\relax
[3] & [3] & [4] & [5] & [6] & [7] & [8] & [6] & [1] & [2] \\\relax
[4] & [4] & [5] & [6] & [7] & [8] & [0] & [6] & [2] & [3] \\\relax
[5] & [5] & [6] & [7] & [8] & [0] & [1] & [6] & [3] & [4] \\\relax
[6] & [6] & [7] & [8] & [0] & [1] & [2] & [3] & [4] & [5] \\\relax
[7] & [7] & [8] & [0] & [1] & [2] & [3] & [6] & [5] & [6] \\\relax
[8] & [8] & [0] & [1] & [2] & [3] & [4] & [5] & [6] & [7]
\end{tabular}
\end{center}
\end{document}
答案2
这是另一个解决方案,使用\halign
:
\def\pdig#1#2#3#4#5#6#7#8#9{[#1] [#2] [#3] [#4] [#5] [#6] [#7] [#8] [#9]}
\def\trule{\vrule height10pt depth4pt\relax}
\vbox{\offinterlineskip\halign{\hfil#\hfil\trule\ &\pdig#\cr
$+_9$ & 0 1 2 3 4 5 6 7 8 \cr
\noalign{\hrule}
[0] & 0 1 2 3 4 5 6 7 8 \cr
[1] & 1 2 3 4 5 6 7 8 0 \cr
[2] & 2 3 4 5 6 7 6 0 1 \cr
[3] & 3 4 5 6 7 8 6 1 2 \cr
[4] & 4 5 6 7 8 0 6 2 3 \cr
[5] & 5 6 7 8 0 1 6 3 4 \cr
[6] & 6 7 8 0 1 2 3 4 5 \cr
[7] & 7 8 0 1 2 3 6 5 6 \cr
[8] & 8 0 1 2 3 4 5 6 7 \cr
}}