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

2
  • 3
    Minimize the use of vertical lines in tables. They disturb more than they help. Commented Jan 2, 2014 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. Commented Feb 1, 2016 at 13:02

4 Answers 4

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.

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

3
  • 19
    It is not the answer to OP's question. Commented Jan 2, 2014 at 10:43
  • 1
    @PrzemysławScherwentke I don't agree with you. We've hand a "don't do this" answers with alternative provided before. Since TeX is about typography, it's not wrong to provide typographical alternatives to what OP asks for. See e.g. What's the quickest way to write “2nd” “3rd” etc in LaTeX
    – yo'
    Commented Jan 2, 2014 at 13:53
  • Thanks so much! It is beautiful but MMA gives the answer 'to' the question. Commented Jan 2, 2014 at 14:21
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

-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

1
  • This doesn't answer the question.
    – Werner
    Commented Jul 13, 2017 at 20:08

You must log in to answer this question.

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