The context
While studying logic, I found myself creating truth tables with different numbers of propositional variables. Sometimes I need to create a truth table for propositions that contains 6 propositional variables which results in a huge table. The one I'm presenting here is a minimal working example.
\documentclass{article}
\begin{document}
\begin{center}
\begin{tabular}{*{3}{|c}|}
\hline
$p$ & $q$ & $p \wedge q$ \\ \hline
0 & 0 & 0 \\ \hline
0 & 1 & 0 \\ \hline
1 & 0 & 0 \\ \hline
1 & 1 & 1 \\ \hline
\end{tabular}
\end{center}
\end{document}
I would find this table easier to see if cells that contain 1s are filled with an specific color and cells that contains 0s are empty (see below).
\documentclass{article}
\usepackage[table]{xcolor}
\begin{document}
\begin{center}
\begin{tabular}{*{3}{|c}|}
\hline
$p$ & $q$ & $p \wedge q$ \\ \hline
& & \\ \hline
& \cellcolor{gray!50!white} & \\ \hline
\cellcolor{gray!50!white} & & \\ \hline
\cellcolor{gray!50!white} & \cellcolor{gray!50!white} & \cellcolor{gray!50!white} \\ \hline
\end{tabular}
\end{center}
\end{document}
However, this would clutter up the code of a table which presents such a simple topic. Ideally, the code from \tabular
environment from the first table should generate the second table shown.
Of course, I can create a macro for both kinds of cells to accomplish that but
- that would also clutter up the
tabular
environment. - that would make text processing of columns more difficult since all columns are not of the same size. When saying "text processing" I'm referring to tasks such as sort a given column: When the contents of this columns are 0s and 1s sorting the columns is easier than if the size of each row were different and their contents are characters from the latin alphabet.
- the number of characters needed to typeset a table does not significantly decrease.
I've never done something like this so I don't know where to search for.
The question
How can I make a table whose source code shows 1s and 0s such that in the output 0s and 1s are replaced with a given value (in this scenario, 1s and 0s would be replaced with the \cellcolor
command and nothing, respectively, in all columns)?
In general, I would like this to occur for some specified columns from a given table. That is, this behavior must not occur in all columns.