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.

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

  • Wow, that's fancy! Thanks a lot, works! – MateInTwo Jan 31 at 19:22
  • If I use the \multicolumn idea of yours for a cell on the rightmost column, it doesn't work, since it pushes the existing color into the next row. Any idea how to fix this? – MateInTwo Jan 31 at 19:42
  • @MateInTwo Can you make a minimal working example (MWE) that demonstrates your problem with the rightmost column? I just tested (see the edit to my answer) and while the alignment is not perfect when zoomed in, I don't see any colour in the next row. – samcarter Jan 31 at 20:21
  • Sorry, I hadn't seen the actual problem - it doesn't work if the cell is already colored. I put the two vertical red bars into the field h2 and that's where it bugged. It works fine if the cell is uncolored and on the right. – MateInTwo Feb 1 at 14:38
  • @MateInTwo Can you make a minimal working example (MWE) that reproduces your problem? – samcarter Feb 1 at 14:42

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.