1

How would I place 4 chessboard side by side? Right now all of them are in one column, below each other. This is the code:

\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}
  • 4
    such code snippets are useless. How should one know how your commands are defined? – Ulrike Fischer Nov 24 '20 at 22:35
  • @UlrikeFischer I'm sorry, I thought there's an universal way to do this. I updated my question with a link – J H Nov 24 '20 at 22:49
  • 2
    your question is archived here forever and will not make sense if you change the code at that overleaf link. it is much better to make a small complete example and add it to your question – David Carlisle Nov 24 '20 at 22:57
  • 1
    note you have multiple errors (19 in the red box) – David Carlisle Nov 24 '20 at 23:03
  • 3
    it is not surprising the chessboards do not display, do not even look at the output if you have an error message. One of them is LaTeX Error: Environment Chessboard undefined. since you have not defined the commands they can do nothing. I do not know what definition you intended. – David Carlisle Nov 24 '20 at 23:33
0

Here's a prototype of what I understand you would like to do. From your code I kept only the essential parts.

The solution is based on the xcoffin package https://ctan.org/pkg/xcoffins?lang=en

that allow you to put material into boxes \SetVerticalCoffin and then precisely join them together. \JoinCoffins

The defined command \JoinAndPrintRow joins 4 boards in a single row and prints the row. The coffins can then be reused with new boards for the next row.

A somewhat longer explanation can be found at

Align text both horizontally and vertically

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

chess

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.