19

I want to draw a table with two \hline and two vertical line. But as shown in the figure, the first vertical line do not cross the two hline. How to solve this problem?

\documentclass{article}
\usepackage{hhline}
\begin{document}

\begin{tabular}{c||c||c}
\hline 
1 & 2 & 3 \\ \hhline{=|=|=}
4 & 5 & 6 \\ \hline
7 & 8 & 9 \\ \hline
\end{tabular}

\end{document}

output

lockstep
  • 250,273
  • 3
    Minimize the use of vertical lines in tables. They disturb more than they help. – Svend Tveskæg Jan 02 '14 at 10:00
  • 6
    +Svend I couldn't disagree more. SOME tables look nice without vertical lines, but there are MANY tables that demand them, and the notion that they should be avoided at all cost is a horrific one that is way too prevalent in the LaTeX community. – Travis Bemrose Feb 01 '16 at 13:02

4 Answers4

24

As stated in the hhline package documentation, | gives you a vertical line which cuts through a double (or single) hline, whereas # gives a double hline segment between two vlines.

So, to correct your situation (leaving aside the aesthetic issues) simply use, # in place of the | in the argument for \hhline.


\documentclass{article}
\usepackage{hhline}
\begin{document}

\begin{tabular}{c||c||c}
\hline 
1 & 2 & 3 \\ \hhline{=#=#=}
4 & 5 & 6 \\ \hline
7 & 8 & 9 \\ \hline
\end{tabular}

\end{document}

You get the following output.

enter image description here


For further reading, please see the hhline package documentation mentioned above. Also, you may like to see this question as well.

Masroor
  • 17,842
3

Don't use vertical lines in tables; they disturb more than they help.

\documentclass{article}

\usepackage{booktabs}

\begin{document}

\begin{tabular}{ccc}
\toprule
1 & 2 & 3 \\
\midrule
4 & 5 & 6 \\
\midrule
7 & 8 & 9 \\
\bottomrule
\end{tabular}

\end{document}

output

0

For information, in {NiceTabular} of nicematrix, the vertical rules (specified by the symbols | in the preamble) are not interrupted by the double horizontal rules (specified by \hline\hline).

\documentclass{article}
\usepackage{nicematrix}
\begin{document}

\begin{NiceTabular}{c||c||c} \hline 1 & 2 & 3 \ \hline\hline 4 & 5 & 6 \ \hline 7 & 8 & 9 \ \hline \end{NiceTabular}

\end{document}

Output of the above code

F. Pantigny
  • 40,250
-3
\documentclass{article}

\usepackage{booktabs}

\begin{document}

\begin{tabular}{c| |c| |c}
\toprule
1 & 2 & 3 \\ \hline
\hline
4 & 5 & 6 \\ \hline \hline
7 & 8 & 9 \\
\bottomrule
\end{tabular}

\end{document}

It looks pretty! This looks nicer