![将 tikz 图片和表格并排放置](https://linux22.com/image/348010/%E5%B0%86%20tikz%20%E5%9B%BE%E7%89%87%E5%92%8C%E8%A1%A8%E6%A0%BC%E5%B9%B6%E6%8E%92%E6%94%BE%E7%BD%AE.png)
我试图将一个简单的表格和一个 tikz 图像并排放置。它似乎根本不起作用,它们堆叠在一起。
\documentclass[11pt]{article}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{tikz}
\usepackage{float}
\usepackage{graphicx}
\begin{document}
\begin{figure}[ht]
\centering
\noindent\begin{minipage}{.5\linewidth}
\centering
\begin{tikzpicture}
\node[draw] (A1) at (0,0) {$A_1$};
\node[draw] (A2) at (1.5,0) {$A_2$};
\node[draw] (A3) at (3,0) {$A_3$};
\draw[->] (A1) to (A2);
\draw[bend left, ->] (A2) to (A3);
\draw[bend left, ->] (A3) to (A2);
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.5\linewidth}
\begin{tabular}{l | c c c}
\toprule
Attacking/Attacked & $A_1$ & $A_2$ & $A_3$ \\ \midrule
$A_1$ & 0 & 1 & 0 \\
$A_2$ & 0 & 0 & 1 \\
$A_3$ & 0 & 1 & 0 \\
\toprule
$\sum Attacked$ & 0 & 2 & 1 \\
\bottomrule
\end{tabular}
\end{minipage}
\caption{Some matrix}
\label{graph:exampleMatrix}
\end{figure}
\end{document}
我尝试过使用 minipage,但我的图像却堆叠起来了。
答案1
我建议使用tabular
环境而不是minipages
:
\documentclass[11pt]{article}
\usepackage{booktabs, makecell}
\usepackage{tikz}
\begin{document}
\begin{figure}[ht]
\centering
\setcellgapes{5pt}
\makegapedcells
\setlength\belowrulesep{0pt}
\setlength\aboverulesep{0pt}
\begin{tabular}{c@{\qquad}c}
\begin{tikzpicture}
\node[draw] (A1) at (0,0) {$A_1$};
\node[draw] (A2) at (1.5,0) {$A_2$};
\node[draw] (A3) at (3,0) {$A_3$};
%
\draw[->] (A1) to (A2);
\draw[bend left, ->] (A2) to (A3);
\draw[bend left, ->] (A3) to (A2);
\end{tikzpicture}
&
\begin{tabular}{l | c c c }
\toprule
Attacking/Attacked & $A_1$ & $A_2$ & $A_3$ \\ \midrule
$A_1$ & 0 & 1 & 0 \\
$A_2$ & 0 & 0 & 1 \\
$A_3$ & 0 & 1 & 0 \\
\toprule
$\sum Attacked$ & 0 & 2 & 1 \\
\bottomrule
\end{tabular}
\end{tabular}
\caption{Some matrix}
\label{graph:exampleMatrix}
\end{figure}
\end{document}
对于单元格中的垂直空间,我添加宏\makegapedcells
,将间隙设置为,5pt
并从中删除规则周围的垂直空间booktabs
。