2

I need to draw Karnaugh Map for a book. package mentioned in this answer Drawing Karnaugh's maps in LaTeX is excellent. I have two questions

  1. How to turn colouring On.
  2. Can we shift position of x,y,z as shown in the alternate answer

.

\documentclass{memoir}    
\usepackage{tikz,xcolor}
\usepackage{karnaugh-map}
\begin{document}
    \begin{karnaugh-map}*[4][2][1][$yz$][$x$]
        \maxterms{0,2,3}
        \minterms{1,4,5,6,7}
        \autoterms[X]
        \implicant{4}{6}
        \implicant{1}{5}
    \end{karnaugh-map}
\end{document}

2 Answers2

5
  1. Coloring is turned off when adding an asterisk to the environment. See the documentation for more information. Therefore remove the asterisk when you begin the karnaugh-map environment making your environment line;

    \begin{karnaugh-map}[4][2][1][$yz$][$x$]
    
  2. This is not directly supported by the package. Fortunately this could manually be done with version v1.0 as suggested in the answer by @epR8GaYuh. It can even be done without modifying the package. If you supply an empty set of labels, they will "disappear" and you may add you own using tikz. Finally you could also add decorations if desired. Based on code from your linked example by Ignasi the following can be produced:

    \documentclass{standalone}
    \usepackage{karnaugh-map}
    \begin{document}
      \begin{karnaugh-map}[4][2][1][][] % note empty X and Y labels
        \maxterms{0,2,3}
        \minterms{1,4,5,6,7}
        \autoterms[X]
        \implicant{4}{6}
        \implicant{1}{5}
        % note: posistion for start of \draw is (0, Y) where Y is
        % the Y size(number of cells high) in this case Y=2
        \draw[color=black, ultra thin] (0, 2) --
        node [pos=0.7, above right, anchor=south west] {$yz$} % Y label
        node [pos=0.7, below left, anchor=north east] {$x$} % X label
        ++(135:1);
      \end{karnaugh-map}
    \end{document}
    

    Example This should work for all combinations of maps with one submap(Z size = 1) provided that Y is changed accordingly and could further be customized to work with multiple submaps if needed.

Disclaimer: I'm the author of karnaugh-map

Mattias
  • 151
4
  1. According to the documentation (see here) removing the star at the start of the karnaugh-map environment is the right way. It should be \begin{karnaugh-map}[4][2][1][$yz$][$x$] then.

  2. Without making changes to the source code of the package itself this does not seem to be possible as the positions for the labels are "hardcoded" (source code). If you comment out lines 250 to 268 inside karnaugh-map.sty you could play a little bit based on this code:

    \documentclass{standalone}
    \usepackage{karnaugh-map}
    \begin{document}
        \begin{karnaugh-map}[4][2][1][$yz$][$x$]
            \maxterms{0,2,3}
            \minterms{1,4,5,6,7}
            \autoterms[X]
            \implicant{4}{6}
            \implicant{1}{5}
            \node at (-0.25,2.5) {$yz$};           % row name
            \node at (-0.6,2.25) {$x$};            % column name
            \draw[ultra thin] (0,2) -- (-1,2.75);  % diagonal line
        \end{karnaugh-map}
    \end{document}
    
epR8GaYuh
  • 2,432