4

Hello my Problem is I've no idea. How I draw this Kv-Diagram in Latex I only found different KV-Diagrams they make with the Karnaugh maps. I only can do this table with Latex. I've no idea how to add the red lines/annotation.

my KV Diagramm

\documentclass{standalone}  
\begin{document} 
\begin{tabular}{c |c |c|c |c |c} 
 $y_0$ & \multicolumn{2}{c|}{$x_0$} &\multicolumn{3}{c}{$\overline{x_0}$}\\ \cline{1-5}
 $x_1$    &1&0&0&1&$\overline{x_3}$\\\cline{2-6}
       &0&1&1&0&$x_3$\\\cline{1-5}
 $\overline{x_1}$   &0&1&1&0&\\\cline{2-6}
       &1&0&0&1&$\overline{x_3}$\\\cline{2-5}
       &$\overline{x_2}$&\multicolumn{2}{c|}{$x_2$}&$\overline{x_2}$\\
\end{tabular}
\end{document}
Bernard
  • 271,350
test
  • 43
  • 2
    Welcome to TeX.se and thanks for including a minimal example document with your question. Is the question how to add the red annotation to the table? – Alan Munn Apr 14 '18 at 17:19
  • Yes I've no idea how add the red annotation – test Apr 14 '18 at 17:23
  • 1
    There are several packages which are dedicated to Karnaugh maps. karnaugh-map (with a hyphen) has examples close to what you're asking for. – Bernard Apr 14 '18 at 18:14
  • see the second @Ignasi answer on question https://tex.stackexchange.com/questions/140567/drawing-karnaughs-maps-in-latex?. your question is actually duplicate to it. – Zarko Apr 14 '18 at 18:17

2 Answers2

6

This is a completely different approach taken from my answer at How to draw a 8x8 Karnaugh map in LaTeX?. It does also show some different outcome, but as a personal preference I find it more comfortable (at least the drawing part in the document).

karnaugh map

\documentclass{article}
\usepackage{kvmap}

\begin{document}
    \begin{kvmap}
    \begin{kvmatrix}{x_0,x_2,x_1,x_3}
        1 & 0 & 0 & 1\\
        0 & 1 & 1 & 0\\
        0 & 1 & 1 & 0\\
        1 & 0 & 0 & 1
    \end{kvmatrix}
    \bundle[color=red]{1}{1}{2}{2}
    \draw[kvbundle,red] (00.south west) -| (00.north east);
    \draw[kvbundle,red] (33.south west) |- (33.north east);
    \draw[kvbundle,red] (30.south east) -| (30.north west);
    \draw[kvbundle,red] (03.south east) |- (03.north west);
    \end{kvmap}
\end{document}

Update 2018-09-21: This answer now uses the kvmap package. You may find the old code in the edit history of this answer.

TeXnician
  • 33,589
  • No, that's look good. My Problem is I do this KV-diagramm for the uni and the task is to do it with the KV-diagramm in my question because of that I don't want use a different diagramm. – test Apr 14 '18 at 19:07
3

A simple version to overlay your map is to use tikzmark (although your Karnaugh map does not really look nice). For ease of use I made all columns with bits equally wide (you may want to add some height with \extrarowheight or stretch the table using \arraystretch).

karnaugh map

\documentclass{article}
\usepackage{array}
\usepackage{tikz}
\usetikzlibrary{tikzmark}  
\begin{document} 
\begin{tabular}{c|wc{1em}|wc{1em}|wc{1em}|wc{1em}|c} 
 $y_0$ & \multicolumn{2}{c|}{$x_0$} &\multicolumn{2}{c}{$\overline{x_0}$}\\ \cline{1-5}
 $x_1$    &1\tikzmark{c1}&0&0&\tikzmark{c2}1&$\overline{x_3}$\\\cline{2-6}
       &0&\tikzmark{ul}1&1&0&$x_3$\\\cline{1-5}
 $\overline{x_1}$   &0&1&1\tikzmark{br}&0&\\\cline{2-6}
       &1\tikzmark{c3}&0&0&\tikzmark{c4}1&$\overline{x_3}$\\\cline{2-5}
       &$\overline{x_2}$&\multicolumn{2}{c|}{$x_2$}&$\overline{x_2}$\\
\end{tabular}
\begin{tikzpicture}[overlay,remember picture]
    \draw[red,rounded corners=5pt] ([xshift=-1.25em,yshift=-2pt]pic cs:c1) -| ++(1.75em,1.25em);
    \draw[red,rounded corners=5pt] ([xshift=-1.25em,yshift=7pt]pic cs:c3) -| ++(1.75em,-1.25em);
    \draw[red,rounded corners=5pt] ([xshift=1.25em,yshift=-2pt]pic cs:c2) -| ++(-1.75em,1.25em);
    \draw[red,rounded corners=5pt] ([xshift=1.25em,yshift=7pt]pic cs:c4) -| ++(-1.75em,-1.25em);
    \draw[red,rounded corners=5pt] ([xshift=-4pt,yshift=.7em]pic cs:ul) rectangle ([yshift=-.3em,xshift=4pt]pic cs:br);
\end{tikzpicture}
\end{document}
TeXnician
  • 33,589
  • Btw: The w array specifier needs a recent version of array. – TeXnician Apr 14 '18 at 18:23
  • Thanks, that's look very good. But after I copy the code in my document and try to compile have the Error "! Package array Error: Illegal pream-token (w): `c' used.". I've do idea what I'm doing wrong. – test Apr 14 '18 at 18:56
  • @Svenja As I've written in the comment this specifier needs a very recent version of array. You could of course use >{\centering\arraybackslash}p{1em} instead (or c and adjust the lengths). – TeXnician Apr 14 '18 at 20:47