如何同时为 Beamer 居中和缩放 tikz 图片

如何同时为 Beamer 居中和缩放 tikz 图片

我需要缩放 Tikz 图片并将其置于框架的中心(我使用的是 Rmarkdown)。我尝试了几个选项scaleboxtransform canvas,,,,,,,等等...adjustboxscalebegin{center}centering

但是当我缩小图形时,它不会居中,反之亦然。这是我的代码:

---
title: "Untitled"
author: "Guilherme"
date: "3/17/2021"
output: 
  beamer_presentation:
    includes:
      in_header: /home/guilherme/GoogleDrive/Analises/Modelo/extra_settings2.tex
---

## Frame
\scalebox{.6}{
\centering
\begin{tikzpicture}[node distance = 3cm, auto]
    \tikzstyle{decision} = [diamond, fill=blue!15, 
        text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
    \tikzstyle{block} = [rectangle, fill=blue!15, 
        text width=5em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{line} = [draw, -latex']
    \tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
        minimum height=2em]
    \node [block] (mcglm) {MCGLM};
    \node [block, right of=mcglm] (poissons) {Poisson sample};
    \node [block, right of=poissons] (poissonf) {Poisson full data};
    \node [block, right of=poissonf] (negbins) {NB sample};
    \node [decision, above of=poissonf] (est1) {1ºPORT 2ºBFGS 3ºPORT};
    \node [block, below of=mcglm] (negbinf) {NB full data};
    \node [block, right of=negbinf] (cmps) {COM-Poisson sample};
    \node [decision, below of=negbinf] (est2) {1ºPORT 2ºBFGS 3ºPORT};
    \node [block, right of=cmps] (cmpf) {COM-Poisson full data};
    \node [decision, below of=cmpf] (est3) {1ºPORT 2ºBFGS 3ºPORT};
    \path [line] (mcglm) -- (poissons);
    \path [line] (poissons) -- (poissonf);
    \path [line] (poissonf) -- (negbins);
    \path [line] (negbins) -- node {} +(2,0) |- node {} (0,-1.5) -| node {} (0,-2.1);
    \path [line] (negbinf) -- (cmps);
    \path [line] (cmps) -- (cmpf);
    \path [line] (poissonf) edge[bend left] node [below left] {} (est1);
    \path [line] (est1) edge[bend left] node [below left] {} (poissonf);
    \path [line] (negbinf) edge[bend right] node [below left] {} (est2);
    \path [line] (est2) edge[bend right] node [below left] {} (negbinf);
    \path [line] (cmpf) edge[bend right] node [below left] {} (est3);
    \path [line] (est3) edge[bend right] node [below left] {} (cmpf);
\end{tikzpicture}
}

extra_settings2.tex文件:

\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{footline}[frame number]
\usepackage{pgf, tikz}
\usetikzlibrary{arrows, automata}
\usetikzlibrary{shapes.geometric}% Package for below command
\tikzstyle{square}=[draw]        % It defines square for graph
\usepackage{adjustbox}           % It resizes tikz pictures

结果: 在此处输入图片描述

答案1

这样怎么样?您也可以\hspace*{\fill}用注释掉的center环境替换,但我喜欢这样与\vspace*{\fill}

投影机

\documentclass{beamer}

\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{footline}[frame number]
\usepackage{pgf, tikz}
\usetikzlibrary{arrows, automata}
\usetikzlibrary{shapes.geometric}% Package for below command
\tikzstyle{square}=[draw]        % It defines square for graph
\usepackage{adjustbox}           % It resizes tikz pictures
   \usetikzlibrary{arrows,automata,positioning,calc,backgrounds}


\begin{document}
\vspace*{\fill}

% \begin{center}
\hspace*{\fill} \scalebox{0.5}{%
\begin{tikzpicture}[node distance = 3cm, auto]
    \tikzstyle{decision} = [diamond, fill=blue!15, 
        text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
    \tikzstyle{block} = [rectangle, fill=blue!15, 
        text width=5em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{line} = [draw, -latex']
    \tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
        minimum height=2em]
    \node [block] (mcglm) {MCGLM};
    \node [block, right of=mcglm] (poissons) {Poisson sample};
    \node [block, right of=poissons] (poissonf) {Poisson full data};
    \node [block, right of=poissonf] (negbins) {NB sample};
    \node [decision, above of=poissonf] (est1) {1ºPORT 2ºBFGS 3ºPORT};
    \node [block, below of=mcglm] (negbinf) {NB full data};
    \node [block, right of=negbinf] (cmps) {COM-Poisson sample};
    \node [decision, below of=negbinf] (est2) {1ºPORT 2ºBFGS 3ºPORT};
    \node [block, right of=cmps] (cmpf) {COM-Poisson full data};
    \node [decision, below of=cmpf] (est3) {1ºPORT 2ºBFGS 3ºPORT};
    \path [line] (mcglm) -- (poissons);
    \path [line] (poissons) -- (poissonf);
    \path [line] (poissonf) -- (negbins);
    \path [line] (negbins) -- node {} +(2,0) |- node {} (0,-1.5) -| node {} (0,-2.1);
    \path [line] (negbinf) -- (cmps);
    \path [line] (cmps) -- (cmpf);
    \path [line] (poissonf) edge[bend left] node [below left] {} (est1);
    \path [line] (est1) edge[bend left] node [below left] {} (poissonf);
    \path [line] (negbinf) edge[bend right] node [below left] {} (est2);
    \path [line] (est2) edge[bend right] node [below left] {} (negbinf);
    \path [line] (cmpf) edge[bend right] node [below left] {} (est3);
    \path [line] (est3) edge[bend right] node [below left] {} (cmpf);
\end{tikzpicture}%
}\hspace*{\fill}
% \end{center}

\vspace*{\fill}


\end{document}

答案2

您也许会成功使用resizebox

\documentclass{beamer}
\usepackage{tikz}
\usepackage{graphicx}

\begin{document}
\begin{frame}
    \begin{center}
    \resizebox{.8\linewidth}{!}{
        \begin{tikzpicture}
            \node {\includegraphics[width=10cm]{example}};
        \end{tikzpicture}
    }
\end{center}
\end{frame}
\end{document}

相关内容