0

I am wondering how to make a graph vertically centered in a slide. The graph is drawn using tikz. The code is below. Thank you very much!

\documentclass[usenames,dvipsnames,xcolor=table]{beamer}

\mode<presentation> { \usetheme{AnnArbor} % or try Darmstadt, Madrid, Warsaw, ... \usecolortheme{wolverine} % or try albatross, beaver, crane, ... \usefonttheme{default} % or try serif, structurebold, ... \setbeamertemplate{navigation symbols}{} \setbeamertemplate{caption}[numbered] }

\usepackage[english]{babel} \usepackage[utf8]{inputenc} \usepackage{datetime} \usepackage{caption} \usepackage{subfigure} \usepackage{comment} \usepackage{amsmath} \usepackage{amssymb} \usepackage{hyperref} \definecolor{plum(traditional)}{rgb}{0.56, 0.27, 0.52} \definecolor{darkpastelgreen}{rgb}{0.01, 0.75, 0.24} \definecolor{hotpink}{rgb}{1.0, 0.41, 0.71} \definecolor{lavenderindigo}{rgb}{0.58, 0.34, 0.92} \definecolor{mygray1}{gray}{0.8} \definecolor{mygray2}{gray}{0.6} \definecolor{mygray3}{gray}{0.4} \definecolor{mygray4}{gray}{0.2} \usepackage{amssymb} \usepackage{graphicx} \usepackage[style=authoryear]{biblatex} \addbibresource{Distraction_slides_reference.bib} \usepackage{tikz} \usetikzlibrary{patterns,arrows,decorations.pathreplacing,calc,intersections,through,backgrounds} \usepackage{slashed} \usepackage{upgreek}

\newdimen\XCoord \newdimen\YCoord \newcommand*{\ExtractCoordinate}[1]{\path (#1); \pgfgetlastxy{\XCoord}{\YCoord};}%

\newtheorem{proposition}{Proposition} \newtheorem{assumption}{Assumption} \newtheorem{axiom}{Axiom} \newtheorem{definition}{Definition} \newtheorem{theorem}{Theorem} \newtheorem{lemma}{Lemma} \newtheorem{proposition}{Proposition} \newtheorem{assumption}{Assumption} \newtheorem{remark}{Remark} \newtheorem{conjecture}{Conjecture} \DeclareMathOperator{\argmax}{arg,max}

\providecommand{\ux}[1]{#1} \renewcommand{\ux}[1]{\underline{#1}}

\setbeamertemplate{theorems}[numbered] \setbeamercovered{transparent}

\title{A} \author{B} \institute{C} \date{09/03/2021}

\begin{document}

\begin{frame}{} \begin{figure}[H] \centering

\begin{tikzpicture}[xscale=0.6,yscale=0.6]

\draw [fill] (-11.5,6) circle [radius=0.7]; \draw [fill=gray] (-10,6) circle [radius=0.45]; \draw [fill=gray] (-8.8,6) circle [radius=0.45]; \draw [fill=gray] (-7.6,6) circle [radius=0.45]; \draw [fill=gray] (-6.4,6) circle [radius=0.45]; \draw [fill] (-3.5,6) circle [radius=0.7]; \draw [fill=gray] (0,2.4) circle [radius=0.45]; \draw [fill=gray] (2,2.4) circle [radius=0.45]; \draw [fill=gray] (4,2.4) circle [radius=0.45];
\draw [fill=gray] (6,2.4) circle [radius=0.45];

\draw (0,7.8) -- (-3,6.2); \draw (0,7.8) -- (3,6.2); \draw (3,6.2) -- (1,4); \draw (3,6.2) -- (5,4); \draw (1,4) -- (0,2.8); \draw (1,4) -- (2,2.8); \draw (5,4) -- (4,2.8); \draw (5,4) -- (6,2.8);

\end{tikzpicture}
\end{figure} \end{frame}

Here is the output for the codes of Holger Karl on 2021/9/2: enter image description here

Ypbor
  • 399

2 Answers2

0

Would \vfill before and after the figure environment work? Something like this, with the code trimmed down:

\documentclass{beamer}

\usepackage{tikz}

\mode<presentation> { \usetheme{AnnArbor} % or try Darmstadt, Madrid, Warsaw, ... \usecolortheme{wolverine} % or try albatross, beaver, crane, ... \usefonttheme{default} % or try serif, structurebold, ... \setbeamertemplate{navigation symbols}{} \setbeamertemplate{caption}[numbered] }

\begin{document}

\begin{frame}

% possibly add vfill here: %\vfill \begin{tikzpicture}[xscale=0.4,yscale=0.4]

\draw [fill] (-11.5,6) circle [radius=0.7]; \draw [fill=gray] (-10,6) circle [radius=0.45]; \draw [fill=gray] (-8.8,6) circle [radius=0.45]; \draw [fill=gray] (-7.6,6) circle [radius=0.45]; \draw [fill=gray] (-6.4,6) circle [radius=0.45]; \draw [fill] (-3.5,6) circle [radius=0.7]; \draw [fill=gray] (0,2.4) circle [radius=0.45]; \draw [fill=gray] (2,2.4) circle [radius=0.45]; \draw [fill=gray] (4,2.4) circle [radius=0.45];
\draw [fill=gray] (6,2.4) circle [radius=0.45];

\draw (0,7.8) -- (-3,6.2); \draw (0,7.8) -- (3,6.2); \draw (3,6.2) -- (1,4); \draw (3,6.2) -- (5,4); \draw (1,4) -- (0,2.8); \draw (1,4) -- (2,2.8); \draw (5,4) -- (4,2.8); \draw (5,4) -- (6,2.8);

\end{tikzpicture}

% possibly add vfill here: %\vfill

\end{frame}

\end{document}

0

The answer of @Ignasi in this Latex beamer: How to horizontally/vertically center text, ignoring other content

For my case, it is

\begin{frame}{}
\begin{tikzpicture}[overlay, remember picture]
\node[anchor=center] at (current page.center) {
\begin{tikzpicture}[xscale=0.6,yscale=0.6]
blabla
\end{tikzpicture}
};
\end{tikzpicture}
\end{frame}
Juan Castaño
  • 28,426
Ypbor
  • 399