图表对齐

图表对齐
\documentclass{article}

\usepackage[demo]{graphicx}
\usepackage{subfig}
\usepackage{tabularx}



\usepackage{tikz}
\usetikzlibrary{arrows}


\tikzstyle{male}=[circle,fill=blue!20,draw,font=\sffamily\Large\bfseries]
\tikzstyle{female}=[circle,fill=red!20,draw,font=\sffamily\Large\bfseries]

\begin{document}

\begin{figure}
\def\tabularxcolumn#1{m{#1}}
\begin{tabularx}{\linewidth}{@{}cXX@{}}
%
\begin{tabular}{cc}
\subfloat[A]{\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,
  thick]
  \node[male] (1) {1};
  \node[female] (2) [below left of=1] {2};
  \node[male] (3) [below right of=2] {3};
  \node[female] (4) [below right of=1] {4};
  \path[every node/.style={font=\sffamily\small}]
    (1) edge node {} (3)
    (2) edge node [right] {} (3)
    (3) edge [bend right] node[right] {} (1)
    (4) edge node {} (2)
\end{tikzpicture}} 
   & \subfloat[B]{\begin{tikzpicture}[baseline,->,>=stealth',shorten >=1pt,auto,node distance=3cm,
     thick]
     \node[female] (1) {1};
     \node[male] (2) [below left of=1] {2};
     \node[male] (3) [below right of=2] {3};
     \node[female] (4) [below right of=1] {4};
     \path[every node/.style={font=\sffamily\small}]
    (2) edge node [left] {} (1)
        edge node [right] {} (3)
    (4) edge node [right] {} (1)
        edge node [left] {} (3)

   \end{tikzpicture}}\\
\subfloat[C]{\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,
  thick]
  \node[male] (1) {1};
  \node[female] (2) [below left of=1] {2};
  \node[male] (3) [below right of=2] {3};
  \node[female] (4) [below right of=1] {4};

  \path[every node/.style={font=\sffamily\small}]
    (1) edge node {} (3)
    (2) edge node [right] {} (3)

\end{tikzpicture}} 
   & \subfloat[D]{\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,
     thick]
     \node[female] (1) {1};
     \node[male] (2) [below left of=1] {2};
     \node[male] (3) [below right of=2] {3};
     \node[female] (4) [below right of=1] {4};

     \path[every node/.style={font=\sffamily\small}]
       (2) edge node [left] {} (3)
       (4) edge node [left] {} (3)
   \end{tikzpicture}}\\

\end{tabular}

\end{tabularx}

\caption{Isomorphism}\label{foo}
\end{figure}

\end{document}

答案1

第二个子图 (B)在环境baseline选项列表中有一个多余的tikzpicture。删除它,图形就会正确对齐。此外,您不需要将子图放入环境中tabular

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{subfig}
\usepackage{tikz}
\usetikzlibrary{arrows}

\tikzstyle{male}=[circle,fill=blue!20,draw,font=\sffamily\Large\bfseries]
\tikzstyle{female}=[circle,fill=red!20,draw,font=\sffamily\Large\bfseries]

\begin{document}
  \begin{figure}[!htb]
    \subfloat[A]{%
      \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,thick]
        \node[male] (1) {1};
        \node[female] (2) [below left of=1] {2};
        \node[male] (3) [below right of=2] {3};
        \node[female] (4) [below right of=1] {4};

        \path[every node/.style={font=\sffamily\small}]
          (1) edge node {} (3)
          (2) edge node [right] {} (3)
          (3) edge [bend right] node[right] {} (1)
          (4) edge node {} (2);
        \end{tikzpicture}%
    }
    \hfill
    \subfloat[B]{%
      \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,thick]
        \node[female] (1) {1};
        \node[male] (2) [below left of=1] {2};
        \node[male] (3) [below right of=2] {3};
        \node[female] (4) [below right of=1] {4};

        \path[every node/.style={font=\sffamily\small}]
          (2) edge node [left] {} (1)
              edge node [right] {} (3)
          (4) edge node [right] {} (1)
              edge node [left] {} (3);
      \end{tikzpicture}%
    }\\
    \subfloat[C]{%
      \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,thick]
        \node[male] (1) {1};
        \node[female] (2) [below left of=1] {2};
        \node[male] (3) [below right of=2] {3};
        \node[female] (4) [below right of=1] {4};

        \path[every node/.style={font=\sffamily\small}]
          (1) edge node {} (3)
          (2) edge node [right] {} (3);
      \end{tikzpicture}%
    }
    \hfill
    \subfloat[D]{%
      \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,thick]
        \node[female] (1) {1};
        \node[male] (2) [below left of=1] {2};
        \node[male] (3) [below right of=2] {3};
        \node[female] (4) [below right of=1] {4};

        \path[every node/.style={font=\sffamily\small}]
          (2) edge node [left] {} (3)
          (4) edge node [left] {} (3);
      \end{tikzpicture}%
    }
    \caption{Isomorphism}\label{foo}
  \end{figure}
\end{document}

下次请检查示例的功能。由于忘记了一些分号,此处的示例无法编译。


在此处输入图片描述

相关内容