我喜欢学习如何在表格中列出所有棋步。
在我的 MWE 中,我手动输入前三步。有没有办法通过循环来完成?
\documentclass{article}
\usepackage{skak, xskak,chessboard}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{array}
\usepackage{comment}
\usepackage[table]{xcolor}
\setlength{\arrayrulewidth}{1mm}
\setlength{\tabcolsep}{18pt}
\renewcommand{\arraystretch}{1.5}
\begin{document}
\newchessgame
\noindent
\mainline{
1.e4 e5 2.Nf3 d6 3.d4 Bg4 4.dxe5 Bxf3 5.Qxf3 dxe5 6.Bc4 Nf6 7.Qb3 Qe7 8.Nc3 c6 9.Bg5 b5 10.Nxb5 cxb5 11.Bxb5+ Nbd7 12.O-O-O Rd8 13.Rxd7 Rxd7 14.Rd1 Qe6 15.Bxd7+ Nxd7 16.Qb8+ Nxb8 17.Rd8#}
\vspace{1cm}
\begin{tabular}{ | p{2cm} | p{2cm} | p{2cm} | }
\hline\textbf{Move}&\textbf{White}&\textbf{Black}\\
\hline
1 & e4 & e5\\
\hline
2 & Nf3 & d6\\
\hline
3 & d4 & Bg4 \\
\hline
}
\end{tabular}
\end{document}
答案1
创建带有循环的表格并不容易,因为表格单元格会构建组。通常最好的方法是将表格的内容组合在宏中并使用它。例如
\documentclass{article}
\PassOptionsToPackage{table}{xcolor}
\usepackage{xskak}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{array}
\usepackage{comment}
\setlength{\arrayrulewidth}{1mm}
\setlength{\tabcolsep}{18pt}
\renewcommand{\arraystretch}{1.5}
\usepackage{etoolbox}
\begin{document}
\newchessgame
\noindent
\mainline{
1.e4 e5 2.Nf3 d6 3.d4 Bg4 4.dxe5 Bxf3 5.Qxf3 dxe5 6.Bc4 Nf6 7.Qb3 Qe7 8.Nc3 c6 9.Bg5 b5 10.Nxb5 cxb5 11.Bxb5+ Nbd7 12.O-O-O Rd8 13.Rxd7 Rxd7 14.Rd1 Qe6 15.Bxd7+ Nxd7 16.Qb8+ Nxb8 17.Rd8#}
\newcommand\tabularcontent{}
\whiledo{\xskaktestmoveid
{\xskakget{movenr}}{\xskakget{player}}}
{%
\ifthenelse{\equal{\xskakget{player}}{w}}
{%
\eappto\tabularcontent
{\xskakget{movenr}&
\noexpand\xskakset{moveid=\xskakget{moveid}}%
\noexpand\xskakget{lan}&}%
}
{%
\eappto\tabularcontent
{\noexpand\xskakset{moveid=\xskakget{moveid}}}
\appto\tabularcontent{\xskakget{lan}\\\hline}%
}
\xskakset{stepmoveid}
}%
\ifthenelse{\equal{\xskakgetgame{lastplayer}}{w}}{\appto\tabularcontent{\\\hline}}{}
\vspace{1cm}
\begin{tabular}{ | p{2cm} | p{2cm} | p{2cm} | }
\hline\textbf{Move}&\textbf{White}&\textbf{Black}\\\hline
\tabularcontent
\end{tabular}
\end{document}