2

So, to draw a table, I use the following Latex Code:

\begin{tabular}{|c|c|}
$p$ & $\bar{p}$\\
\hline\\
1 & 0\\
0 & 1
\end{tabular}

But somehow, this is the outcome

enter image description here

Can someone please explain where did I made a mistake? Thanks in advance.

  • 5
    Leave out the \\ after \hline – CarLaTeX Jan 16 '18 at 14:49
  • You're welcome! I think you could delete your question. – CarLaTeX Jan 17 '18 at 4:35
  • There are two other "mistakes" in case of a formal table for a serious journal: (1) Vertical lines. Avoid it! (2) \hline. Use \toprule,\bottomrule and \midrule instead of \hline for horizontal rules (need the the package booktabs in the preamble). – Fran Jan 17 '18 at 5:26
4

Putting a \\ after the \hline is like you are writing a row with empty cells.

The vertical line at the end of the empty row would appear if you wrote & \\, but of course you do not want an empty row, so simply leave out the \\.

\documentclass{article}

\begin{document}
Your table:
\begin{tabular}{|c|c|}
$p$ & $\bar{p}$\\
\hline\\
1 & 0\\
0 & 1
\end{tabular}

A table with an empty row:
\begin{tabular}{|c|c|}
$p$ & $\bar{p}$\\
\hline
&\\
1 & 0\\
0 & 1
\end{tabular}

The correct table:
\begin{tabular}{|c|c|}
$p$ & $\bar{p}$\\
\hline
1 & 0\\
0 & 1
\end{tabular}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.