我该如何将 4 个棋盘并排摆放?目前它们都在一列中,一个在另一个之下。这是代码:
\documentclass[12pt, a4paper]{report}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}
\usepackage{lmodern}
\usepackage[croatian]{babel}
\usepackage[margin=1.4in]{geometry}
\usepackage[labelsep=period]{caption}
\usepackage{graphicx}
\usepackage{mathastext}
\usepackage{textcomp}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{afterpage}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{epstopdf}
\usepackage{array}
\usepackage{tikz}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{color, colortbl}
\usetikzlibrary{trees}
\usepackage{setspace}
\usepackage{hyperref}
\usepackage{listings}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage[titletoc,page]{appendix}
\usepackage[up,bf,raggedright]{titlesec}
\usepackage{blindtext}
%\usepackage[dvipsnames]{xcolor}
\usepackage{keyval}
\definecolor{applegreen}{rgb}{0.55, 0.71, 0.0}
\definecolor{bananayellow}{rgb}{1.0, 0.88, 0.21}
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}
\begin{document}
\def\Side{\ChessSide}
\newcommand\ChessBoxA{%
{\fboxsep=0pt\fbox{\color{\ChessColori}\rule{\Side}{\Side}}}}
\newcommand\ChessBoxB{%
{\fboxsep=0pt\fbox{\color{\ChessColorii}\rule{\Side}{\Side}}}}
\makeatletter
\newcommand\Row[1]{%
\par\nobreak\nointerlineskip\vskip-\fboxrule%
\@tfor\@tempa:=#1 \do {\csname ChessBox\@tempa\endcsname\kern-\fboxrule}}
\define@key{chessB}{side}{\def\ChessSide{#1}}
\define@key{chessB}{colori}{\def\ChessColori{#1}}
\define@key{chessB}{colorii}{\def\ChessColorii{#1}}
\setkeys{chessB}{
side=1cm,
colori=bananayellow,
colorii=applegreen}
\makeatother
\Conventional
\begin{Chessboard}
\Row{A,A}
\Row{B,B}
\end{Chessboard}
\\[0.2 cm]
\makeatother
\Conventional
\begin{Chessboard}
\Row{B,A}
\Row{B,A}
\end{Chessboard}
\\[0.2 cm]
\makeatother
\Conventional
\begin{Chessboard}
\Row{A,B}
\Row{A,B}
\end{Chessboard}
\\[0.2 cm]
\makeatother
\Conventional
\begin{Chessboard}
\Row{B,B}
\Row{A,A}
\end{Chessboard}
\\[0.2 cm]
\makeatother
\Conventional
\begin{Chessboard}
\Row{A,B}
\Row{B,A}
\end{Chessboard}
\\[0.2 cm]
\makeatother
\Conventional
\begin{Chessboard}
\Row{B,A}
\Row{A,B}
\end{Chessboard}
\end{document}
答案1
这是据我所知您想要做的原型。从您的代码中,我只保留了必要的部分。
该解决方案基于xcoffin
包
https://ctan.org/pkg/xcoffins?lang=en
它可以让你把材料放入盒子\SetVerticalCoffin
然后精确地将它们连接在一起。\JoinCoffins
定义的命令\JoinAndPrintRow
将 4 块木板连成一行并打印该行。然后可以将新木板用于下一行,从而重复使用棺材。
可以在以下网址找到更长的解释
\documentclass[12pt, a4paper]{report}
\usepackage{graphicx}
\usepackage{xcolor}
\definecolor{applegreen}{rgb}{0.55, 0.71, 0.0}
\definecolor{bananayellow}{rgb}{1.0, 0.88, 0.21}
\def\Side{\ChessSide}
\newcommand\ChessBoxA{%
{\fboxsep=0pt\fbox{\color{\ChessColori}\rule{\Side}{\Side}}}}
\newcommand\ChessBoxB{%
{\fboxsep=0pt\fbox{\color{\ChessColorii}\rule{\Side}{\Side}}}}
\makeatletter
\newcommand\Row[1]{%
\par\nobreak\nointerlineskip\vskip-\fboxrule%
\@tfor\@tempa:=#1 \do {\csname ChessBox\@tempa\endcsname\kern-\fboxrule}}
\define@key{chessB}{side}{\def\ChessSide{#1}}
\define@key{chessB}{colori}{\def\ChessColori{#1}}
\define@key{chessB}{colorii}{\def\ChessColorii{#1}}
\setkeys{chessB}{%
side=1cm,
colori=bananayellow,
colorii=applegreen}
\makeatother
\usepackage{xcoffins} % added
\NewCoffin\Chessi
\NewCoffin\Chessii
\NewCoffin\Chessiii
\NewCoffin\Chessiv
\newcommand{\JoinAndPrintRow}{%
\JoinCoffins\Chessi[r,vc]\Chessii[l,vc]
\JoinCoffins\Chessi[r,vc]\Chessiii[l,vc]
\JoinCoffins\Chessi[r,vc]\Chessiv[l,vc]
\noindent\TypesetCoffin\Chessi
\vspace{2\baselineskip}
}
\begin{document}
\SetVerticalCoffin\Chessi{0.25\textwidth}{\Row{A,A}\Row{B,B}}
\SetVerticalCoffin\Chessii{0.25\textwidth} {\Row{B,A}\Row{B,A}}
\SetVerticalCoffin\Chessiii{0.25\textwidth} {\Row{A,B}\Row{A,B}}
\SetVerticalCoffin\Chessiv{0.25\textwidth} {\Row{B,B}\Row{A,A}}
\JoinAndPrintRow % first row
\SetVerticalCoffin\Chessi{0.25\textwidth}{\Row{B,A}\Row{B,B}}
\SetVerticalCoffin\Chessii{0.25\textwidth} {\Row{A,A}\Row{B,A}}
\SetVerticalCoffin\Chessiii{0.25\textwidth} {\Row{A,B}\Row{B,B}}
\SetVerticalCoffin\Chessiv{0.25\textwidth} {\Row{B,A}\Row{A,A}}
\JoinAndPrintRow % second row
\end{document}