1

I am trying to create a Karnaugh Map, but I need to have variables as the terms for the K-map. I am using the karnaugh-map package, where I can get the variable terms inside the K-map, but the K-map is too small. I need to resize it so that each term fits within its box.

Small K-Map

I found this document: https://ctan.mines-albi.fr/graphics/pgf/contrib/karnaugh-map/karnaugh-map.pdf, that says I can resize the K-map with the following code:

\resizebox{\columnwidth}{!}{%
\begin{karnaugh-map}
\end{karnaugh-map}%
}

I tried using that method to resize my K-map, but when I compile I get an error.

\documentclass[tikz, border=2mm]{standalone}
\usepackage{karnaugh-map}
\usepackage{graphicx}
\begin{document}
    \resizebox{\columnwidth}{!}
    {
        \begin{karnaugh-map}[2][2][1]
            \manualterms{$A_0'B_0'+A_0B_0$,0,0,$A_0'B_0'+A_0B_0$}
        \end{karnaugh-map}
    }
\end{document}
❯ tectonic test.tex
Running TeX ...
warning: accessing absolute path `/dev/null`; build may not be reproducible in other environments
error: test.tex:6: Missing number, treated as zero
error: halted on potentially-recoverable error as specified
Matt
  • 13
  • 2

1 Answers1

1

As the manual states, you can't change the relevant dimensions. So one alternative is using plain Tikz. Here's one way to do it: there are many more with Tikz.

For reference have a look into the pgfmanual. Most of the statements used here you'll find already in the tutorials of Part 1.

result

Some hints:

  • nodes with style kd form the matrix
  • their square shape is set via minimum size
  • here I position them with absolute coordinates

Values 0,1 :

  • the xv and yv styles make sure, the relevant nodes fit bottom-top (south-north) and left-right (east-west)
  • it's a kind of shortcut to position them

Labels X1, X2:

  • similar approach, using upper right corner of node (A)
  • and lower left corner of node (A)
  • together with some absolute shift in y-/x-direction, respectively
\documentclass[10pt,border=3mm,tikz]{standalone}

\begin{document}

\begin{tikzpicture}[ kd/.style={draw, minimum size=2.5cm}, xv/.style={anchor=south,minimum height=1cm}, yv/.style={anchor=east,minimum width=1cm}, xl/.style={anchor=south,yshift=9mm}, yl/.style={anchor=east,xshift=-9mm}, ] % ~~~ matrix ~~~~~~~~~~~~~~~~~~~~~~~~ \node[kd] (A) at (0,0) {$A_0'B_0'+A_0B_0$}; \node[kd] at (2.5,-2.5) {$A_0'B_0'+A_0B_0$}; \node[kd] (B) at (2.5,0) {$0$}; \node[kd] (C) at (0,-2.5) {$0$}; % ~~~ values ~~~~~~~~~~~~~ \node[xv] at (A.north) {$0$}; \node[xv] at (B.north) {$1$}; \node[yv] at (A.west) {$0$}; \node[yv] at (C.west) {$1$}; % ~~~ labels ~~~~~~~~~ \node[xl] at (A.north east) {$X_0$}; \node[yl] at (A.south west) {$X_1$}; \end{tikzpicture}

\end{document}

Some alternatives with Tikz:

  • using matrix placement
  • using tikzlibrary postioning
  • using foreach-loops
  • ...

Some alternatives without Tikz:

  • using tables of any kind
MS-SPO
  • 11,519