1

I want to put the equation next to the kmap, but it seems the kmap is located higher. How can I align the text and the kmap to start at the same height?

\documentclass[12pt]{article}

\usepackage{tikz}
\usetikzlibrary{matrix,calc}

\begin{document}
\tikzset{
table nodes/.style={
   rectangle,
   draw=black,
   align=center,
   minimum height=7mm,
   text depth=0.5ex,
   text height=2ex,
   inner xsep=0pt,
   outer sep=0pt
},      
table/.style={
   matrix of nodes,
   row sep=-\pgflinewidth,
   column sep=-\pgflinewidth,
   nodes={
       table nodes
},
execute at empty cell={\node[draw=]{0};}
}
}


$a$:
\begin{tikzpicture}
   \matrix (kmap) [every node/.style={anchor=base},table,text width=10mm,name=kmap]
   {
    \node (a11){1}; & \node (a12){}; & \node (a13){1}; & \node (a14){1}; \\
    \node (a21){1}; & \node (a22){1}; & \node (a23){}; & \node (a24){1}; \\
    \node (a31){1}; & \node (a32){1}; & \node (a33){1}; & \node (a34){1};  \\
    \node (a41){}; & \node (a42){1}; & \node (a43){}; & \node (a44){1};  \\
   };
   \draw (a12.north west) -- ++(0,.3) node (lx3) {};
   \draw (a13.north east) -- ++(0,.3) node (rx3) {};
   \draw (lx3.north) to node[midway,above]{$x_0$} (rx3.north);

   \draw (a21.north west) -- ++(-0.3,0) node (lx4) {};
   \draw (a31.south west) -- ++(-0.3,0) node (rx4) {};
   \draw (lx4.west) to node[midway,left]{$x_1$} (rx4.west);

   \draw (a14.north east) -- ++(0.3,0) node (lx5) {};
   \draw (a24.south east) -- ++(0.3,0) node (rx5) {};
   \draw (lx5.east) to node[midway,right]{$x_3$} (rx5.east);

   \draw (a41.south west) -- ++(0,-.3) node (lx2) {};
   \draw (a42.south east) -- ++(0,-.3) node (rx2) {};
   \draw (lx2.south) to node[midway,below]{$x_2$} (rx2.south);
\end{tikzpicture}
\begin{tabular}{cccc}
   $a$ & $=$ && $x_3 \overline{x_0}$\\
   $$   && $+$ & $x_2 x_1$\\
   $$   && $+$ & $\overline{x_2}\; \overline{x_1}$\\
   $$   && $+$ & $x_3 \overline{x_1}$\\
   $$   && $+$ & $x_3 x_2 x_0$\\
   $$   && $+$ & $x_3 \overline{x_2}\; \overline{x_1}$\\
\end{tabular}

\end{document}

result so far

Added a second picture to clarify result I wish for

2 Answers 2

1

By default TiKZ pictures are aligned with their bottom point being aligned with baseline of surrounding text, but you can change this behaviour with baseline option. As an example, if you want to align them through center point can use:

\begin{tikzpicture}[baseline=(current bounding box.center), ...

Just changing this line in your code the result is:

enter image description here

The complete code:

\documentclass[12pt]{article}

\usepackage{tikz}
\usetikzlibrary{matrix,calc}

\begin{document}
\tikzset{
table nodes/.style={
   rectangle,
   draw=black,
   align=center,
   minimum height=7mm,
   text depth=0.5ex,
   text height=2ex,
   inner xsep=0pt,
   outer sep=0pt
},      
table/.style={
   matrix of nodes,
   row sep=-\pgflinewidth,
   column sep=-\pgflinewidth,
   nodes={
       table nodes
},
execute at empty cell={\node[draw=]{0};}
}
}


$a$:
\begin{tikzpicture}[baseline=(current bounding box.center)]
   \matrix (kmap) [every node/.style={anchor=base},table,text width=10mm,name=kmap]
   {
    \node (a11){1}; & \node (a12){}; & \node (a13){1}; & \node (a14){1}; \\
    \node (a21){1}; & \node (a22){1}; & \node (a23){}; & \node (a24){1}; \\
    \node (a31){1}; & \node (a32){1}; & \node (a33){1}; & \node (a34){1};  \\
    \node (a41){}; & \node (a42){1}; & \node (a43){}; & \node (a44){1};  \\
   };
   \draw (a12.north west) -- ++(0,.3) node (lx3) {};
   \draw (a13.north east) -- ++(0,.3) node (rx3) {};
   \draw (lx3.north) to node[midway,above]{$x_0$} (rx3.north);

   \draw (a21.north west) -- ++(-0.3,0) node (lx4) {};
   \draw (a31.south west) -- ++(-0.3,0) node (rx4) {};
   \draw (lx4.west) to node[midway,left]{$x_1$} (rx4.west);

   \draw (a14.north east) -- ++(0.3,0) node (lx5) {};
   \draw (a24.south east) -- ++(0.3,0) node (rx5) {};
   \draw (lx5.east) to node[midway,right]{$x_3$} (rx5.east);

   \draw (a41.south west) -- ++(0,-.3) node (lx2) {};
   \draw (a42.south east) -- ++(0,-.3) node (rx2) {};
   \draw (lx2.south) to node[midway,below]{$x_2$} (rx2.south);
\end{tikzpicture}
\begin{tabular}{cccc}
   $a$ & $=$ && $x_3 \overline{x_0}$\\
   $$   && $+$ & $x_2 x_1$\\
   $$   && $+$ & $\overline{x_2}\; \overline{x_1}$\\
   $$   && $+$ & $x_3 \overline{x_1}$\\
   $$   && $+$ & $x_3 x_2 x_0$\\
   $$   && $+$ & $x_3 \overline{x_2}\; \overline{x_1}$\\
\end{tabular}

\end{document}
0
0

For example (aligning in cells temporary commented, but to uncomment):

\documentclass[12pt]{article}

\usepackage{tikz}
\usetikzlibrary{matrix,calc}

\begin{document}
\tikzset{
table nodes/.style={
   rectangle,
   draw=black,
%   align=center,
   minimum height=7mm,
   text depth=0.5ex,
   text height=2ex,
   inner xsep=0pt,
   outer sep=0pt
},      
table/.style={
   matrix of nodes,
   row sep=-\pgflinewidth,
   column sep=-\pgflinewidth,
   nodes={
       table nodes
},
execute at empty cell={\node[draw=]{0};}
}
}


$a$:
\begin{tabular}{cl} % PS
\begin{tikzpicture}
   \matrix (kmap) [every node/.style={anchor=base},table,text width=10mm,name=kmap]
   {
    \node (a11){1}; & \node (a12){}; & \node (a13){1}; & \node (a14){1}; \\
    \node (a21){1}; & \node (a22){1}; & \node (a23){}; & \node (a24){1}; \\
    \node (a31){1}; & \node (a32){1}; & \node (a33){1}; & \node (a34){1};  \\
    \node (a41){}; & \node (a42){1}; & \node (a43){}; & \node (a44){1};  \\
   };
   \draw (a12.north west) -- ++(0,.3) node (lx3) {};
   \draw (a13.north east) -- ++(0,.3) node (rx3) {};
   \draw (lx3.north) to node[midway,above]{$x_0$} (rx3.north);

   \draw (a21.north west) -- ++(-0.3,0) node (lx4) {};
   \draw (a31.south west) -- ++(-0.3,0) node (rx4) {};
   \draw (lx4.west) to node[midway,left]{$x_1$} (rx4.west);

   \draw (a14.north east) -- ++(0.3,0) node (lx5) {};
   \draw (a24.south east) -- ++(0.3,0) node (rx5) {};
   \draw (lx5.east) to node[midway,right]{$x_3$} (rx5.east);

   \draw (a41.south west) -- ++(0,-.3) node (lx2) {};
   \draw (a42.south east) -- ++(0,-.3) node (rx2) {};
   \draw (lx2.south) to node[midway,below]{$x_2$} (rx2.south);
\end{tikzpicture}
& % PS
\begin{tabular}[b]{cccc}
   $a$ & $=$ && $x_3 \overline{x_0}$\\
   $$   && $+$ & $x_2 x_1$\\
   $$   && $+$ & $\overline{x_2}\; \overline{x_1}$\\
   $$   && $+$ & $x_3 \overline{x_1}$\\
   $$   && $+$ & $x_3 x_2 x_0$\\
   $$   && $+$ & $x_3 \overline{x_2}\; \overline{x_1}$\\
\end{tabular}
\end{tabular} % PS

\end{document}

enter image description here

For better aligning you may add space after he last line of your tabular e.g. by adding an optional parameter to \\.

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.