2

I'm trying to recreate this table: enter image description here

How do I align all the truth values beneath these headers as such? My current code is as follows:

\documentclass{article}
\usepackage[utf8]{inputenc}

\begin{document}
\ttfamily{
\begin{tabular}{c|c|cccccc} \hline
$p$ & $q$ & \multicolumn{2}{c}{${\sim}(p\land{q})$} & $\Leftrightarrow$ & \multicolumn{3}{c}{$[({\sim}p)\lor({\sim}q)]$} \\ \hline
T & T & F & T & T & F & F & F \\
T & F & T & F & T & F & T & T \\
F & T & T & F & T & T & T & F \\
F & F & T & F & T & T & T & T \\ \hline
\end{tabular}}

\end{document}

Which gives me this:

enter image description here

It appears that every column is centered but not evenly split between the headings.

As a bonus question: Also looking to generate that box around the \iff column but haven't researched to find an answer for that yet.

dylanjm
  • 207
  • Side note: \ttfamily is a macro without an argument -- \ttfamily{} would not delimit the font change to the table only. Most likely, you meant {\ttfamily...} –  Dec 28 '17 at 05:48
  • You may be interested in https://tex.stackexchange.com/a/286908/4427 – egreg Dec 28 '17 at 22:12

1 Answers1

1

Instead of using \multicolumn, I have created a tabular of tabulars, so it's easy to have the columns/subtables centered and the one framed.

I've also done some adjustment with \rule{0pt}{8ex} and a fake row to have the frame separated from the \hlines.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\setlength\extrarowheight{2pt}

\begin{document}
{\ttfamily%
\begin{tabular}{c|c|ccc} 
\hline
$p$ & $q$ & ${\sim}(p\land{q})$ & $\Leftrightarrow$ & $[({\sim}p)\lor({\sim}q)]$ \\ 
\hline
\rule{0pt}{8ex}% to separate the framed column from the \hline
\begin{tabular}{@{}b{1em}@{}}
            T\\
            T\\
            F\\
            F\\
\end{tabular}
&
\begin{tabular}{@{}c@{}}
T\\
F\\
T\\
F\\
\end{tabular}
&
\begin{tabular}{@{}cc@{}}
F & T\\
T & F\\
T & F\\
T & F\\
\end{tabular}
&
\begin{tabular}{|c|}
\hline
T\\
T\\
T\\
T\\
\hline
\end{tabular}
&
\begin{tabular}{@{}ccc@{}}
F & F & F \\
F & T & T \\
T & T & F \\
T & T & T \\
\end{tabular}\\[-2.5ex]
&&&&\\%fake row to separate the framed column from the \hline
\hline
\end{tabular}
}%end \ttfamily effect
\end{document}

enter image description here

CarLaTeX
  • 62,716
  • Thanks, this is perfect and exactly what I was looking. There was a previous answer that was good as well but this answer is to the T, exactly what I was trying to attain. Thanks. – dylanjm Dec 28 '17 at 21:28
  • 1
    You're welcome and thank you for accepting my answer! Christian Hupfer deleted his answer, I don't know why, maybe because the framed column was missing. However it was good as well, as you said. – CarLaTeX Dec 28 '17 at 21:40