我怎样才能将 tikz 图像对齐在左侧并将表格对齐在右侧?

我怎样才能将 tikz 图像对齐在左侧并将表格对齐在右侧?

我想知道如何在 PPT 上将 tikz 对齐到左侧,将表格对齐到右侧。您能帮我解决这个问题吗?谢谢!

目前的结果

\documentclass[10pt]{beamer}
\usepackage{caption}
\usepackage{subcaption}
\usetheme[progressbar=frametitle]{metropolis}
\usepackage{appendixnumberbeamer,pifont}
\usepackage{mathrsfs}
\usepackage{booktabs}
\usepackage[scale=2]{ccicons}
\usepackage{graphicx}
\usepackage{pgfplots}
\usepackage{siunitx}
\usepgfplotslibrary{dateplot}
\usepackage{amsmath}
\usepackage{cite}
\usepackage{xspace}
\newcommand{\themename}{\textbf{\textsc{metropolis}}\xspace}
\usetikzlibrary{hobby,backgrounds,calc,trees,patterns}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
%\usetikzlibrary{patterns,topaths,hobby,calc,backgrounds}
%%TikZ settings
\tikzset{dashblue/.style ={densely dashed, color=blue}}
\tikzset{dashred/.style ={densely dashed, color=red}}
\tikzset{dashgreen/.style ={densely dashed, color=green!50!black}}
\tikzset{blueline/.style ={very thick, color=blue}}
\tikzset{redline/.style ={very thick, color=red}}
\tikzset{thickgrey/.style ={ultra thick, color=black!50!white}}
\tikzset{greenline/.style ={color=green!50!black}}

\colorlet{dgreen}{green!50!black}
\colorlet{dred}{red!50!black}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Styles For TIKz
\usepackage{tikz,listings}
 \tikzstyle{odplayer}=[minimum size=15pt,inner sep=0pt,outer sep=0pt,ball color=red!50!white, circle]
 \tikzstyle{pfplayer}=[minimum size=15pt,inner sep=0pt,outer sep=0pt,ball color=blue!40!white, circle]
  \tikzstyle{udplayer}=[minimum size=15pt,inner sep=0pt,outer sep=0pt,ball color=black!40!white, circle]
\begin{document}
\begin{frame}{Comparison}
\begin{figure}[ht]
\begin{subfigure}{0.5\textwidth}
  \centering
  \begin{tikzpicture}[scale=0.5,auto,thick]
    \path  (180:3) node[pfplayer]  (a) {$1$}
    (180:1) node[pfplayer]  (b) {$2$}
    (0:1)   node[pfplayer]  (c) {$3$}
    (0:3)   node[pfplayer]  (d) {$4$};
    \draw[ultra thick] (a)--(b) (b)--(c) (c)--(d) ;
    \end{tikzpicture}
\end{subfigure}
\begin{subfigure}{0.5\textwidth}
  \centering
  \begin{small}
\begin{tabular}[b]{c|cccc|c} 
    \toprule 
    Model & \multicolumn{1}{c}{$u_1$} &\multicolumn{1}{c}{$u_2$} &
    \multicolumn{1}{c}{$u_3$}&
    \multicolumn{1}{c|}{$u_4$}& $\sum u_i$
    \\
    \midrule 
    A & 0.5&0.5&0.5&0.5&2\\
    B & 0.5&0.5&0.5&0.5&2 \\
    C& 0.5&0.5&0.5&0.5&2 \\
    D & 0.5&0.5&0.5&0.5&2\\
    \bottomrule 
    \end{tabular}
  \end{small}
\end{subfigure}\label{fig:fig}
\end{figure}
\end{frame}
\end{document}

答案1

您的问题已通过评论解决,因此这里有一些题外的评论/建议:

  • beamer中还加载amsmath其他graphicx
  • beamer图环境中不浮动
  • caption包不能很好地工作 beamer,它有自己的机制
  • 从你的 MWE 可以看出,你的子图、子表没有标题,因此你不需要这些环境
  • 图形标签没有意​​义,因为它没有标题
  • 可以通过设置图像基线来调整图像相对于表格的垂直位置(参见下面的 MWE)

从您的文档示例中获得的可能的 MWE (最小工作示例) 可以是:

\documentclass[10pt]{beamer}
\usetheme[progressbar=frametitle]{metropolis}
\usepackage{tikz}
\usetikzlibrary{chains,
                positioning}
\usepackage{makecell}
  
\begin{document}
\begin{frame}{Comparison}
    \begin{figure}
    \centering
    \setcellgapes{3pt}
    \makegapedcells
\begin{tikzpicture}[baseline=0.5\baselineskip, % <---
node distance = 7mm,
  start chain = going right,
  BALL/.style = {circle, minimum size=1em, ball color=blue!40!white,
                 outer sep=0pt,
                 on chain, join=by {-,very thick}}
]
\foreach \i in {1,2,3,4}
    \node (n\i) [BALL] {\i};
    \end{tikzpicture}
\hfil
  \small
\begin{tabular}{c|cccc|c}
    \Xhline{1.2pt}
    Model & $u_1$   &   $u_2$   &   $u_3$   &   $u_4$   & $\sum u_i$    \\
    \Xhline{0.8pt}
    A & 0.5 & 0.5 & 0.5 & 0.5 & 2   \\
    B & 0.5 & 0.5 & 0.5 & 0.5 & 2   \\
    C & 0.5 & 0.5 & 0.5 & 0.5 & 2   \\
    D & 0.5 & 0.5 & 0.5 & 0.5 & 2   \\
    \Xhline{1.2pt}
    \end{tabular}
\end{figure}
\end{frame}
\end{document}

在此处输入图片描述

相关内容