# how to change a table style into a magic square table style?

How can I change my table style into a magic square table style?

\begin{table}[htbp]
\centering
\begin{tabular}{rrr}
\toprule
+1      & +5      & -2 \\
\midrule
& -3      &  \\
& +4      &  \\
\bottomrule
\end{tabular}%
\end{table}%


• Hmmm, looking forward to what you mean by "tablet style" and "magic square table style". These sound interesting... – Werner Nov 15 '17 at 23:27
• Is this question a duplicate of this: how to change table style? – Werner Nov 15 '17 at 23:27
• @werner sorry...table style – ryuk Nov 15 '17 at 23:32
• I know what a magic square is, but what do you mean by "magic square table style" what do you want to change in the above code (it would have been better if the example code had been a complete document to produce the image) – David Carlisle Nov 15 '17 at 23:47
• I mean that I would like that the horizontal and vertical lines of the table are visible, and also that the dimension of the single cell is a square and not a rectangle. – ryuk Nov 16 '17 at 0:05

The following example sets each cell entry in a box that is the width of the baseline skip (that varies depending on the \arraystretch that may have been redefined). This gives a square output.

\documentclass{article}

\usepackage{collcell}
\newcommand{\fwcell}[1]{\makebox[\arraystretch\normalbaselineskip]{$#1$}}

\begin{document}

\begingroup
\setlength{\tabcolsep}{0pt}
\begin{tabular}{ | *{3}{>{\collectcell\fwcell}c<{\endcollectcell} |} }
\hline
1 & 2 & 3 \\
\hline
4 & 5 & 6 \\
\hline
7 & 8 & 9 \\
\hline
\end{tabular}
\renewcommand{\arraystretch}{2}%
\begin{tabular}{ | *{3}{>{\collectcell\fwcell}c<{\endcollectcell} |} }
\hline
1 & 2 & 3 \\
\hline
4 & 5 & 6 \\
\hline
7 & 8 & 9 \\
\hline
\end{tabular}
\endgroup

\end{document}