1

I have two tables, but I can't figure out why it doesn't have vertical line at the right of the table. Could you tell me, where I've made mistake?

First one:

    \newline
\begin{center}
\begin{tabular}{||c c c c c c||} 
 \hline
 $\emph{p}$ & $\emph{q}$ & $([\emph{p} \wedge$ & $(\emph{p} \Rightarrow \emph{q]})$ & $\Rightarrow$ & $\emph{q}$ \\ [0.5ex] 
 \hline\hline
 0 & 0 & 0 & 1 & 1\\ 
 \hline
 0 & 1 & 0 & 1 & 1\\
 \hline
 1 & 0 & 0 & 0 & 1\\
 \hline
 1 & 1 & 1 & 1 & 1\\
 \hline
\end{tabular}
\end{center}

Second one:

    \newline
\begin{center}
\begin{tabular}{||c c c c c c c c c||} 
 \hline
 $\emph{p}$ & $\emph{q}$ & $\neg$ & $(\emph{p} \vee \emph{q})$ & $\leftrightarrow$ & $(\neg\emph{p}$ & $\wedge$ & $\neg\emph{q})$ \\ [0.5ex] 
 \hline\hline
 0 & 0 & 1 & 0 & 1 & 1 & 1 & 1\\ 
 \hline
 0 & 1 & 0 & 1 & 1 & 1 & 0 & 0\\
 \hline
 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1\\
 \hline
 1 & 1 & 0 & 1 & 1 & 0 & 0 & 0\\
 \hline
 \hline
\end{tabular}
\end{center}
  • 2
    in the first table you specified a rule after the 6th column, but you only have 5 columns and in second table you have a rule after the 9th column but only 8 columns – David Carlisle Nov 02 '21 at 18:48
  • Off-topic: what you like to achieve with $\emph{q}$? Correct is just `$q$ ... etc – Zarko Nov 02 '21 at 18:53
  • @DavidCarlisle I'm sorry, but I can't find that rule. I'm totally new to Latex. I've been using it for like 2 hours. – GuwniakSmierdzoncy Nov 02 '21 at 18:57
  • @Zarko thank's! I'll change it. – GuwniakSmierdzoncy Nov 02 '21 at 18:57
  • Following @DavidCarlisle's suggestion, that's often why it's contextually easier to use the *{<num>}{<col spec>} approach to defining your tabular column specification. In your first instance: || *{6}{c} || would help highlight there are 6 columns; your second instance: || *{9}{c} || would help highlight there are 9 columns. – Werner Nov 02 '21 at 19:01
  • you have 6 c cccccc|| so if you have 6 columns the last one will get || but you only have 5 columns, delete one of the c – David Carlisle Nov 02 '21 at 19:01
  • Thank you guys! Really appreciate it. – GuwniakSmierdzoncy Nov 02 '21 at 19:09

1 Answers1

1

Your issue is related to specifying too many columns and then not using them all. Your first table has a column specification with 6 centered columns, while you only supply 5 values per row before terminating the row (with \\). That leaves the last column (which also holds the righthand ||) out of the row and therefore no vertical rules on the right. The same principle holds for the second table. In general, you can use a *{<num>}{<col spec>} approach to defining <num> columns, each of which will have a <col spec> specification. For example, *{5}{c} would be equivalent to c c c c c, and *{3}{| c p{2cm}} would be equivalent to | c p{2cm} | c p{2cm} | c p{2cm}. It's sometimes easier to ensure the same number of columns in the specification and the table by using the abbreviated form.

Here's a slightly different approach to showing the content, using booktabs. It shows:

enter image description here

\documentclass{article}

\usepackage{booktabs}

\begin{document}

[ \begin{array}{ c c c @{,} c c c @{,} c c c } \toprule p & q & [ & p & \wedge & (p \Rightarrow q) & ] & \Rightarrow & q \ \midrule 0 & 0 & & 0 & 0 & 1 & & 1 & 0 \ 0 & 1 & & 0 & 0 & 1 & & 1 & 1 \ 1 & 0 & & 1 & 0 & 0 & & 1 & 0 \ 1 & 1 & & 1 & 1 & 1 & & 1 & 1 \ \bottomrule \end{array} ]

[ \begin{array}{ c c c @{} c c c @{,} c c c @{,} c } \toprule p & q & \neg & (p \vee q) & \leftrightarrow & ( & \neg p & \wedge & \neg q & ) \ \midrule 0 & 0 & 1 & 0 & 1 & & 1 & 1 & 1 & \ 0 & 1 & 0 & 1 & 1 & & 1 & 0 & 0 & \ 1 & 0 & 0 & 1 & 1 & & 0 & 0 & 1 & \ 1 & 1 & 0 & 1 & 1 & & 0 & 0 & 0 & \ \bottomrule \end{array} ]

\end{document}

Note that @{<stuff>} in the column specification changes the space between the adjacent columns to <stuff>. So, in the above cases, I insert a small horizontal space \, between the two columns.

Werner
  • 603,163