在小页面环境中重叠 tikz 图片

在小页面环境中重叠 tikz 图片

请问我怎样才能将下面的第一个网格向左移动以使其不与第二个网格重叠?

\documentclass[12pt]{article}

\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{matrix}
\usetikzlibrary{positioning}
\usepackage{natbib}

\begin{document}

\begin{figure}
\begin{center}
\begin{minipage}[b]{6cm}
\flushleft
\begin{tikzpicture}
\def\myrowhead{{"A","B","C"}}
\def\mycolhead{{"A","B","C"}}
\matrix[matrix of math nodes,draw,
every odd row/.style={align=right},every evenrow/.style={align=left},
nodes={text width=1.3cm},row sep=0.1cm,column sep=0.2cm] 
          (m) {3&0&0\\3&0&0\\0&2&0\\0&2&0\\0&0&1\\0&0&1\\};
\foreach\x[count=\xi from 2,evaluate={\xx=int(2*\x);\xxi=int(\xx+1)}] in {1,2}{
  \draw ({$(m-1-\x)!0.5!(m-1-\xi)$}|-m.north) -- ({$(m-1-\x)!0.5!(m-1-\xi)$}|-m.south);
  \draw ({$(m-\xx-1)!0.5!(m-\xxi-1)$}-|m.west) -- ({$(m-\xx-1)!0.5!(m-\xxi-1)$}-|m.east);
}
\foreach\x in{0,1,2}{
  \node[text depth=0.25ex,above=2mm] at ($(m.north west)!{(2*\x+1)/6}!(m.north east)$) 
     {\pgfmathparse{\myrowhead[\x]}\pgfmathresult};
  \node[left=2mm] at ($(m.north west)!{(2*\x+1)/6}!(m.south west)$) 
     {\pgfmathparse{\mycolhead[\x]}\pgfmathresult};
}
\node[above=24pt of m.north] (firm b) {Group 1 player};
\node[left=2.5cm of m.west,align=center,anchor=center] {Group 1 player};
\end{tikzpicture}
\end{minipage}
\begin{minipage}[b]{6cm}
\begin{tikzpicture}
\def\myrowhead{{"A","B","C"}}
\def\mycolhead{{"A","B","C"}}
\matrix[matrix of math nodes,draw,
every odd row/.style={align=right},every evenrow/.style={align=left},
nodes={text width=1.3cm},row sep=0.1cm,column sep=0.2cm] 
          (m) {2&0&0\\2&0&0\\0&1&0\\0&1&0\\0&0&3\\0&0&3\\};
\foreach\x[count=\xi from 2,evaluate={\xx=int(2*\x);\xxi=int(\xx+1)}] in {1,2}{
  \draw ({$(m-1-\x)!0.5!(m-1-\xi)$}|-m.north) -- ({$(m-1-\x)!0.5!(m-1-\xi)$}|-m.south);
  \draw ({$(m-\xx-1)!0.5!(m-\xxi-1)$}-|m.west) -- ({$(m-\xx-1)!0.5!(m-\xxi-1)$}-|m.east);
}
\foreach\x in{0,1,2}{
  \node[text depth=0.25ex,above=2mm] at ($(m.north west)!{(2*\x+1)/6}!(m.north east)$) 
     {\pgfmathparse{\myrowhead[\x]}\pgfmathresult};
  \node[left=2mm] at ($(m.north west)!{(2*\x+1)/6}!(m.south west)$) 
     {\pgfmathparse{\mycolhead[\x]}\pgfmathresult};
}
\node[above=24pt of m.north] (firm b) {Group 2 player};
\node[left=2.5cm of m.west,align=center,anchor=center] {Group 2 player};
\end{tikzpicture}
\end{minipage}

\begin{tikzpicture}
\def\myrowhead{{"A","B","C"}}
\def\mycolhead{{"A","B","C"}}
\matrix[matrix of math nodes,draw,
every odd row/.style={align=right},every evenrow/.style={align=left},
nodes={text width=1.3cm},row sep=0.1cm,column sep=0.2cm] 
          (m) {2&0&0\\3&0&0\\0&1&0\\0&2&0\\0&0&3\\0&0&1\\};
\foreach\x[count=\xi from 2,evaluate={\xx=int(2*\x);\xxi=int(\xx+1)}] in {1,2}{
  \draw ({$(m-1-\x)!0.5!(m-1-\xi)$}|-m.north) -- ({$(m-1-\x)!0.5!(m-1-\xi)$}|-m.south);
  \draw ({$(m-\xx-1)!0.5!(m-\xxi-1)$}-|m.west) -- ({$(m-\xx-1)!0.5!(m-\xxi-1)$}-|m.east);
}
\foreach\x in{0,1,2}{
  \node[text depth=0.25ex,above=2mm] at ($(m.north west)!{(2*\x+1)/6}!(m.north east)$) 
     {\pgfmathparse{\myrowhead[\x]}\pgfmathresult};
  \node[left=2mm] at ($(m.north west)!{(2*\x+1)/6}!(m.south west)$) 
     {\pgfmathparse{\mycolhead[\x]}\pgfmathresult};
}
\node[above=24pt of m.north] (firm b) {Group 2 player};
\node[left=2.5cm of m.west,align=center,anchor=center] {Group 1 player};
\end{tikzpicture}

\end{center}
\label{normal}
\caption{cap here}
\end{figure}

\end{document}

答案1

您必须将宽图像放入其中minipages,因此它们会突出在它们之外,从而相互重叠。一种解决方案是旋转矩阵左侧的文本。这样我得到了以下图片:

在此处输入图片描述

我稍微修改了你的代码(试图使其更具可读性),但我对结果还不满意。代码是:

\documentclass[12pt]{article}

\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{matrix}
\usetikzlibrary{positioning}
\usepackage{natbib}

\begin{document}

\begin{figure}
\tikzset{
every odd row/.style={align=right},
every evenrow/.style={align=left},
        }
    \centering
\begin{minipage}[b]{6cm}
    \flushleft
\begin{tikzpicture}
\def\myrowhead{{"A","B","C"}}
\def\mycolhead{{"A","B","C"}}
\matrix[matrix of math nodes, draw,
nodes={text width=1.3cm},row sep=0.1cm,column sep=0.2cm]
          (m) {3&0&0\\3&0&0\\0&2&0\\0&2&0\\0&0&1\\0&0&1\\};
\foreach\x[count=\xi from 2,evaluate={\xx=int(2*\x);\xxi=int(\xx+1)}] in {1,2}{
  \draw ({$(m-1-\x)!0.5!(m-1-\xi)$}|-m.north) -- ({$(m-1-\x)!0.5!(m-1-\xi)$}|-m.south);
  \draw ({$(m-\xx-1)!0.5!(m-\xxi-1)$}-|m.west) -- ({$(m-\xx-1)!0.5!(m-\xxi-1)$}-|m.east);
}
\foreach\x in{0,1,2}{
  \node[text depth=0.25ex,above=2mm] at ($(m.north west)!{(2*\x+1)/6}!(m.north east)$)
     {\pgfmathparse{\myrowhead[\x]}\pgfmathresult};
  \node[left=2mm] at ($(m.north west)!{(2*\x+1)/6}!(m.south west)$)
     {\pgfmathparse{\mycolhead[\x]}\pgfmathresult};
}
\node[above=24pt of m.north] (firm b) {Group 1 player};
\node[left=of m.west,align=center,anchor=center,
      rotate=90] {Group 1 player};
\end{tikzpicture}
\end{minipage}\hfill
\begin{minipage}[b]{6cm}
\begin{tikzpicture}
\def\myrowhead{{"A","B","C"}}
\def\mycolhead{{"A","B","C"}}
\matrix[matrix of math nodes, draw,
        nodes={text width=1.3cm, outer sep=0pt},
        row sep=0.1cm, column sep=0.2cm]
          (m) 
{2&0&0\\2&0&0\\0&1&0\\0&1&0\\0&0&3\\0&0&3\\};
\foreach \x [count=\xi from 2,evaluate={\xx=int(2*\x);\xxi=int(\xx+1)}] in {1,2}%
{
\draw ($(m-1-\x)!0.5!(m-1-\xi)$ |-m.north)
        -- ($(m-1-\x)!0.5!(m-1-\xi)$ |-m.south);
\draw ($(m-\xx-1)!0.5!(m-\xxi-1)$ -| m.west)
        -- ($(m-\xx-1)!0.5!(m-\xxi-1)$ -| m.east);
}
\foreach\x in{0,1,2}{
  \node[text depth=0.25ex,above=2mm] 
            at ($(m.north west)!{(2*\x+1)/6}!(m.north east)$)
     {\pgfmathparse{\myrowhead[\x]}\pgfmathresult};
  \node[left=2mm] 
            at ($(m.north west)!{(2*\x+1)/6}!(m.south west)$)
     {\pgfmathparse{\mycolhead[\x]}\pgfmathresult};
}
\node[above=24pt of m.north] (firm b) {Group 2 player};
\node[left=of m.west,align=center,anchor=center,
      rotate=90] {Group 1 player};
\end{tikzpicture}
\end{minipage}

\vspace{2\baselineskip}
\begin{tikzpicture}
\def\myrowhead{{"A","B","C"}}
\def\mycolhead{{"A","B","C"}}
\matrix[matrix of math nodes,draw,
nodes={text width=1.3cm},row sep=0.1cm,column sep=0.2cm]
          (m) {2&0&0\\3&0&0\\0&1&0\\0&2&0\\0&0&3\\0&0&1\\};
\foreach\x[count=\xi from 2,evaluate={\xx=int(2*\x);\xxi=int(\xx+1)}] in {1,2}{
  \draw ({$(m-1-\x)!0.5!(m-1-\xi)$}|-m.north) -- ({$(m-1-\x)!0.5!(m-1-\xi)$}|-m.south);
  \draw ({$(m-\xx-1)!0.5!(m-\xxi-1)$}-|m.west) -- ({$(m-\xx-1)!0.5!(m-\xxi-1)$}-|m.east);
}
\foreach\x in{0,1,2}{
  \node[text depth=0.25ex,above=2mm] at ($(m.north west)!{(2*\x+1)/6}!(m.north east)$)
     {\pgfmathparse{\myrowhead[\x]}\pgfmathresult};
  \node[left=2mm] at ($(m.north west)!{(2*\x+1)/6}!(m.south west)$)
     {\pgfmathparse{\mycolhead[\x]}\pgfmathresult};
}
\node[above=24pt of m.north] (firm b) {Group 2 player};
\node[left=of m.west,align=center,anchor=center,
      rotate=90] {Group 1 player};
\end{tikzpicture}

\label{normal}
\caption{cap here}
\end{figure}

\end{document}

编辑: 我不知道背景,为什么你的 MWE 写得(在我看来)如此复杂。看看下面的 MWE 是否对你有用。在其中,我尝试将其优化为上面的图像。

\documentclass[12pt]{article}

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

\begin{document}

\begin{figure}
\tikzset{
every odd row/.style={align=right},
every evenrow/.style={align=left},
row sep=0.0cm, column sep=0.0cm
        }
    \centering
\begin{minipage}[b]{6cm}
    \flushleft
\begin{tikzpicture}
\matrix[matrix of math nodes, draw, inner sep=0pt,
        nodes={text width=1.5cm,
               inner sep=2mm, outer sep=0pt},
        ]   (m)
{3&0&0\\ 3&0&0\\ 0&2&0\\ 0&2&0\\ 0&0&1\\ 0&0&1\\};
    \foreach \i [evaluate=\i as \j using int(2*\i)] in {1,2}
{
\draw (m-1-\i.north east) -- (m-6-\i.south east);
\draw (m-\j-1.south west) -- (m-\j-3.south east);
}
% A B C
    \foreach \x [count=\i,
                 evaluate=\i as \j using int(2*\i),
                 evaluate=\i as \k using int(\j-1)] in {A,B,C}
{
\node[above=2mm of m-1-\i.north] {\x};
\node[left=2mm of $(m-\j-1.west)!0.5!(m-\k-1.west)$] {\x};
}
% players
\node[above=24pt of m.north] (firm b) {Group 1 player};
\node[left=of m.west,align=center,anchor=center,
      rotate=90] {Group 1 player};
\end{tikzpicture}
\end{minipage}\hfill
\begin{minipage}[b]{6cm}
\begin{tikzpicture}
\matrix[matrix of math nodes, draw, inner sep=0pt,
        nodes={text width=1.5cm, 
               inner sep=2mm, outer sep=0pt},
        ]   (m) 
{2&0&0\\    2&0&0\\ 0&1&0\\ 0&1&0\\ 0&0&3\\ 0&0&3\\};
    \foreach \i [evaluate=\i as \j using int(2*\i)] in {1,2}
{
\draw (m-1-\i.north east) -- (m-6-\i.south east);
\draw (m-\j-1.south west) -- (m-\j-3.south east);
}
% A B C
    \foreach \x [count=\i,
                 evaluate=\i as \j using int(2*\i),
                 evaluate=\i as \k using int(\j-1)] in {A,B,C}
{
\node[above=2mm of m-1-\i.north] {\x};
\node[left=2mm of $(m-\j-1.west)!0.5!(m-\k-1.west)$] {\x};
}
% players
\node[above=24pt of m.north] (firm b) {Group 2 player};
\node[left=of m.west,align=center,anchor=center,
      rotate=90] {Group 1 player};
\end{tikzpicture}
\end{minipage}

\vspace{2\baselineskip}
\begin{tikzpicture}
\matrix[matrix of math nodes, draw, inner sep=0pt,
        nodes={text width=1.5cm,
               inner sep=2mm, outer sep=0pt},
        ]   (m)
{2&0&0\\    3&0&0\\ 0&1&0\\ 0&2&0\\ 0&0&3\\ 0&0&1\\};
% lines
    \foreach \i [evaluate=\i as \j using int(2*\i)] in {1,2}
{
\draw (m-1-\i.north east) -- (m-6-\i.south east);
\draw (m-\j-1.south west) -- (m-\j-3.south east);
}
% A B C
    \foreach \x [count=\i,
                 evaluate=\i as \j using int(2*\i),
                 evaluate=\i as \k using int(\j-1)] in {A,B,C}
{
\node[above=2mm of m-1-\i.north] {\x};
\node[left=2mm of $(m-\j-1.west)!0.5!(m-\k-1.west)$] {\x};
}
% players
\node[above=24pt of m.north] (firm b) {Group 2 player};
\node[left=of m.west,align=center,anchor=center,
      rotate=90] {Group 1 player};
\end{tikzpicture}

\label{normal}
\caption{cap here}
\end{figure}

\end{document}

相关内容