1

I have this K-Map written with the KvMap package, but I don't know how to center it properly:

\documentclass[a4paper,12pt]{article}
\usepackage[a4paper, margin=2cm]{geometry}
\usepackage[utf8]{inputenc}

\usepackage{kvmap}
\usetikzlibrary{backgrounds}

\begin{document}
    \begin{center}
        \begin{kvmap}
          \kvlist{8}{4}{\phantom{0},\phantom{0},\phantom{0},\phantom{0},\phantom{0},\phantom{0},\phantom{0},\phantom{0},\phantom{0},\phantom{0},\phantom{0},\phantom{0},\phantom{0},\phantom{0},\phantom{0},\phantom{0},X,X,X,X,X,X,X,X,\phantom{0},1,1,\phantom{0},X,X,X,\phantom{0}}{Q_2, Q_1, Q_0 ,Q_4 ,  Q_3 }
          \foreach \tikzn/\tikzi in {00/0, 10/1, 20/3, 30/2, 40/6, 50/7, 60/5, 70/4,
            01/8, 11/9, 21/11, 31/10, 41/14, 51/15, 61/13, 71/12,
            02/24, 12/25, 22/27, 32/26, 42/30, 52/31, 62/29, 72/28,
            03/16, 13/17, 23/19, 33/18, 43/22, 53/23, 63/21, 73/20
          } 
          {\node[font=\footnotesize,anchor=north east, inner sep=0.25pt] at (\tikzn.north east) {$\tikzi$};}
          \begin{scope}[on background layer]
            \fill[gray!30] (1,-2) rectangle (3,-4);
            \fill[gray!30] (5,-2) rectangle (7,-4);
          \end{scope}
        \end{kvmap}
    \end{center}
\end{document}

I would like to have the same space from the left and right side of the Kmap.

1
  • 1
    For me, the image is centered. Maybe it gets visible by adding the showframe option to geometry and by placing the kvmap in an \fbox. The table-like part might seem to be shifted to the right due to the numbers and the "Q3Q4" on the left. – leandriis Jan 3 '20 at 12:49
1

The kvmap is centered. However, you're right into thinking that it doesn't appear centered, because the eye is led by the vertical rules.

You can tell TeX to back up the width of the label Q4Q3 by inserting a negative space.

\documentclass[a4paper,12pt]{article}
\usepackage[a4paper, margin=2cm]{geometry}
\usepackage[utf8]{inputenc}

\usepackage{calc}
\usepackage{kvmap}
\usetikzlibrary{backgrounds}

\usepackage{showframe} % just to show the margins, remove it

\begin{document}

\begin{center}

\settowidth{\dimen0}{$Q_4Q_3$}\hspace*{-\dimen0}%
\begin{kvmap}
  \kvlist{8}{4}{\phantom{0},\phantom{0},\phantom{0},\phantom{0},
                \phantom{0},\phantom{0},\phantom{0},\phantom{0},
                \phantom{0},\phantom{0},\phantom{0},\phantom{0},
                \phantom{0},\phantom{0},\phantom{0},\phantom{0},
                X,X,X,X,X,X,X,X,\phantom{0},1,1,\phantom{0},X,X,X,
                \phantom{0}}
               {Q_2, Q_1, Q_0, Q_4, Q_3}
  \foreach \tikzn/\tikzi in {
    00/0, 10/1, 20/3, 30/2, 40/6, 50/7, 60/5, 70/4,
    01/8, 11/9, 21/11, 31/10, 41/14, 51/15, 61/13, 71/12,
    02/24, 12/25, 22/27, 32/26, 42/30, 52/31, 62/29, 72/28,
    03/16, 13/17, 23/19, 33/18, 43/22, 53/23, 63/21, 73/20
  } 
  {
   \node[font=\footnotesize,anchor=north east, inner sep=0.25pt] at (\tikzn.north east) {$\tikzi$};
  }
  \begin{scope}[on background layer]
    \fill[gray!30] (1,-2) rectangle (3,-4);
    \fill[gray!30] (5,-2) rectangle (7,-4);
  \end{scope}
\end{kvmap}

\end{center}
\end{document}

enter image description here

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.