Table formatting: remove horizontal and vertical borders from only specific cells
Like this?
You have many possibilities, one of them is use \multicolumn
command which hasn't border lines:
\documentclass{article}
\usepackage[table]{xcolor}
\newcommand\mcc[1]{\multicolumn{1}{c}{#1}} % <---
\setlength{\parskip}{\baselineskip}
\title{FACTORbox}
\author{Algebra Teacher Who Struggles with LaTeX Tables}
\date{January 2021}
\begin{document}
\maketitle
In the table below, I only want \textbf{borderlines around the values in black,
} not the red values above and to the left of the black colored values.
Also, I can't figure out a way to \textbf{remove the gray shading from upper left corner cell.}
\renewcommand\arraystretch{2}
\begin{tabular}{ c | c | c | }
% \hline
\mcc{} & \mcc{\textcolor{red}{$x$}} & \mcc{\textcolor{red}{$+6$}} \\
\cline{2-3}
\textcolor{red}{$x$} & $x^2$ & $6x$ \\
\cline{2-3}
\textcolor{red}{$+2$} & $2x$ & $12$ \\
\cline{2-3}
\end{tabular}
\end{document}
Edit:
Another possibilities is to use ˙blkarray
package:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{blkarray}
\begin{document}
$\renewcommand\arraystretch{2}
\begin{blockarray}{r cc}
& \textcolor{red}{x} & \textcolor{red}{+6} \\
\cline{2-3}
\begin{block}{r|c|c|}
\cline{2-3}
\textcolor{red}{x} & x^2 & 6x \\
\cline{2-3}
\textcolor{red}{+2} & 2x & 12 \\
\cline{2-3}
\end{block}
\end{blockarray}
$
\end{document}
Result is the same as before.
With the package nicematrix
.
\documentclass{article}
\usepackage{nicematrix}
\usepackage{xcolor}
\begin{document}
\renewcommand\arraystretch{1.8}
$\begin{NiceMatrix}%
[
hvlines,
columns-width=auto,
first-row, code-for-first-row = \color{red},
first-col, code-for-first-col = \color{red}
]
& x & +6 \\
x & x^2 & 6x \\
+2 & 2x & 12
\end{NiceMatrix}$
\end{document}
You need several compilations (because nicematrix
uses PGF/Tikz nodes).