How do I draw this table? I am not able to place the variables outside the box. Also the the vertical borders are not of same length. So how do I vary the lengths of those vertical lines?
Secondly is there any simpler code to draw Karnaugh diagrams for 2x2 to 4x4 tables? Here this was described but I find this quite complicated to understand and run. In particular,
. No need of coloured text.
- 779
- 4
- 15
1 Answers
One solution with matrix of math nodes.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix(m) [matrix of math nodes, nodes in empty cells, nodes={minimum size=1cm, outer sep=0pt, text height=1.5ex, text depth=.25ex}]
{
& b_1 & b'_1 & \
& & & b'_3 \
& & & \
& & & \
& & & b'_3 \
};
\draw (m-1-1.south east) rectangle (m-5-3.south east);
\draw (m-1-2.north east) -- (m-5-2.south east);
\draw (m-2-1.south east) node[left=2.5mm] {$b_2$} -- (m-2-4.south east);
\draw (m-3-1.south west) -- (m-3-4.south west) node[right=2.5mm] {$b_3$};
\draw (m-4-1.south east) node[left=2.5mm] {$b'_2$} -- (m-4-4.south east);
\end{tikzpicture}
\end{document}
I think you may check the NiceTabular package with which you could create some very nicematrix in a nutshell.
- 19,186
-
with
tikzpackage, I a receiving the error thatxstring.styis not found. – Manjoy Das Apr 24 '21 at 15:56 -
can you plz help me with the table drawing by pointing the directions. I have no idea about
south eastcommands. – Manjoy Das Apr 24 '21 at 15:57 -
1When creating a matrix of nodes like this one, you create a table with 5 rows and 4 columns, named
(m). Each cell (node) of this matrix is known by(m-row-col), i.e.(m-2-3)means the cell at the 2nd row and the 3rd column. Each cell is a node, so you can call their many anchors (north, south, east, west, etc.) If you want to draw a line above a row, you draw from the above left corner of the first cell to the above right corner of the last one. Hence the(m-5-2.north east)naming. Hope this is clear. – SebGlav Apr 24 '21 at 16:44
matrix of nodes. Do you want to insert values in the boxes later? Please, feel free to be more specific about the final purpose of this. – SebGlav Apr 24 '21 at 13:01