# Big indent when putting tikzpicture inside tabular?

Related to Easy way to generate Rubik's cube diagrams.

I'm trying to put some tikzpicture code inside a tabular environment. But I get this big gap? How can I make the cube fit nicely inside the cell (i.e. centered vertically and horizontally). Also I'm trying to get the text in the 2nd column to be aligned with the top of the cell. I tried [t] but this didn't work.

For reference, I want it to look something like this

## MWE

\documentclass{article}
\usepackage[a4paper,margin=1cm]{geometry}
\usepackage{tikz,tikz-3dplot}
\usetikzlibrary{3d,backgrounds}

% Custom TikZ Cube Diagrams
% Colours
\definecolor{R}{RGB}{202,65,55}
\definecolor{G}{RGB}{50,205,50}
\definecolor{B}{RGB}{51,72,237}
\definecolor{W}{RGB}{255,255,255}
\definecolor{O}{RGB}{255,153,31}
\definecolor{Y}{RGB}{255,255,0}
\definecolor{X}{RGB}{65,65,65}
\definecolor{_}{RGB}{65,65,65}
%
% Define the notation and how it translates into \myarray
\newcommand{\TikZRubikFaceLeft}[9]{\def\myarrayL{#1,#2,#3,#4,#5,#6,#7,#8,#9}}
\newcommand{\TikZRubikFaceRight}[9]{\def\myarrayR{#1,#2,#3,#4,#5,#6,#7,#8,#9}}
\newcommand{\TikZRubikFaceTop}[9]{\def\myarrayT{#1,#2,#3,#4,#5,#6,#7,#8,#9}}
\newcommand{\BuildArray}{\foreach \X [count=\Y] in \myarrayL
{\ifnum\Y=1
\xdef\myarray{"\X"}
\else
\xdef\myarray{\myarray,"\X"}
\fi}
\foreach \X in \myarrayR
{\xdef\myarray{\myarray,"\X"}}
\foreach \X in \myarrayT
{\xdef\myarray{\myarray,"\X"}}
\xdef\myarray{{\myarray}}
}
%
% The tikzpicture code for generating the cube diagrams
\newcommand{\DrawCube}[1][2cm]{%
\BuildArray % First build the array!
\tdplotsetmaincoords{55}{135}
\resizebox{#1}{!}{%
\begin{tikzpicture}[scale=0.35]
\clip (-2.5,-2.5) rectangle (2.5,2.5);
\begin{scope}[tdplot_main_coords,rounded corners=0.06mm]
\filldraw [canvas is yz plane at x=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
\filldraw [canvas is xz plane at y=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
\filldraw [canvas is yx plane at z=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
\foreach \X [count=\XX starting from 0] in {-1.5,-0.5,0.5}{
\foreach \Y [count=\YY starting from 0] in {-1.5,-0.5,0.5}{
\pgfmathtruncatemacro{\Z}{\XX+3*(2-\YY)}
\pgfmathsetmacro{\mycolor}{\myarray[\Z]}
\pgfmathtruncatemacro{\Z}{2-\XX+3*(2-\YY)+9}
\pgfmathsetmacro{\mycolor}{\myarray[\Z]}
\pgfmathtruncatemacro{\Z}{2-\YY+3*\XX+18}
\pgfmathsetmacro{\mycolor}{\myarray[\Z]}
}
}
\end{scope}
\end{tikzpicture}
}
}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

\begin{document}

\begin{center}
\LARGE \textbf{F2L Algorithms}
\end{center}

\section{Both pieces in top layer}
\subsection{White sticker facing up}

\begin{tabular}{|c|l|}
\hline

\TikZRubikFaceLeft
{_}{_}{G}
{R}{R}{_}
{R}{R}{_}
\TikZRubikFaceRight
{R}{_}{_}
{_}{G}{G}
{_}{G}{G}
\TikZRubikFaceTop
{_}{R}{_}
{_}{_}{_}
{W}{_}{_}
\DrawCube
&
\textsf{U2 (R U R') U (R U' R') }\\ \hline

\TikZRubikFaceLeft
{_}{_}{G}
{R}{R}{_}
{R}{R}{_}
\TikZRubikFaceRight
{R}{G}{_}
{_}{G}{G}
{_}{G}{G}
\TikZRubikFaceTop
{_}{_}{_}
{_}{_}{_}
{W}{R}{_}
\DrawCube
&
\textsf{(R U2 R') U' (R U R')} \\ \hline
\end{tabular}

\end{document}


Added a bunch of % to line ends...to remove extraneous spaces.

\documentclass{article}
\usepackage[a4paper,margin=1cm]{geometry}
\usepackage{tikz,tikz-3dplot}
\usetikzlibrary{3d,backgrounds}

% Custom TikZ Cube Diagrams
% Colours
\definecolor{R}{RGB}{202,65,55}
\definecolor{G}{RGB}{50,205,50}
\definecolor{B}{RGB}{51,72,237}
\definecolor{W}{RGB}{255,255,255}
\definecolor{O}{RGB}{255,153,31}
\definecolor{Y}{RGB}{255,255,0}
\definecolor{X}{RGB}{65,65,65}
\definecolor{_}{RGB}{65,65,65}
%
% Define the notation and how it translates into \myarray
\newcommand{\TikZRubikFaceLeft}[9]{\def\myarrayL{#1,#2,#3,#4,#5,#6,#7,#8,#9}}%
\newcommand{\TikZRubikFaceRight}[9]{\def\myarrayR{#1,#2,#3,#4,#5,#6,#7,#8,#9}}%
\newcommand{\TikZRubikFaceTop}[9]{\def\myarrayT{#1,#2,#3,#4,#5,#6,#7,#8,#9}}%
\newcommand{\BuildArray}{\foreach \X [count=\Y] in \myarrayL%
{\ifnum\Y=1%
\xdef\myarray{"\X"}%
\else%
\xdef\myarray{\myarray,"\X"}%
\fi}%
\foreach \X in \myarrayR%
{\xdef\myarray{\myarray,"\X"}}%
\foreach \X in \myarrayT%
{\xdef\myarray{\myarray,"\X"}}%
\xdef\myarray{{\myarray}}%
}%
%
% The tikzpicture code for generating the cube diagrams
\newcommand{\DrawCube}[1][2cm]{%
\BuildArray % First build the array!
\tdplotsetmaincoords{55}{135}%
\resizebox{#1}{!}{%
\begin{tikzpicture}[scale=0.35]
\clip (-2.5,-2.5) rectangle (2.5,2.5);
\begin{scope}[tdplot_main_coords,rounded corners=0.06mm]
\filldraw [canvas is yz plane at x=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
\filldraw [canvas is xz plane at y=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
\filldraw [canvas is yx plane at z=1.5] (-1.5,-1.5) rectangle (1.5,1.5);
\foreach \X [count=\XX starting from 0] in {-1.5,-0.5,0.5}{
\foreach \Y [count=\YY starting from 0] in {-1.5,-0.5,0.5}{
\pgfmathtruncatemacro{\Z}{\XX+3*(2-\YY)}
\pgfmathsetmacro{\mycolor}{\myarray[\Z]}
\pgfmathtruncatemacro{\Z}{2-\XX+3*(2-\YY)+9}
\pgfmathsetmacro{\mycolor}{\myarray[\Z]}
\pgfmathtruncatemacro{\Z}{2-\YY+3*\XX+18}
\pgfmathsetmacro{\mycolor}{\myarray[\Z]}
}
}
\end{scope}%
\end{tikzpicture}%
}%
}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

\begin{document}

\begin{center}
\LARGE \textbf{F2L Algorithms}
\end{center}

\section{Both pieces in top layer}
\subsection{White sticker facing up}

\begin{tabular}{|c|l|}
\hline
%
\TikZRubikFaceLeft
{_}{_}{G}
{R}{R}{_}
{R}{R}{_}%
\TikZRubikFaceRight
{R}{_}{_}
{_}{G}{G}
{_}{G}{G}%
\TikZRubikFaceTop
{_}{R}{_}
{_}{_}{_}
{W}{_}{_}%
\DrawCube
&
\textsf{U2 (R U R') U (R U' R') }\\ \hline
%
\TikZRubikFaceLeft
{_}{_}{G}
{R}{R}{_}
{R}{R}{_}%
\TikZRubikFaceRight
{R}{G}{_}
{_}{G}{G}
{_}{G}{G}%
\TikZRubikFaceTop
{_}{_}{_}
{_}{_}{_}
{W}{R}{_}%
\DrawCube
&
\textsf{(R U2 R') U' (R U R')} \\ \hline
\end{tabular}

\end{document}


• +1. Yes, that is my bad, I did not pay attention to this when rewriting the array code. – user121799 Nov 11 '18 at 2:31
• @marmot I do it all the time. No worries. – Steven B. Segletes Nov 11 '18 at 2:42