![表格格式:仅从特定单元格中删除水平和垂直边框](https://linux22.com/image/427628/%E8%A1%A8%E6%A0%BC%E6%A0%BC%E5%BC%8F%EF%BC%9A%E4%BB%85%E4%BB%8E%E7%89%B9%E5%AE%9A%E5%8D%95%E5%85%83%E6%A0%BC%E4%B8%AD%E5%88%A0%E9%99%A4%E6%B0%B4%E5%B9%B3%E5%92%8C%E5%9E%82%E7%9B%B4%E8%BE%B9%E6%A1%86.png)
下面的 MWE 创建了一个 3 x 3 的表格。表格上方的文本描述了我希望没有边框的特定单元格。
我相信解决方案在于正确使用\cline
命令并结合\multicolumn{1}{c|}
。
但我无法找出正确的语法来实现期望的结果。
非常感谢您的帮助!
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[table]{xcolor}
\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.}
\def\arraystretch{2}
\begin{tabular}{ |c | c | c | }
% \hline
\cellcolor{gray}& \textcolor{red}{$x$} & \textcolor{red}{$+6$} \\
\hline
\textcolor{red}{$x$} & $x^2$ & $6x$ \\
\hline
\textcolor{red}{$+2$} & $2x$ & $12$ \\
\hline
\end{tabular}
\end{document}
答案1
像这样?
您有很多种可能性,其中之一就是使用\multicolumn
没有边框的命令:
\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}
编辑:
另一种可能性是使用˙blkarray
包:
\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}
结果和以前一样。
答案2
带包裹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}
您需要多次编译(因为nicematrix
使用 PGF/Tikz 节点)。