[Tex/LaTex] Creating truth tables using over/underbrace with array environment

amsmatharraysmath-modespacing

Using the code

\documentclass{article}
\usepackage{amsmath}
\usepackage{array}
\newcolumntype{C}{>$c<$}
\begin{document}
\[
\begin{array}{C|C|C|C|C|C}
$p$ & $q$ & $p\land q$ & $\overbrace{(p\land q)\to p}^{\textbf{(a)}}$ & $p\lor q$ & $\overbrace{p\to (p\lor q)}^{\textbf{(b)}}$\\
\hline
T & T & T & T & T & T\\
T & F & F & T & T & T\\
F & T & F & T & T & T\\
F & F & F & T & F & T
\end{array}
\]
\end{document}

I get the following:
enter image description here

I can also use

\begin{array}{C|C|C|C|C|C}
$p$ & $q$ & $p\land q$ & $(p\land q)\to p$ & $p\lor q$ & $p\to (p\lor q)$\\
\hline
T & T & T & T & T & T\\
T & F & F & T & T & T\\
F & T & F & T & T & T\\
F & F & F & $\underbrace{\text{T}}_{\textbf{(a)}}$ & F & $\underbrace{\text{T}}_{\textbf{(b)}}$
\end{array}

to get
enter image description here

The only problem, in both cases, is that I want the over/underbrace usage, but I do not want the vertical lines to extend for all of the columns. Is there a way to accomplish the overbrace effect without having the vertical bars scale with it?

Note: If someone can think of a better title for this post and/or more appropriate tags, then please change for whatever works best.

Best Answer

You could use the \smash macro to encase the expressions with \overbrace and \underbrace material.

Since the tables are mostly set in text mode (except for the header row), I suggest you use tabular instead of array environments. Furthermore, consider using center environments instead of encasing the tables in \[ and \] statements. Finally, you should contemplate getting rid of all vertical bars in the tables and using \midrule (from the booktabs package) instead of \hline. This will give you a much more open look.

Actually, without the vertical bars, using \smash isn't strictly necessary. However, I suggest you keep the \smash directives, just in case you do decide to retain (or bring back) the vertical bars in the tables.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\usepackage{booktabs} % for "\midrule" macro
\usepackage{lipsum} % for filler text
\begin{document}
\lipsum[2]
\bigskip % some extra vertical space *above* the first "center" env.
\begin{center}
\begin{tabular}{cccccc}
$p$ & $q$ & $p\land q$ & $\smash{\overbrace{(p\land q)\to p}^{\textbf{(a)}}}$ & $p\lor q$ & $\smash{\overbrace{p\to (p\lor q)}^{\textbf{(b)}}}$\\
\midrule
T & T & T & T & T & T\\
T & F & F & T & T & T\\
F & T & F & T & T & T\\
F & F & F & T & F & T\\
\end{tabular}
\end{center}

\lipsum[2]

\begin{center}
\begin{tabular}{cccccc}
$p$ & $q$ & $p\land q$ & $(p\land q)\to p$ & $p\lor q$ & $p\to (p\lor q)$\\
\midrule
T & T & T & T & T & T\\
T & F & F & T & T & T\\
F & T & F & T & T & T\\
F & F & F & $\smash{\underbrace{\text{T}}_{\textbf{(a)}}}$ & F & $\smash{\underbrace{\text{T}}_{\textbf{(b)}}}$\\
\end{tabular}
\end{center}

\bigskip  % some extra vertical space *below* the second "center" env.
\lipsum[2]
\end{document}