卡诺图中的 00、01... 不是 \overline{B}\overline{C}、\overline{B}C...

卡诺图中的 00、01... 不是 \overline{B}\overline{C}、\overline{B}C...

MWE 如下:

\documentclass[12pt,a4paper]{letter}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{karnaugh-map}

\begin{document}
\begin{karnaugh-map}[4][2][1][$BC$][$A$]
        \minterms{1,2,4,7}
        \maxterms{0,3,5,6}
        \implicant{1}{1}
        \implicant{2}{2}
        \implicant {4}{4}
        \implicant{7}{7}
    \end{karnaugh-map}
\end{document}

输出为:

我不想A在列边(带有01),而是想要\overline{A}A分别代替01。同样,在行侧我也不想用BC( 00011110)。而是用00我想要\overline{B}\overline{C},而不是01我想要\overline{B}C,而不是11我想要BC,而不是10我想要B\overline{C}

答案1

嗯,这是可能的,但遗憾的是只能通过一种相当 hack 的方式。原因是零和一是硬编码在karnaugh-map包的代码中的,因此不容易编辑。

有效的方法是首先抓取相关单元格的硬编码节点内容并将其丢弃到从未使用的框中,然后将替换文本添加到节点内容中。需要对文本高度进行小幅修正。请注意,由于全局,这些设置也适用于后续的其他矩阵。如果您不想要这样,请考虑使用和或类似的东西\tikzset来限定所有内容的范围。\bgroup\egroup

\documentclass[border=10pt]{standalone}
\usepackage{karnaugh-map}

\newsavebox{\gobblebox}

\begin{document}
\tikzset{
    text height=0.66em,
    row 1 column 2/.style={
        nodes={
            execute at begin node=$\overline{B}\overline{C}$\begin{lrbox}{\gobblebox},
            execute at end node=\end{lrbox},
        }
    },
    row 1 column 3/.style={
        nodes={
            execute at begin node=$\overline{B}C$\begin{lrbox}{\gobblebox},
            execute at end node=\end{lrbox},
        }
    },
    row 1 column 4/.style={
        nodes={
            execute at begin node=$BC$\begin{lrbox}{\gobblebox},
            execute at end node=\end{lrbox},
        }
    },
    row 1 column 5/.style={
        nodes={
            execute at begin node=$B\overline{C}$\begin{lrbox}{\gobblebox},
            execute at end node=\end{lrbox},
        }
    },
    row 2 column 1/.style={
        nodes={
            execute at begin node=$\overline{A}$\begin{lrbox}{\gobblebox},
            execute at end node=\end{lrbox},
        }
    },
    row 3 column 1/.style={
        nodes={
            execute at begin node=$A$\begin{lrbox}{\gobblebox},
            execute at end node=\end{lrbox},
        }
    },
}
\begin{karnaugh-map}[4][2][1][][]
    \minterms{1,2,4,7}
    \maxterms{0,3,5,6}
    \implicant{1}{1}
    \implicant{2}{2}
    \implicant{4}{4}
    \implicant{7}{7}
\end{karnaugh-map}
\end{document}

在此处输入图片描述

答案2

看起来karnaugh-map确实没有提供修改此行为的简单方法。我猜你可以使用\patchcmdfrom etoolbox,但相关命令很繁琐。你可以复制karnaugh-map.sty到本地目录并在那里修改源。

将以下文本保存为patch_file

--- a/karnaugh-map.sty  2023-07-20 07:48:03.000000000 -0400
+++ b/karnaugh-map.sty  2023-08-07 08:40:40.505867916 -0400
@@ -253,8 +253,8 @@
         \IfValueT{#1}{\renewcommand{\@karnaughmap@var@labelA@}{#1}}%
         \IfValueT{#2}{\renewcommand{\@karnaughmap@var@labelB@}{#2}}%
         \IfValueT{#3}{\renewcommand{\@karnaughmap@var@labelC@}{#3}}%
-        \renewcommand{\@karnaughmap@var@labelX@}{\@karnaughmap@var@labelB@\@karnaughmap@var@labelA@}%
-        \renewcommand{\@karnaughmap@var@labelY@}{\@karnaughmap@var@labelC@}%
+        \renewcommand{\@karnaughmap@var@labelX@}{}%
+        \renewcommand{\@karnaughmap@var@labelY@}{}%
         \renewcommand{\@karnaughmap@var@labeltype@}{2}%
       \fi
     \fi
@@ -353,10 +353,14 @@
     \fi
     \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=421
       \renewcommand{\@karnaughmap@local@matrixtemplate@}{%
-                     \&                      00 \&                      01 \&                      11 \&                      10 \& \phantom{00} \\
-                  0  \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \& |(000011)|  \phantom{0} \& |(000010)|  \phantom{0} \&              \\
-                  1  \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \& |(000111)|  \phantom{0} \& |(000110)|  \phantom{0} \&              \\
-        \phantom{00} \&                         \&                         \&                         \&                         \&              \\
+        \& $\overline{\mbox{\@karnaughmap@var@labelB@}}\overline{\mbox{\@karnaughmap@var@labelC@}}$%
+        \& $\overline{\mbox{\@karnaughmap@var@labelB@}}$\@karnaughmap@var@labelC@%
+        \& \@karnaughmap@var@labelB@$\overline{\mbox{\@karnaughmap@var@labelC@}}$%
+        \& \@karnaughmap@var@labelB@\@karnaughmap@var@labelC@%
+        \& \phantom{00} \\
+        $\overline{\mbox{\@karnaughmap@var@labelA@}}$  \& |(000000)|  \phantom{0} \& |(000001)|  \phantom{0} \& |(000011)|  \phantom{0} \& |(000010)|  \phantom{0} \&              \\
+        \@karnaughmap@var@labelA@                      \& |(000100)|  \phantom{0} \& |(000101)|  \phantom{0} \& |(000111)|  \phantom{0} \& |(000110)|  \phantom{0} \&              \\
+                                          \phantom{00} \&                         \&                         \&                         \&                         \&              \\
       }%
     \fi
     \ifnum\@karnaughmap@var@mapsizex@\@karnaughmap@var@mapsizey@\@karnaughmap@var@mapsizez@=441

然后做:

cp $(kpsewhich karnaugh-map.sty) . && patch -p1 < patch_file
\documentclass{standalone}
\usepackage{karnaugh-map}

\begin{document}
\begin{karnaugh-map}[4][2][1]
  \minterms{1,2,4,7}
  \maxterms{0,3,5,6}
  \implicant{1}{1}
  \implicant{2}{2}
  \implicant{4}{4}
  \implicant{7}{7}
\end{karnaugh-map}
\begin{karnaugh-map}[4][2][1][$A$][$B$][$C$]
  \minterms{1,2,4,7}
  \maxterms{0,3,5,6}
  \implicant{1}{1}
  \implicant{2}{2}
  \implicant{4}{4}
  \implicant{7}{7}
\end{karnaugh-map}
\end{document}

您必须修改其他 2x2 或 4x4 的“模板”,但您可以从我上面所做的操作中了解。

在此处输入图片描述

相关内容