如何将 tikz 图片置于 latex beamer 页面的中心

如何将 tikz 图片置于 latex beamer 页面的中心

如何将 tikzpicture 居中?现在,它似乎从左边距开始。

滑动

这是我的代码:

\documentclass{beamer}

% choose theme (warning, to use the UniBern theme you need to copy the files beamerthemeUniBern.sty and ublogo.pdf in the same directory)
\usetheme{theme1}

% packages

\usepackage{graphicx}
\usepackage{hyperref} % allows clickable urls
\usepackage{tikz}
\usepackage{listings} % show code
\usepackage{dsfont} % show code
\usepackage{fontawesome}
\usepackage{tikz}
\usetikzlibrary{snakes}
\usetikzlibrary{positioning}
\newlength\yearposx
\makeatletter
\def\blfootnote{\gdef\@thefnmark{}\@footnotetext}
\makeatother

\definecolor{lightgrey}{RGB}{245,245,245}

% slide numbering
\setbeamertemplate{sidebar right}{}
\setbeamertemplate{footline}{%
    \hfill\usebeamertemplate***{navigation symbols}
    \hspace{1cm}\insertframenumber{}/\inserttotalframenumber}

% define title page

% begin document
\begin{document}


    

\frame{
    \frametitle{a}
    %till 2000

\scalebox{0.7}{
\begin{tikzpicture}[
node distance=1.5 cm and 0.8cm,
ar/.style={->,>=latex,thick},
mynode/.style={
  draw,
  line width=1pt,
  text width=3cm,
  minimum height= 1 cm,
  align=center
  }
]

\node[mynode,text width=3cm, fill=lightgrey] (c1) at (0,0) {Diagnosed};
\node[mynode,text width=3.5cm, fill=lightgrey, below=1cm of c1] (c2) {blablabla \\[1cm]$  $};
\node[mynode,text width=3.5cm, fill=lightgrey, below=1cm of c2] (c3) {blablabla \\[1cm]$  $};

\node[align=center,text width=3cm,left=2cm of c2] (c2_3) {First-line \\ blbla};
\node[align=center,text width=3cm,left=2cm of c3] (c3_3) {Second-line \\ blbla};
\node[draw,align=center,text width=18cm,below left =1cm and -11cm of c3] (text1) {\textbf{aaa}: Very long long long text 1 \hspace{0.5cm}
\textbf{aaa}: Very long long long text 2\hspace{0.5cm}
\textbf{aaa}: Very long long long text 3};

\draw[->,thick] (c1) -- (c2);
\draw[->,thick] (c2) -- (c3);
\end{tikzpicture}}
}
\end{document}

以下是主题:

\RequirePackage{calc}
\RequirePackage{etoolbox}

\mode<presentation>

\newdimen\beamer@ubBorderHeight
\newdimen\beamer@ubTitleHeight
\newdimen\beamer@ubFooterHeight
\newdimen\beamer@ubOverlap

\beamer@ubOverlap=0.2pt
\beamer@ubBorderHeight=0.015\paperheight
\beamer@ubTitleHeight=0.125\paperheight
\beamer@ubFooterHeight=0.032\paperheight

\definecolor{ubRed}{HTML}{E6002E}
\definecolor{ubGrey}{RGB}{255,255,255}

\ProcessOptionsBeamer

\setbeamercolor{normal text}{fg=black}
\setbeamercolor{alerted text}{fg=ubRed}
\setbeamercolor{itemize item}{fg=ubRed}
\setbeamercolor{itemize subitem}{fg=ubRed}
\setbeamercolor{example text}{fg=black}
\setbeamercolor{structure}{fg=black}
\setbeamercolor{date in title page}{fg=black}

% set fonts
\RequirePackage[scaled]{helvet}
\renewcommand*\familydefault{\sfdefault}

\usefonttheme[onlymath]{serif}
\RequirePackage{iftex}
\ifPDFTeX
\RequirePackage[T1]{fontenc}
\RequirePackage[utf8]{inputenc}
\fi



\setbeamerfont*{structure}{series=\bfseries}
\setbeamerfont*{title}{size*={18}{22}}
\setbeamercolor*{title}{bg=ubRed}
\setbeamerfont*{subtitle}{size*={18}{22}}
\setbeamerfont*{author}{size*={10}{12},series=\bfseries}
\setbeamerfont*{institute}{size*={10}{12}}
\setbeamerfont*{frametitle}{size*={18}{22}}
\setbeamercolor*{frametitle}{fg=ubRed}
\setbeamerfont*{framesubtitle}{size*={18}{22}}
\setbeamercolor*{framesubtitle}{fg=black}
\setbeamerfont*{date}{size*={8}{10}}
\setbeamerfont*{headline}{size*={8}{10}}
\beamertemplatenavigationsymbolsempty

\defbeamertemplate*{title page}{uni bern}{%
  % list trick from https://texfaq.org/FAQ-chngmargonfly
  \begin{list}{}{
  \setlength{\listparindent}{\parindent}%
  \setlength{\itemindent}{\parindent}%
  \setlength{\parsep}{\parskip}%
  \setlength{\leftmargin}{0pt}%
  \setlength{\rightmargin}{0pt}}
  \item[]
  \vspace*{\stretch{2}}
  {\usebeamerfont*{title}\color{ubRed}\inserttitle\par} % no idea why usebeamercolor{title} does not work here
  {\usebeamerfont*{subtitle}\insertsubtitle\par}
  \vspace{\stretch{1}}
  {\usebeamerfont{author}\insertauthor\par}
  {\usebeamerfont{date}\insertdate\par}
  \vspace*{\stretch{2}}
  \end{list}
%  \end{minipage}
}

\defbeamertemplate*{background canvas}{uni bern}{%
\begin{minipage}[t]{\paperwidth+10pt}
   \setlength{\baselineskip}{0pt}
   \setlength{\lineskip}{-\beamer@ubOverlap}
   \setlength{\parskip}{0pt}
   \ifnumgreater{\c@framenumber}{1}{}{}

   \ifnumgreater{\c@framenumber}{2}{
        \ifdefempty{\insertframesubtitle}{
          \rule{0pt}{6ex+\beamer@ubTitleHeight}\\
          \color{ubGrey}\rule{\paperwidth}{\paperheight-\beamer@ubTitleHeight-\beamer@ubFooterHeight-6ex}
        }{
          \rule{0pt}{6ex+2\beamer@ubTitleHeight}\\          
          \color{ubGrey}\rule{\paperwidth}{\paperheight-2\beamer@ubTitleHeight-\beamer@ubFooterHeight-6ex}   
        }
   }{}
  \end{minipage}
}

\defbeamertemplate*{headline}{uni bern}{% 
    \ifnumgreater{\c@framenumber}{2}{
      \vspace{3.5ex}
      \hspace{4.5ex}\inserttitle
    }{}
}

\defbeamertemplate*{frametitle}{uni bern}{
\begin{minipage}[b]{\textwidth}
\vspace{0.5ex}
\raggedright
\vspace{3.5ex}
{\insertframetitle\par}
{\usebeamerfont{framesubtitle}\usebeamercolor*{framesubtitle}\insertframesubtitle}
\end{minipage}
}


% set bullets

\defbeamertemplate*{itemize item}{uni bern}{$\bullet$}
\defbeamertemplate*{itemize subitem}{uni bern}{$\bullet$}
\setbeamersize{text margin left=4ex}
\setbeamersize{text margin right=4ex}



\mode<all>

答案1

如果你想居中某物超出\textwidth(因此不会居中,而是左对齐),通常有助于假装某物宽度为零。

\begin{center}
\makebox[0pt]{%
   something%
}
\end{center}

确保没有多余的空格,因为这些空格可能会带来某物偏离中心。

在此处输入图片描述

\documentclass{beamer}

% choose theme (warning, to use the UniBern theme you need to copy the files beamerthemeUniBern.sty and ublogo.pdf in the same directory)
\usetheme{theme1}

% packages

\usepackage{graphicx}
\usepackage{hyperref} % allows clickable urls
\usepackage{tikz}
\usepackage{listings} % show code
\usepackage{dsfont} % show code
\usepackage{fontawesome}
\usepackage{tikz}
\usetikzlibrary{snakes}
\usetikzlibrary{positioning}
\newlength\yearposx
\makeatletter
\def\blfootnote{\gdef\@thefnmark{}\@footnotetext}
\makeatother

\definecolor{lightgrey}{RGB}{245,245,245}

% slide numbering
\setbeamertemplate{sidebar right}{}
\setbeamertemplate{footline}{%
    \hfill\usebeamertemplate***{navigation symbols}
    \hspace{1cm}\insertframenumber{}/\inserttotalframenumber}

% define title page

% begin document
\begin{document}


    

\frame{
    \frametitle{a}
    %till 2000

    \begin{center}
      \makebox[0pt]{%
\scalebox{0.7}{%
\begin{tikzpicture}[
node distance=1.5 cm and 0.8cm,
ar/.style={->,>=latex,thick},
mynode/.style={
  draw,
  line width=1pt,
  text width=3cm,
  minimum height= 1 cm,
  align=center
  }
]

\node[mynode,text width=3cm, fill=lightgrey] (c1) at (0,0) {Diagnosed};
\node[mynode,text width=3.5cm, fill=lightgrey, below=1cm of c1] (c2) {blablabla \\[1cm]$  $};
\node[mynode,text width=3.5cm, fill=lightgrey, below=1cm of c2] (c3) {blablabla \\[1cm]$  $};

\node[align=center,text width=3cm,left=2cm of c2] (c2_3) {First-line \\ blbla};
\node[align=center,text width=3cm,left=2cm of c3] (c3_3) {Second-line \\ blbla};
\node[draw,align=center,text width=18cm,below left =1cm and -11cm of c3] (text1) {\textbf{aaa}: Very long long long text 1 \hspace{0.5cm}
\textbf{aaa}: Very long long long text 2\hspace{0.5cm}
\textbf{aaa}: Very long long long text 3};

\draw[->,thick] (c1) -- (c2);
\draw[->,thick] (c2) -- (c3);
\end{tikzpicture}}}
\end{center}
}
\end{document}

相关内容