消除幻灯片之间的公式跳跃

消除幻灯片之间的公式跳跃

如何消除幻灯片之间方程式的跳跃?我希望,即使变量发生变化,两张幻灯片上的 也位于同一位置\leq\geq

\documentclass{beamer} 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\usepackage{tkz-euclide}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usepackage{geometry}
\geometry{left = 30mm, right = 30mm}    
\usepackage[it]{caption}
\usepackage{subfig}

\begin{document}


  \begin{columns}[onlytextwidth]
    \begin{column}{0.45\textwidth}

 Given convex $MINLP$

  \begin{align*}
  \min z \\
  y_1 + y_2 + x_1^2 + x_2^2 &\leq z \\
  (x_1-2)^2-x_2 &\leq 0 \\
  x_1 - 2y_1 &\geq 0 \\
  x_1-x_2-3(1-y_1) &\leq 0 \\
  x_1 - (1-y_1) &\geq 0 \\
  x_2-y_2 &\leq 0 \\
  x_1+x_2 &\leq 3y_1\\ 
  y_1+y_2 &\leq 1\\
  0 \leq x_1,x_2, &\leq 4\\
  y_1,y_2 &\in \{0,1\}
  \end{align*}  

 Choose initial integer solutions $y_1 = y_2 = 1$. Upper bound $U = \infty$. 


    \end{column}
    \begin{column}{0.45\textwidth}
% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=blue!20, 
    text width=7.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20, 
    text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{blockH} = [rectangle, draw, fill=red!20, 
    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]

\begin{tikzpicture}[node distance = 3.5cm, auto]
    % Place nodes
    \node [blockH] (init) {Init};
    \node [block, below of=init, node distance=3cm] (NLP) { Solve NLP($x^k_I$) or F($x^k_I$)};
    \node [block, below of=NLP] (Bound) { Add linearaziation at $x^k$  to MIP};
    \node [block, below of=Bound] (MIP) { Solve MIP($x^k$, $U$) };
    \node [decision, right of=MIP, node distance=6cm] (Infeas) { MIP infeasible? -> Exit };

    \path [line] (init) -- (NLP);
    \path [line] (NLP) -- node {Update U?} (Bound);
%    \path [line] (Bound) -- (Update);
    \path [line] (Bound) -- (MIP);
     \path [line] (MIP) -- (Infeas);
      \path [line] (Infeas) |-  node[near start] {No} (NLP);
\end{tikzpicture}
    \end{column}
  \end{columns}
  \end{frame}







  %Step 2
  \begin{frame}

  \begin{columns}[onlytextwidth]
    \begin{column}{0.45\textwidth}

 Fix $y_1 = y_2 = 1$ and solve NLP. 

  \begin{align*}
  \min z \\
  1 + 1 + x_1^2 + x_2^2 &\leq z \\
  (x_1-2)^2-x_2 &\leq 0 \\
  x_1 - 2 &\geq 0 \\
  x_1-x_2-3(1-1) &\leq 0 \\
  x_1 - (1-1) &\geq 0 \\
  x_2-1 &\leq 0 \\
  x_1+x_2 &\leq 3\\ 
  1+1 &\leq 1\\
  0 \leq x_1,x_2, &\leq 4\\
  1,1 &\in \{0,1\}
  \end{align*}  

Optimal solution $x_1=x_2=2$, (x,y) = (2,2,1,1) is a solution to our $MINLP$.


    \end{column}
    \begin{column}{0.45\textwidth}
% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=blue!20, 
    text width=7.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20, 
    text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{blockH} = [rectangle, draw, fill=red!20, 
    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]

\begin{tikzpicture}[node distance = 3.5cm, auto]
    % Place nodes
    \node [block] (init) {Init};
    \node [blockH, below of=init, node distance=3cm] (NLP) { Solve NLP($x^k_I$) or F($x^k_I$)};
    \node [block, below of=NLP] (Bound) { Add linearaziation at $x^k$  to MIP};
    \node [block, below of=Bound] (MIP) { Solve MIP($x^k$, $U$) };
    \node [decision, right of=MIP, node distance=6cm] (Infeas) { MIP infeasible? -> Exit };

    \path [line] (init) -- (NLP);
    \path [line] (NLP) -- node {Update U?} (Bound);
%    \path [line] (Bound) -- (Update);
    \path [line] (Bound) -- (MIP);
     \path [line] (MIP) -- (Infeas);
      \path [line] (Infeas) |-  node[near start] {No} (NLP);
\end{tikzpicture}
    \end{column}
  \end{columns}
  \end{frame}
\end{document}

答案1

为什么要使用geometry包装?您应该记住,beamer幻灯片的实际尺寸是 128 x 96 毫米,因此您需要\geometry{left = 30mm, right = 30mm}截断一半的幻灯片宽度!因此,所有内容都移到了右侧,由于空间太小,这会带来问题。

编辑(1):

  • 删除geometry包并定义文本宽度
  • 重新绘制你的图形,以便它们适合幻灯片
  • 不要使用过时的语法tikzpicure(而是right=of (...)使用right=of (...),而是tikzstyle使用tikzset,...)
  • 在序言中集中样式(代码将变得更短)

编辑(2):

  • 如果右列(第二列)的图片在两个框架上相等,那么您可以考虑将两个框架合并为一个,并使用\only<..>{ ...}揭示机制
  • 将方程式放入array环境中,并在两个数组中定义相等的行高和第一列宽
  • 添加\vphantom{$y_1$}文本“给定凸 MINLP。”
  • 将两个数组添加\setlength\arraycolsep{2pt}到两个数组,使水平距离\leq相等。
  • 使第一列中的图片高于文本和公式

经过所有这些测量后,图片和位置leq将在框架中固定,但是由于第一张和第二张幻灯片上的方程式不同,它们的外观(宽度)将发生变化。新代码是:

\documentclass{beamer}
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    %\usepackage[ngerman]{babel}
    \usepackage{tikz}
\usetikzlibrary{arrows,positioning,shapes.geometric}
\usepackage{array}

\tikzset{
    node distance = 9mm and 5mm,
    auto,
decision/.style = {diamond, draw, fill=blue!20,
                   text width=5em, align=flush center, inner sep=-2pt},
   block/.style = {rectangle, draw, fill=blue!20,
                   text width=5em, align=center, rounded corners,
                   minimum height=4em},
  blockH/.style = {rectangle, draw, fill=red!20,
                   text width=5em, align=center, rounded corners,
                   minimum height=4ex},
    line/.style = {draw, -latex'},
   cloud/.style = {draw, ellipse, fill=red!20, minimum height=2em}
        }

    \begin{document}
\begin{frame}
\begin{columns}[b,onlytextwidth]
    \begin{column}{0.5\textwidth}
\only<1>{
\vphantom{$y_1$}Given convex MINLP.\vspace*{-1ex}
    \setlength\arraycolsep{2pt}
\[\begin{array}{@{\rule[-1ex]{0pt}{3ex}}>{\raggedleft\arraybackslash$}p{9em}<{$}l}
                    \min z  &           \\
y_1 + y_2 + x_1^2 + x_2^2   &   \leq z  \\
            (x_1-2)^2-x_2   &   \leq 0  \\
                x_1 - 2y_1  &   \geq 0  \\
        x_1-x_2-3(1-y_1)    &   \leq 0  \\
            x_1 - (1-y_1)   &   \geq 0  \\
                    x_2-y_2 &   \leq 0  \\
                    x_1+x_2 &   \leq 3y_1   \\
                    y_1+y_2 &   \leq 1  \\
            0 \leq x_1,x_2, &   \leq 4  \\
                    y_1,y_2 &   \in \{0,1\}
\end{array}\]
Choose initial integer solutions $y_1 = y_2 = 1$. Upper bound $U = \infty$.
    }
\only<2>{
Fix $y_1 = y_2 = 1$ and solve NLP.\vspace*{-1ex}
    \setlength\arraycolsep{2pt}
\[\begin{array}{@{\rule[-1ex]{0pt}{3ex}}>{\raggedleft\arraybackslash$}p{9em}<{$}l}
              \min z  \\
1 + 1 + x_1^2 + x_2^2   &   \leq z \\
        (x_1-2)^2-x_2   &   \leq 0 \\
            x_1 - 2     &   \geq 0 \\
        x_1-x_2-3(1-1)  &   \leq 0 \\
            x_1 - (1-1) &   \geq 0 \\
                x_2-1   &   \leq 0 \\
                x_1+x_2 &   \leq 3\\
                    1+1 &   \leq 1\\
         0 \leq x_1,x_2 &   \leq 4\\
                    1,1 &   \in \{0,1\}
\end{array}\]
Optimal solution $x_1=x_2=2$, $(x,y)=(2,2,1,1)$ is a solution
to our MINLP.
    }
    \end{column}
    \begin{column}{0.48\textwidth}
\begin{tikzpicture}
% Place nodes
\node [blockH]                  (init)  {Init};
\node [block,below=of init]     (NLP)   {Solve NLP($x^k_I$) or F($x^k_I$)};
\node [block,below=of NLP]      (Bound) {Add linearaziation at $x^k$  to MIP};
\node [block,below=of Bound]    (MIP)   {Solve MIP($x^k, U$)};
\node [decision,right=of MIP]   (Infeas){MIP infeasible?\\ -> Exit};
%
\path[line] (init)  edge (NLP)
            (NLP)   edge node {Update U?} (Bound)
            (Bound) edge (MIP)
            (MIP)   edge (Infeas)
            (Infeas) |-  node[near start] {No} (NLP);
\end{tikzpicture}
    \end{column}
  \end{columns}
\end{frame}
\end{document}

在此处输入图片描述

原始代码(第一次编辑后)是:

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%\usepackage[ngerman]{babel}
\usepackage{tikz}
\usetikzlibrary{arrows,decorations.pathmorphing,shapes}
\usepackage{tkz-euclide}
%\usepackage{tikz} <-- second time ...
%\usepackage{geometry}
%\geometry{left = 30mm, right = 30mm}
\usepackage[it]{caption}
\usepackage{subfig}

\tikzset{
    node distance = 7mm and 5mm,
    auto,
decision/.style = {diamond, draw, fill=blue!20,
                   text width=7.5em, align=flush center, inner sep=-2pt},
   block/.style = {rectangle, draw, fill=blue!20,
                   text width=5em, align=center, rounded corners,
                   minimum height=4em},
  blockH/.style = {rectangle, draw, fill=red!20,
                   text width=5em, align=center, rounded corners,
                   minimum height=4ex},
    line/.style = {draw, -latex'},
   cloud/.style = {draw, ellipse, fill=red!20, minimum height=2em}
        }

    \begin{document}
\begin{frame}
\begin{columns}[onlytextwidth]
    \begin{column}{0.48\textwidth}
Given convex\\ 
$MINLP$
\begin{align*}
                    \min z  &           \\
y_1 + y_2 + x_1^2 + x_2^2   &   \leq z  \\
            (x_1-2)^2-x_2   &   \leq 0  \\
                x_1 - 2y_1  &   \geq 0  \\
        x_1-x_2-3(1-y_1)    &   \leq 0  \\
            x_1 - (1-y_1)   &   \geq 0  \\
                    x_2-y_2 &   \leq 0  \\
                    x_1+x_2 &   \leq 3y_1   \\
                    y_1+y_2 &   \leq 1  \\
            0 \leq x_1,x_2, &   \leq 4  \\
                    y_1,y_2 &   \in \{0,1\}
\end{align*}
Choose initial integer solutions $y_1 = y_2 = 1$. Upper bound $U = \infty$.
    \end{column}
    \begin{column}{0.5\textwidth}

\begin{tikzpicture}
% Place nodes
\node [blockH]                  (init)  {Init};
\node [block,below=of init]     (NLP)   {Solve NLP($x^k_I$) or F($x^k_I$)};
\node [block,below=of NLP]      (Bound) {Add linearaziation at $x^k$  to MIP};
\node [block,below=of Bound]    (MIP)   {Solve MIP($x^k$, $U$)};
\node [decision,right=of MIP]   (Infeas){MIP infeasible? -> Exit};
%
\path[line] (init)  edge (NLP)
            (NLP)   edge node {Update U?} (Bound)
%            (Bound) edge (Update)
            (Bound) edge (MIP)
            (MIP)   edge (Infeas)
            (Infeas) |-  node[near start] {No} (NLP);
\end{tikzpicture}
    \end{column}
  \end{columns}
\end{frame}

  %Step 2
  \begin{frame}
  \begin{columns}[onlytextwidth]
    \begin{column}{0.48\textwidth}
Fix $y_1 = y_2 = 1$\\ 
and solve NLP.
  \begin{align*}
               \leq z  \\
1 + 1 + x_1^2 + x_2^2   &   \leq z \\
        (x_1-2)^2-x_2   &   \leq 0 \\
            x_1 - 2     &   \geq 0 \\
\hphantom{_1}
        x_1-x_2-3(1-1)  &   \leq 0 \\
            x_1 - (1-1) &   \geq 0 \\
                x_2-1   &   \leq 0 \\
                x_1+x_2 &   \leq 3\\
                    1+1 &   \leq 1\\
        0 \leq x_1,x_2, &   \leq 4\\
                    1,1 &   \in \{0,1\}
  \end{align*}

Optimal solution $x_1=x_2=2$, (x,y) = (2,2,1,1) is a solution
to our $MINLP$.
    \end{column}
    \begin{column}{0.5\textwidth}
\begin{tikzpicture}
% Place nodes
\node [blockH] (init) {Init};
\node [block, below=of init, node distance=3cm] (NLP) { Solve NLP($x^k_I$) or F($x^k_I$)};
\node [block, below=of NLP] (Bound) { Add linearaziation at $x^k$  to MIP};
\node [block, below=of Bound] (MIP) { Solve MIP($x^k$, $U$) };
\node [decision, right=of MIP] (Infeas) { MIP infeasible? -> Exit };
%
\path [line] (init) -- (NLP);
\path[line] (init)  edge (NLP)
            (NLP)   edge node {Update U?} (Bound)
%            (Bound) edge (Update)
            (Bound) edge (MIP)
            (MIP)   edge (Infeas)
            (Infeas) |-  node[near start] {No} (NLP);
\end{tikzpicture}
    \end{column}
  \end{columns}
  \end{frame}
\end{document}

上面的代码给出:

在此处输入图片描述

相关内容