Hello,
I'd like to achieve the attached image in LaTeX.
How could I make a rectangle around a bunch of cells in LaTeX?
Thanks
Graphics, Figures & Tables ⇒ Rectangles around Table Cells
Rectangles around Table Cells
- Attachments
-
- Screen shot 2011-05-25 at 5.17.47 PM.png (21.02 KiB) Viewed 14520 times
Rectangles around Table Cells
Do you know the karnaugh package on CTAN?
I used it long time ago. More recently, but still some years ago I made some Karnaugh maps with TikZ. If you are interested I can send you some example.
Ignasi
I used it long time ago. More recently, but still some years ago I made some Karnaugh maps with TikZ. If you are interested I can send you some example.
Ignasi
Re: Rectangles around Table Cells
Yes but it doesnt arrange the K maps as I want them to do (ie. not in the correct standard cell order).
Therefore I would like to do it myself..
Therefore I would like to do it myself..
Rectangles around Table Cells
I've found my tikz code for Karnaugh maps. Command names are in catalan, but I've added some comments in English. I hope you could understand them. You only need tikz. Next you'll find the code with two examples using it.
Best regards,
Ignasi
Best regards,
Ignasi
Code: Select all
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,calc}
%internal group
%#1-space between node and grouping line. Default=0
%#2-top left node
%#3-bottom right node
\newcommand{\implicant}[3][0]{
\draw[rounded corners=3pt] ($(#2.north west)+(135:#1)$) rectangle ($(#3.south east)+(-45:#1)$);
}
%group lateral borders
%#1-space between node and grouping line. Default=0
%#2-top left node
%#3-bottom right node
\newcommand{\implicantcostats}[3][0]{
\draw[rounded corners=3pt] ($(rf.east |- #2.north)+(90:#1)$)-| ($(#2.east)+(0:#1)$) |- ($(rf.east |- #3.south)+(-90:#1)$);
\draw[rounded corners=3pt] ($(cf.west |- #2.north)+(90:#1)$) -| ($(#3.west)+(180:#1)$) |- ($(cf.west |- #3.south)+(-90:#1)$);
}
%group top-bottom borders
%#1-space between node and grouping line. Default=0
%#2-top left node
%#3-bottom right node
\newcommand{\implicantdaltbaix}[3][0]{
\draw[rounded corners=3pt] ($(cf.south -| #2.west)+(180:#1)$) |- ($(#2.south)+(-90:#1)$) -| ($(cf.south -| #3.east)+(0:#1)$);
\draw[rounded corners=3pt] ($(rf.north -| #2.west)+(180:#1)$) |- ($(#3.north)+(90:#1)$) -| ($(rf.north -| #3.east)+(0:#1)$);
}
%group corners
%#1-space between node and grouping line. Default=0
\newcommand{\implicantcantons}[1][0]{
\draw[rounded corners=3pt] ($(rf.east |- 0.south)+(-90:#1)$) -| ($(0.east |- cf.south)+(0:#1)$);
\draw[rounded corners=3pt] ($(rf.east |- 8.north)+(90:#1)$) -| ($(8.east |- rf.north)+(0:#1)$);
\draw[rounded corners=3pt] ($(cf.west |- 2.south)+(-90:#1)$) -| ($(2.west |- cf.south)+(180:#1)$);
\draw[rounded corners=3pt] ($(cf.west |- 10.north)+(90:#1)$) -| ($(10.west |- rf.north)+(180:#1)$);
}
%Empty Karnaugh map 4x4
\newenvironment{Karnaugh}%
{
\begin{tikzpicture}[baseline=(current bounding box.north),scale=0.8]
\draw (0,0) grid (4,4);
\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);
%
\matrix (mapa) [matrix of nodes,
column sep={0.8cm,between origins},
row sep={0.8cm,between origins},
every node/.style={minimum size=0.3mm},
anchor=8.center,
ampersand replacement=\&] at (0.5,0.5)
{
\& |(c00)| 00 \& |(c01)| 01 \& |(c11)| 11 \& |(c10)| 10 \& |(cf)| \phantom{00} \\
|(r00)| 00 \& |(0)| \phantom{0} \& |(1)| \phantom{0} \& |(3)| \phantom{0} \& |(2)| \phantom{0} \& \\
|(r01)| 01 \& |(4)| \phantom{0} \& |(5)| \phantom{0} \& |(7)| \phantom{0} \& |(6)| \phantom{0} \& \\
|(r11)| 11 \& |(12)| \phantom{0} \& |(13)| \phantom{0} \& |(15)| \phantom{0} \& |(14)| \phantom{0} \& \\
|(r10)| 10 \& |(8)| \phantom{0} \& |(9)| \phantom{0} \& |(11)| \phantom{0} \& |(10)| \phantom{0} \& \\
|(rf) | \phantom{00} \& \& \& \& \& \\
};
}%
{
\end{tikzpicture}
}
%Empty Karnaugh map 2x4
\newenvironment{Karnaughvuit}%
{
\begin{tikzpicture}[baseline=(current bounding box.north),scale=0.8]
\draw (0,0) grid (4,2);
\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);
%
\matrix (mapa) [matrix of nodes,
column sep={0.8cm,between origins},
row sep={0.8cm,between origins},
every node/.style={minimum size=0.3mm},
anchor=4.center,
ampersand replacement=\&] at (0.5,0.5)
{
\& |(c00)| 00 \& |(c01)| 01 \& |(c11)| 11 \& |(c10)| 10 \& |(cf)| \phantom{00} \\
|(r00)| 0 \& |(0)| \phantom{0} \& |(1)| \phantom{0} \& |(3)| \phantom{0} \& |(2)| \phantom{0} \& \\
|(r01)| 1 \& |(4)| \phantom{0} \& |(5)| \phantom{0} \& |(7)| \phantom{0} \& |(6)| \phantom{0} \& \\
|(rf) | \phantom{00} \& \& \& \& \& \\
};
}%
{
\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};
}
%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}
\contingut{0,0,0,0,0,1,0,1,1,1,0,0,0,1,0,1}
\implicant{0}{2}
\implicantdaltbaix[3pt]{3}{10}
\implicantcostats{4}{14}
\end{Karnaugh}
\begin{Karnaugh}
\minterms{4,10,11,13}
\maxterms{1,3,6,7,8,9,12,14}
\indeterminats{0,2,5,15}
\implicant{4}{5}
\implicant{11}{10}
\implicant{13}{15}
\implicantcostats{0}{2}
\implicant[3pt]{0}{4}
\implicant[3pt]{5}{13}
\implicant[3pt]{15}{11}
\implicantdaltbaix[3pt]{2}{10}
\end{Karnaugh}
\end{document}
Re: Rectangles around Table Cells
Hello,
I am having the same issue. Did you find the right code?
Were you able to draw the kmap in your picture?
Thank you
OOzy
I am having the same issue. Did you find the right code?
Were you able to draw the kmap in your picture?
Thank you
OOzy
Re: Rectangles around Table Cells
Have you tested the code I posted in my previous answer?
Ignasi
Ignasi
Rectangles around Table Cells
Hello,
Yes, I did but it does not produce the image shown above with:
I hope you get it.
Thank you
Yes, I did but it does not produce the image shown above with:
Code: Select all
A
________
| |
Thank you
Rectangles around Table Cells
I think that the line which marks negate or not negate variables is not necessary if you uses 0 and 1 to label rows and columns, but, in any case, I've made some changes to the code and something similar to wanted lines and labels are shown now.
I hope you could adapt the code to your needs.
I hope you could adapt the code to your needs.
Code: Select all
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,calc}
%internal group
%#1-space between node and grouping line. Default=0
%#2-top left node
%#3-bottom right node
\newcommand{\implicant}[3][0]{
\draw[rounded corners=3pt] ($(#2.north west)+(135:#1)$) rectangle ($(#3.south east)+(-45:#1)$);
}
%group lateral borders
%#1-space between node and grouping line. Default=0
%#2-top left node
%#3-bottom right node
\newcommand{\implicantcostats}[3][0]{
\draw[rounded corners=3pt] ($(rf.east |- #2.north)+(90:#1)$)-| ($(#2.east)+(0:#1)$) |- ($(rf.east |- #3.south)+(-90:#1)$);
\draw[rounded corners=3pt] ($(cf.west |- #2.north)+(90:#1)$) -| ($(#3.west)+(180:#1)$) |- ($(cf.west |- #3.south)+(-90:#1)$);
}
%group top-bottom borders
%#1-space between node and grouping line. Default=0
%#2-top left node
%#3-bottom right node
\newcommand{\implicantdaltbaix}[3][0]{
\draw[rounded corners=3pt] ($(cf.south -| #2.west)+(180:#1)$) |- ($(#2.south)+(-90:#1)$) -| ($(cf.south -| #3.east)+(0:#1)$);
\draw[rounded corners=3pt] ($(rf.north -| #2.west)+(180:#1)$) |- ($(#3.north)+(90:#1)$) -| ($(rf.north -| #3.east)+(0:#1)$);
}
%group corners
%#1-space between node and grouping line. Default=0
\newcommand{\implicantcantons}[1][0]{
\draw[rounded corners=3pt] ($(rf.east |- 0.south)+(-90:#1)$) -| ($(0.east |- cf.south)+(0:#1)$);
\draw[rounded corners=3pt] ($(rf.east |- 8.north)+(90:#1)$) -| ($(8.east |- rf.north)+(0:#1)$);
\draw[rounded corners=3pt] ($(cf.west |- 2.south)+(-90:#1)$) -| ($(2.west |- cf.south)+(180:#1)$);
\draw[rounded corners=3pt] ($(cf.west |- 10.north)+(90:#1)$) -| ($(10.west |- rf.north)+(180:#1)$);
}
%Empty Karnaugh map 4x4
\newenvironment{Karnaugh}%
{
\begin{tikzpicture}[baseline=(current bounding box.north),scale=0.8]
\draw (0,0) grid (4,4);
\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);
%
\matrix (mapa) [matrix of nodes,
column sep={0.8cm,between origins},
row sep={0.8cm,between origins},
every node/.style={minimum size=0.3mm},
anchor=8.center,
ampersand replacement=\&] at (0.5,0.5)
{
\& |(c00)| 00 \& |(c01)| 01 \& |(c11)| 11 \& |(c10)| 10 \& |(cf)| \phantom{00} \\
|(r00)| 00 \& |(0)| \phantom{0} \& |(1)| \phantom{0} \& |(3)| \phantom{0} \& |(2)| \phantom{0} \& \\
|(r01)| 01 \& |(4)| \phantom{0} \& |(5)| \phantom{0} \& |(7)| \phantom{0} \& |(6)| \phantom{0} \& \\
|(r11)| 11 \& |(12)| \phantom{0} \& |(13)| \phantom{0} \& |(15)| \phantom{0} \& |(14)| \phantom{0} \& \\
|(r10)| 10 \& |(8)| \phantom{0} \& |(9)| \phantom{0} \& |(11)| \phantom{0} \& |(10)| \phantom{0} \& \\
|(rf) | \phantom{00} \& \& \& \& \& \\
};
\draw ([yshift=1mm]c01.north west)--([yshift=1mm]c11.north east) node[midway,above]{d};
\draw ([yshift=-4mm]11.south west)--([yshift=-4mm]10.south east) node[midway,below]{c};
\draw ([xshift=-2mm]r01.north west)--([xshift=-2mm]r11.south west) node[midway,left]{b};
\draw ([xshift=4mm]14.north east)--([xshift=4mm]10.south east) node[midway,right]{a};
}%
{
\end{tikzpicture}
}
%Empty Karnaugh map 2x4
\newenvironment{Karnaughvuit}%
{
\begin{tikzpicture}[baseline=(current bounding box.north),scale=0.8]
\draw (0,0) grid (4,2);
\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);
%
\matrix (mapa) [matrix of nodes,
column sep={0.8cm,between origins},
row sep={0.8cm,between origins},
every node/.style={minimum size=0.3mm},
anchor=4.center,
ampersand replacement=\&] at (0.5,0.5)
{
\& |(c00)| 00 \& |(c01)| 01 \& |(c11)| 11 \& |(c10)| 10 \& |(cf)| \phantom{00} \\
|(r00)| 0 \& |(0)| \phantom{0} \& |(1)| \phantom{0} \& |(3)| \phantom{0} \& |(2)| \phantom{0} \& \\
|(r01)| 1 \& |(4)| \phantom{0} \& |(5)| \phantom{0} \& |(7)| \phantom{0} \& |(6)| \phantom{0} \& \\
|(rf) | \phantom{00} \& \& \& \& \& \\
};
\draw ([yshift=2mm]c01.north west)--([yshift=2mm]c11.north east) node[midway,above]{c};
\draw ([yshift=-4mm]7.south west)--([yshift=-4mm]6.south east) node[midway,below]{b};
\draw ([xshift=-2mm]r01.north west)--([xshift=-2mm]r01.south west) node[midway,left]{a};
}%
{
\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};
}
%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{Karnaughvuit}
\contingut{0,0,0,0,0,1,0,1}
\end{Karnaughvuit}
\begin{Karnaugh}
\contingut{0,0,0,0,0,1,0,1,1,1,0,0,0,1,0,1}
\implicant{0}{2}
\implicantdaltbaix[3pt]{3}{10}
\implicantcostats{4}{14}
\end{Karnaugh}
\begin{Karnaugh}
\minterms{4,10,11,13}
\maxterms{1,3,6,7,8,9,12,14}
\indeterminats{0,2,5,15}
\implicant{4}{5}
\implicant{11}{10}
\implicant{13}{15}
\implicantcostats{0}{2}
\implicant[3pt]{0}{4}
\implicant[3pt]{5}{13}
\implicant[3pt]{15}{11}
\implicantdaltbaix[3pt]{2}{10}
\end{Karnaugh}
\end{document}
Re: Rectangles around Table Cells
I improved a little the code that I copied here (now you can draw maps up to 3x3 variables) and put it inside this .sty file, to use like a package. Feel free to use it.
- Attachments
-
- karnaughmapalternative.sty
- For free use.
- (11.78 KiB) Downloaded 506 times