Make a truth table in LaTeX​

Truth tables are used for several important purposes in mathematics, computer science, and logic. If you are writing in LaTeX then you may need to create a truth table using LaTeX.

In this tutorial, I am going to show you two different methods that can be used to create a truth table in LateX. One is using the array environment and the other one uses the tabular environment.

Method 1: Using the array Environment

Below is an example of creating a simple truth table with the help of array environment:

\[
\begin{array}{|c|c|c|c|}
\hline
A & B & A \land B & A \lor B \\ \hline
0 & 0 & 0 & 0 \\ \hline
0 & 1 & 0 & 1 \\ \hline
1 & 0 & 0 & 1 \\ \hline
1 & 1 & 1 & 1 \\ \hline
\end{array}
\]

Below is given complete document code:

\documentclass{article}
\begin{document}


\[
\begin{array}{|c|c|c|c|}
\hline
A & B & A \land B & A \lor B \\ \hline
0 & 0 & 0 & 0 \\ \hline
0 & 1 & 0 & 1 \\ \hline
1 & 0 & 0 & 1 \\ \hline
1 & 1 & 1 & 1 \\ \hline
\end{array}
\]


\end{document}

If you compile it, then you will able to see the result looks like below:

truth table

Also read: Fixed: Table Cutting on the Right side in LaTeX for wide table

Method 2: Using tabular Environment

Let’s create the same truth table using the tabular environment:

\[
\begin{tabular}{|c|c|c|c|}
\hline
A & B & A \land B & A \lor B \\ \hline
0 & 0 & 0 & 0 \\ \hline
0 & 1 & 0 & 1 \\ \hline
1 & 0 & 0 & 1 \\ \hline
1 & 1 & 1 & 1 \\ \hline
\end{tabular}
\]

And below is the complete code:

\documentclass{article}
\begin{document}

\[
\begin{tabular}{|c|c|c|c|}
\hline
A & B & A \land B & A \lor B \\ \hline
0 & 0 & 0 & 0 \\ \hline
0 & 1 & 0 & 1 \\ \hline
1 & 0 & 0 & 1 \\ \hline
1 & 1 & 1 & 1 \\ \hline
\end{tabular}
\]

\end{document}

It will give the same result as the method 1.

Leave a Reply

Your email address will not be published. Required fields are marked *