4
\begin{tabular}{c|m{3em}|m{3em}|m{3em}|}
& 1 & 2 & 3 \\
\cline{2-4}
$3$ & $7500^2$ & $25000^2$ & $0$ \\
\cline{2-4}
$2$ & $5000^1$ & $0$ & \cellcolor{gray!5}\\
\cline{2-4}
$1$ & $0$  &\cellcolor{gray!5} &\cellcolor{gray!5}\\
\cline{2-4}
\end{tabular}

How can I remove the vertical bars in the first row? Thanks.

Mico
  • 506,678
latra
  • 95

2 Answers2

5

In the definition

\begin{tabular}{c|m{3em}|m{3em}|m{3em}|}

each column specification effectively consists of both a basic type (c or m) and a vertical bar along the right-hand edge.

To avoid getting a vertical bar at the right-hand edge, it's necessary to use a different column specification locally. In the following example, I use \multicolumn{1}{l}{...} -- actually, abbreviated to \mc{...} -- to provide such an alternate column specification in each of the four cells of the first row.

enter image description here

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{array}
\setlength\extrarowheight{2pt}            % for a less-cramped "look"
\newcommand\mc[1]{\multicolumn{1}{l}{#1}} % Note: no vertical bars
\begin{document}
\begin{tabular}{c|p{3em}|p{3em}|p{3em}|}
\mc{} & \mc{$1$} & \mc{$2$} & \mc{$3$} \\
\cline{2-4}
$3$   & $7500^2$ & $25000^2$ & $0$ \\
\cline{2-4}
$2$   & $5000^1$ & $0$       & \cellcolor{gray!10}\\
\cline{2-4}
$1$   & $0$ &\cellcolor{gray!10} &\cellcolor{gray!10}\\
\cline{2-4}
\end{tabular}
\end{document}
Mico
  • 506,678
  • Is there other alternative? – latra Apr 17 '18 at 21:25
  • @latra - I'm not sure I understand the gist of your question. Are you maybe expressing a view that there should be a simpler solution "out there"? – Mico Apr 17 '18 at 21:28
  • I think using \multicolumn{1}{l} is a trick. It also depends upon the package of multicolumn. There should have some function of LaTeX that we can directly work on this issue. – latra Apr 18 '18 at 23:07
  • @latra - For sure, \multicolumn is a macro that's provided by the LaTeX "kernel" -- there's no need to load a package to access this macro. Moreover, \multicolumn{1}{...}{...}really is the standard way to provide a local override of the overall settings of a given column. Finally, I'm not in charge of deciding what ought to be in the LaTeX kernel. I thus can't provide a meaningful view on your opinion as to what needs to be in the LaTeX kernel. – Mico Apr 19 '18 at 14:15
0

You can easily do that table with {NiceTabular} of nicematrix. Moreover, you will have a perfect PDF output (some rules won't seem to disappera at some levels of zoom).

\documentclass{article}
\usepackage{xcolor}
\usepackage{nicematrix}

\begin{document}

\setlength\extrarowheight{2pt} \begin{NiceTabular}{lll}[first-col,first-row,hvlines,columns-width=3em] \CodeBefore \cellcolor{gray!10}{2-3,3-2,3-3} \Body & 1 & 2 & 3 \ 3 & $7500^2$ & $25000^2$ & $0$ \Block{3-1}{} \ 2 & $5000^1$ & $0$ \Block{2-1}{} \ 1 & $0$ \end{NiceTabular}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

F. Pantigny
  • 40,250