40
\begin{tabular}{|c|c|c|}
Column 1 & Column 2 & column3 \\
\hline
second row & & \\
\hline
\end{tabular}

How do I change the border style? Using | I can draw thin solid vertical lines and \hline draws thin solid horizontal lines. I would like a thick outer border and thin dotted lines of various sizes and colors in the table. In short I would like to achieve similar functionality of attached screenshot of MS word table options in LaTeX. Also the reason for asking this is to put all table borders related answers in one place.

Thanks for your help. Screenshot of MS Word "Borders and Shading" dialog box

1
  • I wouldn´t like the look of dashed lines, even in illustrations, if you can use gray lines instead. Commented Feb 17, 2015 at 16:46

6 Answers 6

25
\documentclass{article}
\usepackage{array,booktabs,arydshln,xcolor}
\newcommand\VRule[1][\arrayrulewidth]{\vrule width #1}

\begin{document}

\begin{tabular}{!{\VRule[2pt]}c!{\VRule}c!{\color{red}\VRule[3pt]}c!{\VRule}}
Column 1 & Column 2 & column3 \\\specialrule{3pt}{0pt}{0pt}
second row & & \\\hdashline
third row  & & \\\specialrule{4pt}{0pt}{0pt}
\end{tabular}

\end{document}

enter image description here

2
  • I want to add a one bold horizontal line only between the two row... this method didn't work.
    – Fadwa
    Commented Oct 9, 2013 at 10:18
  • 7
    Please explain how this works.
    – Duncan
    Commented Mar 26, 2018 at 17:53
32

comparison of table layouts

Here are a few table layouts, with my favourite one last.

\documentclass{article}
\usepackage{xcolor}
\usepackage{booktabs}
\begin{document}
    \begin{tabular}{p{6cm}p{6cm}}
        \begin{tabular}{|c|c|c|}
        \hline
        Column 1 & Column 2 & Column 3 \\
        \hline
        second row & & \\
        \hline
        third row & & \\
        \hline
        \end{tabular}
        &
        \begin{tabular}{ccc}
        Column 1 & Column 2 & Column 3 \\
        \hline
        second row & & \\
        \hline
        third row & & \\
        \hline
        \end{tabular}
        \\[5em]
        \begin{tabular}{|ccc|}
        \hline
        Column 1 & Column 2 & Column 3 \\
        \hline
        second row & & \\
        third row & & \\
        \hline
        \end{tabular}
        &
        \begin{tabular}{|c|c|c|}
        \hline
        Column 1 & Column 2 & Column 3 \\
        \hline
        second row & & \\
        third row & & \\
        \hline
        \end{tabular}
        \\[5em]
        \begin{tabular}{ccc}
        Column 1 & Column 2 & Column 3 \\
        second row & & \\
        third row & & 
        \end{tabular}
        &
        \begin{tabular}{lll}
        \toprule
        Column 1 & Column 2 & Column 3 \\
        \midrule
        second row & & \\
        third row & & \\
        \bottomrule
        \end{tabular}
        \\[5em]
        % Colour for the rulings in tables:
        \makeatletter
           \def\rulecolor#1#{\CT@arc{#1}}
           \def\CT@arc#1#2{%
           \ifdim\baselineskip=\z@\noalign\fi
           {\gdef\CT@arc@{\color#1{#2}}}}
           \let\CT@arc@\relax
          \rulecolor{gray!50}
        \makeatother
        \begin{tabular}{@{}lll@{}}
        \toprule
        Column 1 & Column 2 & Column 3 \\
        \midrule
        second row & & \\
        third row & & \\
        \bottomrule
        \end{tabular}
       &
        \begin{tabular}{@{}lll@{}}
        \toprule
        Column 1 & Column 2 & Column 3 \\
        \cmidrule(r){1-1}\cmidrule(lr){2-2}\cmidrule(l){3-3}
        second row & & \\
        third row & & \\
        \bottomrule
        \end{tabular}
   \end{tabular}
\end{document}
5

There is the hhline package and the arydshln package. You can get colour in the table with the xcolor package.

You might have your reasons to typeset your tables with many different line styles... I'd usually recommend to avoid vertical lines at all and to draw horizontal lines with commands provided by the booktabs package.

In case you are writing something related to science, more or less all textbooks seem to roughly follow similar guidelines. Rarely you will find a vertical line.

4

An alternative solution with tblr environment of tabularray package:

\documentclass{article}

\usepackage{tabularray}
\usepackage{xcolor}

\begin{document}

\begin{tblr}{|[2pt,cyan3]c|[dashed,purple3]c|[dotted]c|[2pt,cyan3]}
\hline[2pt,cyan3]
Column 1   & Column 2 & column3 \\
\hline[purple3,dashed]
Second Row & Alpha    & Beta \\
\hline[dotted]
Third Row  & Gamma    & Delta \\
\hline[2pt,cyan3]
\end{tblr}

\end{document} 

enter image description here

1

With nicematrix, you have an environment {NiceTabular} constructed upon {tabular} (of array).

  • You can use the classical tools provided by array for the rules.

  • You can use the classical packages which apply to the tabulars of LaTeX (eg: aryshln for dashed rules).

  • {NiceTabular} has a built-in command \hdottedline and a letter : for dotted rules (with dots which are true circles).

  • In fact, nicematrix creates PGF/Tikz nodes under the cells, columns and rows of the environment, and so, it's possible to use Tikz to draw whatever rule you want (with the styles of Tikz).

However, you need several compilations (because nicematrix uses PGF/Tikz nodes).

\documentclass{article}

\usepackage{nicematrix}
\usepackage{tikz}

\begin{document}

\begin{NiceTabular}{|c:c|}
\hline
A & B \\
\hdottedline
C & D \\
\hline
\end{NiceTabular}


\bigskip
\begin{NiceTabular}{ccc}
A & B & C \\
E & F & G \\
H & I & J
\CodeAfter
\begin{tikzpicture}
\draw [dotted] (1-|1) -- (1-|4) ;
\draw [loosely dashed] (2-|1) -- (2-|4) ;
\draw [dash dot dot] (3-|1) -- (3-|4) ;
\draw [red, thick] (4-|1) -- (4-|4) ;
\draw [dotted] (1-|1) -- (4-|1) ;
\draw [loosely dashed] (1-|2) -- (4-|2) ;
\draw [dash dot dot] (1-|3) -- (4-|3) ;
\draw [red, thick] (1-|4) -- (4-|4) ;
\end{tikzpicture}
\end{NiceTabular}

\end{document}

Output of the above code

0

You can use all the flexibility permitted by LaTeX:

\usepackage{arydshln}
...

\begin{table}[h]
\begin{tabular}{lll}
\multicolumn{1}{c}{\textbf{Title 1}} &  & \multicolumn{1}{c}{\textbf{Title 2}} \\
\cline{1-1} \cline{3-3}
\multicolumn{1}{|l|}{Cell 1} & & \multicolumn{1}{|l|}{Cell 2} \\
\cdashline{3-3}
\multicolumn{1}{|l|}{Cell 3} & & \multicolumn{1}{|l|}{Cell 4} \\
\cline{3-3}
\multicolumn{1}{|l|}{Cell 5} & & \\
\cline{1-1}
\end{tabular}
\end{table}

The result is:

enter image description here

1
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Commented Feb 17, 2015 at 12:11

You must log in to answer this question.

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