2

I know there are already great Karnaugh-Questions out there but mine is specifically about reordering the Negations of a karnaughmap-Map.

I'm currently using the karnaughmap-Package by Michael Vonbun but I am not bound to this package. The package is quite easy to use and I was already able to sort of reproduce what i was looking to:

image of hand drawn KV Diagram image of TikZ KV Diagram

This is my LaTeX code:

\documentclass{article}
\usepackage{karnaughmap}

\begin{document}

    \begin{tikzpicture}[thick]
    \karnaughmapcolorfield{4}{028a}{violet!50}

    \karnaughmap
    [omitidx,omitbinaries,
    omitnegated=false,
    variables={{x_0}{x_2}{x_1}{x_3}},
    function=y_0]
    {1010 0000 1010 0000}
    % i actually want to display 1111 0000 0000 0000
    \end{tikzpicture}

\end{document}

view result on sharelatex.com

I am misusing the variable naming and the binary to get the counter-clockwise naming. I was ok with this until i discovered, that the negation bars from x_0 and x_1 are off. This means that the truth values inside makes no sense at all.

How can I move the negation bar from the x_0 at the left to the x_0 at the right?

I have more or less no TikZ experience which is why i used a package for this.

The package documentation states on page 36 in the todo-notes that there currently is no possibility to permute the karnaugh map via direct TikZ interaction.

My goal:

manipulated image of TikZ KV Diagram

done via image manipulation, red arrow shows what changed

2

I've adapted my answer in Drawing Karnaugh's maps in LaTeX to fit your needs.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}

%Empty Karnaugh map 4x4
\newenvironment{Karnaugh}%
{
\begin{tikzpicture}[baseline=(current bounding box.north),scale=0.8]

\matrix (mapa) [matrix of nodes,
           nodes in empty cells,
         column sep=-\pgflinewidth,
         row sep=-\pgflinewidth,
         every node/.style={draw, minimum size=8mm, outer sep=0pt},
         row 1/.style={every node/.style={draw=none, minimum size=8mm, outer sep=0pt}},
         column 1/.style={every node/.style={draw=none, minimum size=8mm, outer sep=0pt}},
        ampersand replacement=\&]
{
|[draw=none]| \&[2mm] |(c01)| \& |(c11)| \& |(c10)| \& |(c00)| \\[2mm]
|(r01)| \& |(3)|  \& |(7)|  \& |(6)|  \& |(2)|  \\
|(r11)| \& |(11)| \& |(15)| \& |(14)| \& |(10)| \\
|(r10)| \& |(9)|  \& |(13)| \& |(12)| \& |(8)|  \\
|(r00)| \& |(1)|  \& |(5)|  \& |(4)|  \& |(0)|  \\
};
\draw (3.north west) -- node [pos=0.7,above right,anchor=south west, inner sep=1pt] {$x_2x_0$} node [pos=0.7,below left,anchor=north east, inner sep=1pt] {$x_3x_1$} ++(135:1);

\draw ([xshift=1mm]c01.south west)--node[above] {$x_0$} ([xshift=-1mm]c11.south east);
\draw ([xshift=1mm]c10.south west)--node[above] {$\overline{x_0}$} ([xshift=-1mm]c00.south east);
\draw ([yshift=-1mm]r01.north east)--node[left] {$x_1$} ([yshift=1mm]r11.south east);
\draw ([yshift=-1mm]r10.north east)--node[left] {$\overline{x_1}$} ([yshift=1mm]r00.south east);
\draw ([shift={(2mm,-1mm)}]2.north east)--node[right] {$\overline{x_3}$} ([shift={(2mm,1mm)}]2.south east);
\draw ([shift={(2mm,-1mm)}]10.north east)--node[right] {$x_3$} ([shift={(2mm,1mm)}]8.south east);
\draw ([shift={(2mm,-1mm)}]0.north east)--node[right] {$\overline{x_3}$} ([shift={(2mm,1mm)}]0.south east);
\draw ([shift={(1mm,-2mm)}]1.south west)--node[below] {$\overline{x_2}$} ([shift={(-1mm,-2mm)}]1.south east);
\draw ([shift={(1mm,-2mm)}]5.south west)--node[below] {$x_2$} ([shift={(-1mm,-2mm)}]4.south east);
\draw ([shift={(1mm,-2mm)}]0.south west)--node[below] {$\overline{x_2}$} ([shift={(-1mm,-2mm)}]0.south east);

}%
{
\end{tikzpicture}
}

%Defines 8 or 16 values (0,1,X)
\newcommand{\contingut}[1]{%
\foreach \x [count=\xi from 0]  in {#1}
     \path (\xi) node {\x};
}

%color fields
%#1 - comma separated list of filling terms. 
%#2 - filling color
\newcommand{\colorfields}[2]{%
\foreach \i in {#1}
   \fill[#2, opacity=.3] (\i.north west) rectangle (\i.south east);
}

%Places 1 in listed positions
\newcommand{\minterms}[1]{%
    \foreach \x in {#1}
        \path (\x) node {1};
}

%Places 0 in listed positions
\newcommand{\maxterms}[1]{%
    \foreach \x in {#1}
        \path (\x) node {0};
}

%Places X in listed positions
\newcommand{\indeterminats}[1]{%
    \foreach \x in {#1}
        \path (\x) node {X};
}

\begin{document}
\begin{Karnaugh}
\minterms{0,1,2,3}
\colorfields{0,1,2,3}{red}
\end{Karnaugh}
\end{document}

enter image description here

0

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.