I used this truth table when writing a proof.
Unfortunately I made a tiny typo; The first time around, I misplaced an additional ʹ
symbol, which just happened to make the output exactly wrong. It ended up taking me forever to understand why nothing after that seemed to add up the way I knew it should.
It led me to wonder. Is it possible to build some kind of macro that will allow me to generate accurate truth tables according to a given input? In other words: I'd like it to work something like:
\truthtable{A, B, ( A \oplus B )', (A) \oplus (B')}
As opposed to having to draw the entire thing manually, potentially making errors. How would you even begin to program something like this in LaTeX?
Here's the full manual MWE for the table pictured above:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[border=10pt]{standalone}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%hdashline
\usepackage{array}
\usepackage{arydshln}
\setlength\dashlinedash{0.2pt}
\setlength\dashlinegap{1.5pt}
\setlength\arrayrulewidth{0.3pt}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{table}[htbp!]
\centering
\caption{}
\label{tab}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tabular}{@{}cccc@{}}
\toprule%%–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
$A$ & $B$ & $(A \oplus B)'$ & $(A) \oplus (B')$ \\
\midrule%%–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
0 & 0 & 1 & 1 \\ \hdashline%%··········································
0 & 1 & 0 & 0 \\ \hdashline%%··········································
1 & 0 & 0 & 0 \\ \hdashline%%··········································
1 & 1 & 1 & 1 \\ \bottomrule%––––––––––––––––––––––––––––––––––––––––––
\end{tabular}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Best Answer
This is something quickly written. Does not steer the Mars rover, in fact it is just a one-liner. If you make your code copyable I will add all the table options, if needed. (In fact, I made zero efforts to make the output "pretty", nor to suppress spaces or empty lines.) Also one can use a loop to create all the rows. I added explanations to the output.