karnaugh-map-2.tex 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. \documentclass{article}
  2. \usepackage[pdftex,active,tightpage]{preview}
  3. \setlength\PreviewBorder{2mm}
  4. \usepackage{tikz}
  5. \usetikzlibrary{matrix,calc}
  6. %internal group
  7. %#1-space between node and grouping line. Default=0
  8. %#2-top left node
  9. %#3-bottom right node
  10. \newcommand{\implicant}[3][0]{
  11. \draw[rounded corners=3pt] ($(#2.north west)+(135:#1)$) rectangle ($(#3.south east)+(-45:#1)$);
  12. }
  13. %group lateral borders
  14. %#1-space between node and grouping line. Default=0
  15. %#2-top left node
  16. %#3-bottom right node
  17. \newcommand{\implicantcostats}[3][0]{
  18. \draw[rounded corners=3pt] ($(rf.east |- #2.north)+(90:#1)$)-| ($(#2.east)+(0:#1)$) |- ($(rf.east |- #3.south)+(-90:#1)$);
  19. \draw[rounded corners=3pt] ($(cf.west |- #2.north)+(90:#1)$) -| ($(#3.west)+(180:#1)$) |- ($(cf.west |- #3.south)+(-90:#1)$);
  20. }
  21. %group top-bottom borders
  22. %#1-space between node and grouping line. Default=0
  23. %#2-top left node
  24. %#3-bottom right node
  25. \newcommand{\implicantdaltbaix}[3][0]{
  26. \draw[rounded corners=3pt] ($(cf.south -| #2.west)+(180:#1)$) |- ($(#2.south)+(-90:#1)$) -| ($(cf.south -| #3.east)+(0:#1)$);
  27. \draw[rounded corners=3pt] ($(rf.north -| #2.west)+(180:#1)$) |- ($(#3.north)+(90:#1)$) -| ($(rf.north -| #3.east)+(0:#1)$);
  28. }
  29. %group corners
  30. %#1-space between node and grouping line. Default=0
  31. \newcommand{\implicantcantons}[1][0]{
  32. \draw[rounded corners=3pt] ($(rf.east |- 0.south)+(-90:#1)$) -| ($(0.east |- cf.south)+(0:#1)$);
  33. \draw[rounded corners=3pt] ($(rf.east |- 8.north)+(90:#1)$) -| ($(8.east |- rf.north)+(0:#1)$);
  34. \draw[rounded corners=3pt] ($(cf.west |- 2.south)+(-90:#1)$) -| ($(2.west |- cf.south)+(180:#1)$);
  35. \draw[rounded corners=3pt] ($(cf.west |- 10.north)+(90:#1)$) -| ($(10.west |- rf.north)+(180:#1)$);
  36. }
  37. %Empty Karnaugh map 4x4
  38. \newenvironment{Karnaugh}%
  39. {
  40. \begin{tikzpicture}[baseline=(current bounding box.north),scale=0.8]
  41. \draw (0,0) grid (4,4);
  42. \draw (0,4) -- node [pos=0.7,above right,anchor=south west] {cd} node [pos=0.7,below left,anchor=north east] {ab} ++(135:1);
  43. %
  44. \matrix (mapa) [matrix of nodes,
  45. column sep={0.8cm,between origins},
  46. row sep={0.8cm,between origins},
  47. every node/.style={minimum size=0.3mm},
  48. anchor=8.center,
  49. ampersand replacement=\&] at (0.5,0.5)
  50. {
  51. \& |(c00)| 00 \& |(c01)| 01 \& |(c11)| 11 \& |(c10)| 10 \& |(cf)| \phantom{00} \\
  52. |(r00)| 00 \& |(0)| \phantom{0} \& |(1)| \phantom{0} \& |(3)| \phantom{0} \& |(2)| \phantom{0} \& \\
  53. |(r01)| 01 \& |(4)| \phantom{0} \& |(5)| \phantom{0} \& |(7)| \phantom{0} \& |(6)| \phantom{0} \& \\
  54. |(r11)| 11 \& |(12)| \phantom{0} \& |(13)| \phantom{0} \& |(15)| \phantom{0} \& |(14)| \phantom{0} \& \\
  55. |(r10)| 10 \& |(8)| \phantom{0} \& |(9)| \phantom{0} \& |(11)| \phantom{0} \& |(10)| \phantom{0} \& \\
  56. |(rf) | \phantom{00} \& \& \& \& \& \\
  57. };
  58. }%
  59. {
  60. \end{tikzpicture}
  61. }
  62. %Empty Karnaugh map 2x4
  63. \newenvironment{Karnaughvuit}%
  64. {
  65. \begin{tikzpicture}[baseline=(current bounding box.north),scale=0.8]
  66. \draw (0,0) grid (4,2);
  67. \draw (0,2) -- node [pos=0.7,above right,anchor=south west] {bc} node [pos=0.7,below left,anchor=north east] {a} ++(135:1);
  68. %
  69. \matrix (mapa) [matrix of nodes,
  70. column sep={0.8cm,between origins},
  71. row sep={0.8cm,between origins},
  72. every node/.style={minimum size=0.3mm},
  73. anchor=4.center,
  74. ampersand replacement=\&] at (0.5,0.5)
  75. {
  76. \& |(c00)| 00 \& |(c01)| 01 \& |(c11)| 11 \& |(c10)| 10 \& |(cf)| \phantom{00} \\
  77. |(r00)| 0 \& |(0)| \phantom{0} \& |(1)| \phantom{0} \& |(3)| \phantom{0} \& |(2)| \phantom{0} \& \\
  78. |(r01)| 1 \& |(4)| \phantom{0} \& |(5)| \phantom{0} \& |(7)| \phantom{0} \& |(6)| \phantom{0} \& \\
  79. |(rf) | \phantom{00} \& \& \& \& \& \\
  80. };
  81. }%
  82. {
  83. \end{tikzpicture}
  84. }
  85. %Defines 8 or 16 values (0,1,X)
  86. \newcommand{\contingut}[1]{%
  87. \foreach \x [count=\xi from 0] in {#1}
  88. \path (\xi) node {\x};
  89. }
  90. %Places 1 in listed positions
  91. \newcommand{\minterms}[1]{%
  92. \foreach \x in {#1}
  93. \path (\x) node {1};
  94. }
  95. %Places 0 in listed positions
  96. \newcommand{\maxterms}[1]{%
  97. \foreach \x in {#1}
  98. \path (\x) node {0};
  99. }
  100. %Places X in listed positions
  101. \newcommand{\indeterminats}[1]{%
  102. \foreach \x in {#1}
  103. \path (\x) node {X};
  104. }
  105. \begin{document}
  106. \begin{preview}
  107. \begin{Karnaugh}
  108. \contingut{0,0,0,0,0,1,0,1,1,1,0,0,0,1,0,1}
  109. \implicant{0}{2}
  110. \implicantdaltbaix[3pt]{3}{10}
  111. \implicantcostats{4}{14}
  112. \end{Karnaugh}
  113. \begin{Karnaugh}
  114. \minterms{4,10,11,13}
  115. \maxterms{1,3,6,7,8,9,12,14}
  116. \indeterminats{0,2,5,15}
  117. \implicant{4}{5}
  118. \implicant{11}{10}
  119. \implicant{13}{15}
  120. \implicantcostats{0}{2}
  121. \implicant[3pt]{0}{4}
  122. \implicant[3pt]{5}{13}
  123. \implicant[3pt]{15}{11}
  124. \implicantdaltbaix[3pt]{2}{10}
  125. \end{Karnaugh}
  126. \end{preview}
  127. \end{document}