1

I have following table in LaTeX:

\documentclass[]{article}
\begin{document}
\begin{center}
  \begin{tabular}{r *{10}{| c}}
    \cline{2-9}
    1 & & & & & & & & \cellcolor{black}  \\ \cline{2-9}
    2 & & & & & & & & \cellcolor{black} \\ \cline{2-9}
    3 & & & & & & & &  \\ \cline{2-9}
    4 & & & & & & & & \\ \cline{2-9}
    5 & & & & & & & &  \\ \cline{2-9}
    6 & & & & & & & &  \\ \cline{2-9}
    7 & & & & & & & &  \\ \cline{2-9}
    8 & & & & & & & &  \\ \cline{2-9}
    \multicolumn{1}{c}{}  & \multicolumn{1}{c}{a} & \multicolumn{1}{c}{b} & \multicolumn{1}{c}{c} & \multicolumn{1}{c}{d} & \multicolumn{1}{c}{e} & \multicolumn{1}{c}{f} & \multicolumn{1}{c}{g} & \multicolumn{1}{c}{h}
  \end{tabular}
\end{center}
\end{document}

How would I go about getting single borders (not rows or columns, but for example the left side of a specific cell) to have a specific color? Thanks in advance.

MateInTwo
  • 113

2 Answers2

1

Tinkering around with hhline:

\documentclass[]{article}

\usepackage{hhline,colortbl}

\begin{document}
\begin{center}
  \begin{tabular}{r *{10}{| c}}
    \cline{2-9}
    1 & & & & & & & & \cellcolor{black}  \\ \cline{2-9}
    2 & & & & & & & & \cellcolor{black} \\ \cline{2-9}
    3 & & & & & & & &  \\ \cline{2-9}
    4 & & & & & & & & \\ \cline{2-9}
    5 & & & & & & & &  \\ \cline{2-9}
    6 & & & & & & & &  \\ \cline{2-9}
    \hhline{~|-|-|>{\arrayrulecolor{red}}-|>{\arrayrulecolor{black}}-|-|-|-|-|-|}
    7 & & & \multicolumn{1}{!{\color{red}\vline}c!{\color{red}\vline}}{}  & & & & &  \\ 
        \hhline{~|-|-|>{\arrayrulecolor{red}}-|>{\arrayrulecolor{black}}-|-|-|-|-|-|}
    8 & & & & & & & &  \\ \cline{2-9}
    \multicolumn{1}{c}{}  & \multicolumn{1}{c}{a} & \multicolumn{1}{c}{b} & \multicolumn{1}{c}{c} & \multicolumn{1}{c}{d} & \multicolumn{1}{c}{e} & \multicolumn{1}{c}{f} & \multicolumn{1}{c}{g} & \multicolumn{1}{c}{h}
  \end{tabular}
\end{center}
\end{document}

enter image description here


Also works at the right edge

\documentclass[]{article}

\usepackage{hhline,colortbl}

\begin{document}
\begin{center}
  \begin{tabular}{r *{10}{| c}}
    \cline{2-9}
    1 & & & & & & & & \cellcolor{black}  \\ \cline{2-9}
    2 & & & & & & & & \cellcolor{black} \\ \cline{2-9}
    3 & & & & & & & &  \\ \cline{2-9}
    4 & & & & & & & & \\ \cline{2-9}
    5 & & & & & & & &  \\ \cline{2-9}
    6 & & & & & & & &  \\ \cline{2-9}
    \hhline{~|-|-|-|-|-|-|-|>{\arrayrulecolor{red}}-|>{\arrayrulecolor{black}}-|}
    7 & & &  & & & & & \multicolumn{1}{!{\color{red}\vline}c!{\color{red}\vline}}{}   \\ 
    \hhline{~|-|-|-|-|-|-|-|>{\arrayrulecolor{red}}-|>{\arrayrulecolor{black}}-|}
    8 & & & & & & & &  \\ \cline{2-9}
    \multicolumn{1}{c}{}  & \multicolumn{1}{c}{a} & \multicolumn{1}{c}{b} & \multicolumn{1}{c}{c} & \multicolumn{1}{c}{d} & \multicolumn{1}{c}{e} & \multicolumn{1}{c}{f} & \multicolumn{1}{c}{g} & \multicolumn{1}{c}{h}
  \end{tabular}
\end{center}
\end{document}

enter image description here


and with cell colours

\documentclass[]{article}

\usepackage{hhline,colortbl}

\begin{document}
\begin{center}
  \begin{tabular}{r *{10}{| c}}
    \cline{2-9}
    1 & & & & & & & & \cellcolor{black}  \\ \cline{2-9}
    2 & & & & & & & & \cellcolor{black} \\ \cline{2-9}
    3 & & & & & & & &  \\ \cline{2-9}
    4 & & & & & & & & \\ \cline{2-9}
    5 & & & & & & & &  \\ \cline{2-9}
    6 & & & & & & & &  \\ \cline{2-9}
    \hhline{~|-|-|-|-|-|-|-|>{\arrayrulecolor{red}}-|>{\arrayrulecolor{black}}-|}
    7 & & &  & & & & & \multicolumn{1}{!{\color{red}\vline}c!{\color{red}\vline}}{\cellcolor{yellow}}   \\ 
    \hhline{~|-|-|-|-|-|-|-|>{\arrayrulecolor{red}}-|>{\arrayrulecolor{black}}-|}
    8 & & & & & & & &  \\ \cline{2-9}
    \multicolumn{1}{c}{}  & \multicolumn{1}{c}{a} & \multicolumn{1}{c}{b} & \multicolumn{1}{c}{c} & \multicolumn{1}{c}{d} & \multicolumn{1}{c}{e} & \multicolumn{1}{c}{f} & \multicolumn{1}{c}{g} & \multicolumn{1}{c}{h}
  \end{tabular}
\end{center}
\end{document}

enter image description here

1

The environment {NiceTabular} of nicematrix is similar to the classical environment {tabular} (as provided by the package array) but creates PGF/TikZ nodes under the cells, rows and columns.

Then it's possible to use those nodes with TikZ in the co-called \CodeAfter to draw whatever rule you want.

\documentclass{article}
\usepackage{nicematrix,tikz}

\begin{document}

\begin{center} \begin{NiceTabular}{*{8}{c}}[first-col,last-row,hvlines] 1 \ 2 \ 3 \ 4 \ 5 \ 6 \ 7 \ 8 \ & a & b & c & d & e & f & g & h \CodeAfter \tikz \draw [red] (6-|3) -- (7-|3) ; \end{NiceTabular} \end{center}

\end{document}

Output of the first code

It's also possible to use the command \Block (provided by niceamtrix) and its key borders to draw the border of the cell with the command inserted at the right place.

\documentclass{article}
\usepackage{nicematrix,tikz}

\begin{document}

\begin{center} \begin{NiceTabular}{*{8}{c}}[first-col,last-row,hvlines] 1 \ 2 \ 3 \ 4 \ 5 \ 6 & & \Block[borders={tikz={color=red},right}]{}{}\ 7 \ 8 \ & a & b & c & d & e & f & g & h \end{NiceTabular} \end{center}

\end{document}

Output of the above code

F. Pantigny
  • 40,250