4

I'm trying to add a vertical double line to the horizontal one using \hhline. I want to add this double vertical line after column Year, before (a,b) in my table (the second line from the left). I want this new vertical double line to go from the top, down to the bottom of the table.

My code is:

  \begin{table}[h!]
  \begin{center}
  \begin{tabular}{|c|c|c|c|c|c|}
  \hline
  Year & a & c &e & g\\ 
  &b & d &   f &h \\ \hhline{|=|=|=|=|=|} 
  1995 & 423 & 1049.5 & 3.4 & 31.1 \\ \hline  
  1996 & 224 & 1009.9 & 3.2 & 31.0\\ \hline
  1997 & 209 & 1069.1* & 3.5 & 30.8\\ \hline
  1998 & 298 & 1270.9 & 4.0 & 31.9\\ \hline
  1999 & 322  & 1386.1 &4.2 & 32.9\\ \hline
  2000 & 507 & 1633.9 & 5.0&32.7 \\ \hline
  2001 & 472 & 1515.5 & 4.5&34.0\\ \hline
\end{tabular}
\end{center}

\end{table}

What do I do to improve it? I tried searching other threads but I couldn't get the solutions to work for me.

2
  • Welcome to TeX.SX! Please complete your code with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand, it's easier for us just copy-paste and run it.
    – CarLaTeX
    Commented Feb 20, 2017 at 17:21
  • don't use just h it usually generates a warning, better to use [htp] otherwise it is more likely the table goes to the end of the document. Also only use ! in exceptional cases where you want to ignore the current settings. Commented Feb 20, 2017 at 17:30

3 Answers 3

5

You don't need \hhline for this:

\begin{center}
 \begin{tabular}{|c||c|c|c|c|c|}
  \hline
  Year & a & c &e & g\\ 
  &b & d &   f &h \\ \hline\hline  % \hhline{|=|=|=|=|=|} 
  1995 & 423 & 1049.5 & 3.4 & 31.1\\ \hline  
  1996 & 224 & 1009.9 & 3.2 & 31.0\\ \hline
  1997 & 209 & \phantom{*}1069.1*& 3.5 & 30.8\\ \hline
  1998 & 298 & 1270.9 & 4.0 & 31.9\\ \hline
  1999 & 322 & 1386.1 & 4.2 & 32.9\\ \hline
  2000 & 507 & 1633.9 & 5.0 & 32.7\\ \hline
  2001 & 472 & 1515.5 & 4.5 & 34.0\\ \hline
 \end{tabular}
\end{center}

enter image description here

1
  • Unrelated to the main question, but what does the use of \phantom do here?
    – Adam_G
    Commented Nov 4, 2022 at 17:25
4

Vertical double-lines that cross double horizontal lines (=) require #. However, I'd go with a more open, booktabs presentation:

enter image description here

\documentclass{article}

\usepackage{hhline,booktabs}

\begin{document}

\begin{tabular}{|c||c|c|c|c|c|}
  \hline
  Year & a & c &e & g\\ 
  &b & d &   f &h \\
  \hhline{|=#=|=|=|=|} 
  1995 & 423 & 1049.5 & 3.4 & 31.1\\ \hline  
  1996 & 224 & 1009.9 & 3.2 & 31.0\\ \hline
  1997 & 209 & 1069.1\rlap{*} & 3.5 & 30.8\\ \hline
  1998 & 298 & 1270.9 & 4.0 & 31.9\\ \hline
  1999 & 322 & 1386.1 & 4.2 & 32.9\\ \hline
  2000 & 507 & 1633.9 & 5.0 & 32.7\\ \hline
  2001 & 472 & 1515.5 & 4.5 & 34.0\\ \hline
\end{tabular}

\bigskip

\begin{tabular}{ *{6}{c} }
  \toprule
       & a & c & e & g \\
  Year & b & d & f & h \\
  \midrule
  1995 & 423 & 1049.5 & 3.4 & 31.1 \\
  1996 & 224 & 1009.9 & 3.2 & 31.0 \\
  1997 & 209 & 1069.1\rlap{*} & 3.5 & 30.8 \\
  1998 & 298 & 1270.9 & 4.0 & 31.9 \\
  1999 & 322 & 1386.1 & 4.2 & 32.9 \\
  2000 & 507 & 1633.9 & 5.0 & 32.7 \\
  2001 & 472 & 1515.5 & 4.5 & 34.0 \\
  \bottomrule
\end{tabular}

\end{document}
0

If you actually want a double vertical line crossing a double horizontal line (without being broken), you might use {NiceTabular} of nicematrix. With the package, the vertical lines are drawn with PGF/TikZ and are never broken.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}{|c||c|c|c|c|}
  \hline
  Year & a & c &e & g\\ 
  &b & d &   f &h \\
  \hline\hline
  1995 & 423 & 1049.5 & 3.4 & 31.1\\ \hline  
  1996 & 224 & 1009.9 & 3.2 & 31.0\\ \hline
  1997 & 209 & 1069.1\rlap{*} & 3.5 & 30.8\\ \hline
  1998 & 298 & 1270.9 & 4.0 & 31.9\\ \hline
  1999 & 322 & 1386.1 & 4.2 & 32.9\\ \hline
  2000 & 507 & 1633.9 & 5.0 & 32.7\\ \hline
  2001 & 472 & 1515.5 & 4.5 & 34.0\\ \hline
\end{NiceTabular}

\end{document}

Output of the first code

However, if you want the default behavior of {tabular} with {NiceTabular} (because you want to use {NiceTabular} for other functionnalities), you can define a column I with the original definition of |.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\newcolumntype{I}{!{\vrule}}

\begin{NiceTabular}{|cIIc|c|c|c|}
  \hline
  Year & a & c &e & g\\ 
  &b & d &   f &h \\
  \hline\hline
  1995 & 423 & 1049.5 & 3.4 & 31.1\\ \hline  
  1996 & 224 & 1009.9 & 3.2 & 31.0\\ \hline
  1997 & 209 & 1069.1\rlap{*} & 3.5 & 30.8\\ \hline
  1998 & 298 & 1270.9 & 4.0 & 31.9\\ \hline
  1999 & 322 & 1386.1 & 4.2 & 32.9\\ \hline
  2000 & 507 & 1633.9 & 5.0 & 32.7\\ \hline
  2001 & 472 & 1515.5 & 4.5 & 34.0\\ \hline
\end{NiceTabular}

\end{document}

Output of the second code

You must log in to answer this question.

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