I highly recommend kvmacros
. It isn't your average package which you can simply use with \usepackage{}
, instead you have to manually install it, but this should not be a problem.
It is not the most intuitive, but if you play with it a little, you'll get the idea.
So, here how the code could look:
\documentclass{article}
\input{kvmacros}
\begin{document}
\karnaughmap{5}{}%
{{$x_1$}{$x_4$}{$x_2$}{$x_5$}{$x_3$}}%
{%
0011011001101000%
0110011011001000%
}%
{%
%Single Ones
\put(2.5,3.5){\oval(0.9,0.9)[]}
\put(1.5,0.5){\oval(0.9,0.9)[]}
\put(7.5,2.5){\oval(0.9,0.9)[]}
\put(0.5,1.5){\oval(0.9,0.9)[]}
%Pairs of Ones
\put(1,2.5){\oval(1.9,0.9)[]}
\put(4,2.5){\oval(1.9,0.9)[]}
\put(6,3.5){\oval(1.9,0.9)[]}
\put(7,0.5){\oval(1.9,0.9)[]}
\put(4,0.5){\oval(1.9,0.9)[]}
}
\end{document}
And most importantly the result:
I am assuming every not 1 is 0 (else simply use ~
). If you don't need the number in each square, you could just put \kvnoindex
in front, for other options just consult the documentation.
EDIT: This might be more than was asked, but here is another example, with a more fancy result.
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\input{kvmacros}
\begin{document}
\karnaughmap{5}{$f(x_i)$}%
{{$x_1$}{$x_2$}{$x_3$}{$x_4$}{$x_5$}}%
{%
0011011001100110%
0110011001000110%
}%
{%
%Single Ones
\textcolor{Blue}{
\put(2.5,3.5){\oval(0.9,0.9)[]}
\put(7.5,2.5){\oval(0.9,0.9)[]}
\put(0.5,1.5){\oval(0.9,0.9)[]}}
%Pairs of Ones
\put(1,2.5){\oval(1.9,0.9)[]}
%Quadruples of Ones
\textcolor{Yellow}{
\put(4,2){\oval(1.9,1.9)[]}}%
\textcolor{Green}{
\put(6,4){\oval(1.9,1.9)[b]}
\put(6,0){\oval(1.9,1.9)[t]}}%
\textcolor{Red}{
\put(5,0.5){\oval(3.9,0.9)[r]}
\put(3,0.5){\oval(3.9,0.9)[l]}}
}
\end{document}
Here the result:
Have Fun!
Best Answer
With the
kvmap
package you can input your Karnaugh map like a tabular. This works even for very large sizes (I just tested 64x64 fields), so it is definitely able to typeset an 8x8 map.If you want to draw implicants you can use the
\bundle
macro and pass the coordinates of the corners to it. For further explanation see the old answer (which explains the code a bit better).Full code example:
Old answer
The following code will produce Karnaugh maps in any size you want it to have (tested for some 2n) as TikZ pictures. You input your map like you would input a table in LaTeX using the
kvmatrix
environment. The only argument of this environment is a comma-separated list of your variable names. Therefore a simple 2x2 matrix would look likeThere is a second environment provided,
kvmap
, which is basically a tikzpicture (but for the sake of semantic consistency). You should use this if you are planning to work with the fields. Each field is named by its x- and y-index in the following way:xy
(where00
is the top-left corner andnm
is the bottom-right corner with n+1 and m+1 as the dimensions of your matrix, e.g.11
for a 2x2 matrix).The code is also able to draw borders around cells which can be bundled. Therefore you would use the command
\package[options]{x1}{y1}{x2}{y2}
with the coordinates of the corners of the rectangle. If the package should be open to the margin use theinvert
option (if the coordinates are at the outer-most rows/columns; theoverlapmargins
option specifies how far the bundle is drawn into the margin). You can color a package with thecolor
option and to avoid overlapping with other packages specify a reduction of space withreducespace
.Here the working code: