In a document, I have to include those simple diagrams to show the procedure of reducing logical circuits.
What do you think is the best way to do them?
graphics
In a document, I have to include those simple diagrams to show the procedure of reducing logical circuits.
What do you think is the best way to do them?
Best Answer
When I had to draw Karnaugh maps for my computer organization class, I use the
colortbl
package and colored individual cells; however, this got really bulky really quickly, and required coloring the intersections manually. Knowing what I do now, I'd use a TikZ matrix:This produces the following output:
Oddly, the most complicated part of this solution is probably labeling the rows and columns with
00
, etc., and drawing the separating vertical and horizontal lines. Other than that, things are pretty straightforward. Thematrix of math nodes
option tells TikZ to surround each entry in the matrix with\node {$
and$};
. If you want to play with the spacing, you can use therow sep=
andcolumn sep=
options. Next, I loop over each row/column index, and place the label a bit away from said row. Finally, I place the global labels further away. Drawing the edges uses the(pt-a -| pt-b)
coordinate syntax, which says "place this point on the intersection of a horizontal line frompt-a
and a vertical line frompt-b
";|-
reverses which uses the horizontal line. Looking at that should make it clear why those were chosen; they draw the separating lines.Finally, we draw the regions in the Karnaugh map. We work on the background layer (which was declared at the start of the document), and just surround each region with a semi-transparent colored rectangle. TikZ will handle the blending for us.
Edit: Since you requested a solution in LaTeX or ConTeXt, I should add that TikZ works with plain TeX, LaTeX, and ConTeXt, so this'll work in both cases. The TikZ manual tells you what needs to change when using ConTeXt (not much); if I recall, the environments mostly become
\starttikzpicture
/\stoptikzpicture
pairs and the like, but I don't use ConTeXt, so I'm not sure.