5

I would like to draw something like this:

enter image description here

So I would like to highlight the path from 13 -> 9 -> 11 -> 3. How can I draw this path in a Karnough map?

edit: It don't has to be done with kvmacros, but I would like to have an example with which I can create other Karnaugh maps (with other marks of blocks of ones) without problems.

The Karnaugh map was pretty streight forward, although I would rather like the x at the bottom and w at the right.

\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{2mm}

\usepackage[dvipsnames]{xcolor}
\input{kvmacros}

\begin{document}
\begin{preview}
    \karnaughmap{4}{$f(w,x,y,z)$}{{$w$}{$x$}{$y$}{$z$}}%
    {
        1100
        1100
        0011
        0101
    }
    {
        \textcolor{Blue}{
            \put(2,3.5){\oval(3.9,0.9)[]}
        }
        \textcolor{WildStrawberry}{
            \put(0.9,3.5){\oval(1.7,0.8)[]}
        }
        \textcolor{Green}{
            \put(0.7,1.5){\oval(1.9,0.9)}
        }
        \textcolor{Sepia}{
            \put(1.5,1.5){\oval(1.6,0.7)}
        }
        \textcolor{Red}{
            \put(1.92,1){\oval(0.9,1.9)}
        }
        \textcolor{LimeGreen}{
            \put(1.76,-0.2){\oval(0.9,2.1)[t]}
            \put(1.76,4.2){\oval(0.9,2.1)[b]}
        }
    }
\end{preview}
\end{document}
4
  • I think the best way would be to use \tikzmark, but now sure where you are getting the magic coordinates from? – Peter Grill Mar 25 '13 at 21:57
  • Out of topic: you can reduce the number of keystrokes by using \documentclass[preview,border=2mm]{standalone} and removing \begin{preview} and \end{preview} from your document body. Thanks! – kiss my armpit Mar 25 '13 at 22:01
  • @Karl'sstudents: standalone does quite often not crop the image the the correct part, so I take preview in most of my examples. – Martin Thoma Mar 25 '13 at 22:07
  • @moose: With the option preview to the standalone class, you will do the same thing as you load preview package. One more benefit, you no longer need to explicitly specify \begin{preview}...\end{preview}. By the way, your GitHub is very interesting! – kiss my armpit Mar 25 '13 at 22:58
5

Here is an example of using tikzmark:

enter image description here

Note:

  • This does require two runs. First one to determine the locations, and the second to do the drawing.

  • The \tikzmark is from Adding a large brace next to a body of text.

  • Also, I don't know how those coordinates were determined so I just piggy backed onto the existing nodes so added the tikzmark to 13 and 11 and used shorten >= -4.5ex to stretch into the node above it.

  • The drawing quality of the picture mode \oval does not seem very good, but perhaps there is someone on this site who can address that issue.

Code:

\documentclass[border=2pt]{standalone}

\usepackage[dvipsnames]{xcolor}
\input{kvmacros}

\usepackage{tikz}
\usetikzlibrary{calc}%
\newcommand{\tikzmark}[1]{%
    \tikz[overlay, remember picture, baseline] \node (#1) {};%
}

\newcommand{\DrawArrow}[3][]{%
    \begin{tikzpicture}[overlay,remember picture]
        \draw[
                ->, thick,% distance=\ArcDistance,
                %shorten <=\ShortenBegin, shorten >=\ShortenEnd,
                %out=\OutAngle, in=\InAngle, Arrow Style, #2
                #1
            ] 
                ($(#2)+(-0.50em,3.5ex)$) to 
                ($(#3)+(1.5em,0.0ex)$);
    \end{tikzpicture}% <-- important
}

\begin{document}
    \karnaughmap{4}{$f(w,x,y,z)$}{{$w$}{$x$}{$y$}{$z$}}%
    {
        1100
        1100
        0011
        0101
    }
    {
        \textcolor{Blue}{
            \put(2,3.5){\oval(3.9,0.9)[]}
        }
        \textcolor{WildStrawberry}{
            \put(0.9,3.5){\oval(1.7,0.8)[]}
        }
        \textcolor{Green}{
            \put(0.7,1.5){\tikzmark{11}\oval(1.9,0.9)}
        }
        \textcolor{Sepia}{
            \put(1.5,1.5){\oval(1.6,0.7)}
        }
        \textcolor{Red}{
            \put(1.92,1){\oval(0.9,1.9)}
        }
        \textcolor{LimeGreen}{
            \put(1.76,-0.2){\tikzmark{13}\oval(0.9,2.1)[t]}
            \put(1.76,4.2){\oval(0.9,2.1)[b]}
        }
    }
\DrawArrow[red, ultra thick, out=-180, in=-90, distance=1.5em, shorten >= -4.5ex]{13}{11}
\end{document}
2
  • Hi Peter, I think I know how to get better results. You can use convert. See my Makefile. This Makefile produces this image. I take deeper a look (and quite likely accept) at your answer tomorrow. Have to sleep now. – Martin Thoma Mar 25 '13 at 22:40
  • 1
    Ok, but the quality of the drawing capability of kvmacros seems very poor. You should consider doing the entire drawing in tikz. – Peter Grill Mar 25 '13 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.