7

how to make some border lines of a table thick and colored (either vertical lines or horizental lines)?I tried Xcline but could not color it. Also I tried make the cline thick but failed.

2
  • 2
    Please post a minimal working example (MWE) of what you have tried.
    – CarLaTeX
    Sep 15, 2017 at 4:04
  • 1
    Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See minimal working example (MWE). Sep 15, 2017 at 5:13

2 Answers 2

17

enter image description here

\documentclass{article}

\usepackage{hhline,colortbl}

\begin{document}
\arrayrulecolor{green}

\begin{tabular}{
 !{\color{red}\vrule width 2pt}
 l
 |
 c
 !{\color{blue}\vrule width 2pt}
 c
 ||
}
 one & two & three\\
\hline
  1 & 2 & 3\\%
\noalign{
\color{yellow}
\hrule height 5pt
}%
4&5&6\\
\hline
\end{tabular}
\end{document}
5
  • 1
    As usual I'm impressed by your answer. I also hope that the example was meant to discourage the questioner's design idea. Sep 15, 2017 at 17:44
  • 6
    @PeterWilson oh now I'm hurt, I thought it was an example of a pinnacle of typographic design:( Sep 15, 2017 at 18:27
  • Further, How to just make parts of border lines thick and colored.
    – alex
    Sep 18, 2017 at 4:30
  • If I'm trying to color the last line of the table using the same syntax, the red vertical line goes beyond the last horizontal line. How can I solve it ?
    – 3isenHeim
    Nov 26, 2019 at 7:13
  • 1
    @EisenHeim please don't ask new questions as comments on old answers, that means you have an error somewhere, perhaps you have \\ after the line. Nov 26, 2019 at 7:53
0

With nicematrix, you can draw rules with all the characteristics of lines of TikZ.

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

\begin{document}

\begin{NiceTabular}{|c|[tikz={very thick,blue}]cc}
\Hline[tikz={very thick,red}]
one & two & three \\
four & five & six \\
seven & eight & nine 
\end{NiceTabular}

\end{document}

Output of the above code

Of course, you can define your own short-cuts with \newcommand and \newcolumntype.

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

\newcommand{\ThickHline}{\Hline[tikz={very thick,red}]}
\newcolumntype{I}{|[tikz={very thick,blue}]}

\begin{document}

\begin{NiceTabular}{|cIcc}
\ThickHline
one & two & three \\
four & five & six \\
seven & eight & nine 
\end{NiceTabular}

\end{document}

The output is the same.

However, nicematrix provides also a key to define in a comprehensive way tools for your personal style of rules (with the ability to define a command similar to \cline).

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

\NiceMatrixOptions
  {
    custom-line = 
     {
       command = ThickHline ,
       ccommand = ThickNCLine ,
       letter = I ,
       tikz = { very thick, blue }
     }
  }

\begin{document}

\begin{NiceTabular}{|cIcc}
\ThickHline
one & two & three \\
four & five & six \\
\ThickNCLine{2-3}
seven & eight & nine 
\end{NiceTabular}

\end{document}

Output of the above code

Eventually, it's possible with the tools of nicematrix, to draw with TikZ whatever rule you want but using the PGF/TikZ nodes created by nicematrix under the cells, rows and columns of the tabular.

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

\begin{document}

\begin{NiceTabular}{|ccc}
one & two & three \\
four & five & six \\
seven & eight & nine 
\CodeAfter
  \tikz \draw [very thick, blue] (2-|2) -- (3-|3) ;
\end{NiceTabular}

\end{document}

Output of the last code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .