Math & Sciencebeamer | Reducing horizontal Space in Equations

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
latexhelp1
Posts: 141
Joined: Sun Jun 12, 2011 6:30 am

beamer | Reducing horizontal Space in Equations

Post by latexhelp1 »

I am having trouble with the horizontal spacing in equations. I would like to reduce the spacing within the equation so that it looks more natural.

Here's the first one:

Code: Select all

\begin{equation*}
  \int_s^\infty x(t) e^{-bp}\,dp 
\end{equation*}
There is too much space between the integral sign and the x in x(t).

Here's the second one:

Code: Select all

\begin{equation*}
  ln(z) =
  \tikz[baseline]{
    \node[anchor=base](t1){$g$};
  } 
  \tikz[baseline]{
    \node[anchor=base](t2){$(t(b), b)$};
  } 
\end{equation*}
There is too much space between the h and the ln(z) and the h and the (t(b, b)).

For a minimum working example that embeds these 2:

Code: Select all

    \documentclass[professionalfonts, smaller]{beamer} 
    \usetheme{CambridgeUS}
    \usepackage[latin1]{inputenc}
    \usefonttheme{professionalfonts}
    \usepackage{tikz}
    \usepackage{iwona}
    \usepackage{amsmath}
    \usepackage{verbatim}
    \usepackage[T1]{fontenc}
    \usepackage{mathtools}
    \usepackage{fix-cm}
    \usetikzlibrary{arrows,shapes}
    \DeclareMathOperator*{\Max}{Max}
    \newcommand\deriv{^{\mkern4mu\prime}}

    \begin{document}

    \tikzstyle{every picture}+=[remember picture]

    \everymath{\displaystyle}

    \begin{frame}
    \frametitle{Frame Title}

    \tikzstyle{na} = [baseline=-.5ex]

\begin{equation*}
    \int_s^\infty x(t) e^{-bp}\,dp 
     \end{equation*}

    \vspace{0.2cm}

     \begin{equation*}
           ln(z) =
            \tikz[baseline]{
             \node[anchor=base](t1){$g$};
            } 
            \tikz[baseline]{
               \node[anchor=base](t2){$(t(b), b)$};
          } 
    \end{equation*}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

beamer | Reducing horizontal Space in Equations

Post by Stefan Kottwitz »

  1. You could use limits above and below, instead of right of the expression:

    Code: Select all

    \int\limits_s^\infty x(t) e^{-bp}\,dp
  2. Try

    Code: Select all

    \begin{equation*}
         \ln(z) =
          \tikz[overlay, remember picture, baseline=(t1.base)]{
            \node(t1){$g$};
          }
          \tikz[overlay, remember picture, baseline=(t2.base)]{
             \node[anchor=west, right of=t1, node distance=20pt](t2){$(t(b), b)$};
          }
    \end{equation*}
equations.png
equations.png (6 KiB) Viewed 6532 times
Stefan
LaTeX.org admin
latexhelp1
Posts: 141
Joined: Sun Jun 12, 2011 6:30 am

beamer | Reducing horizontal Space in Equations

Post by latexhelp1 »

Stefan,

That works very well. I had to make a slight change though to the code. Otherwise, it was changing the position of the equation on the slide with every time I compiled it.

Code: Select all

        \documentclass[professionalfonts, smaller]{beamer}
        \usetheme{CambridgeUS}
        \usepackage[latin1]{inputenc}
        \usefonttheme{professionalfonts}
        \usepackage{tikz}
        \usepackage{iwona}
        \usepackage{amsmath}
        \usepackage{verbatim}
        \usepackage[T1]{fontenc}
        \usepackage{mathtools}
        \usepackage{fix-cm}
        \usetikzlibrary{arrows,shapes}
        \DeclareMathOperator*{\Max}{Max}
        \newcommand\deriv{^{\mkern4mu\prime}}

        \begin{document}

        \tikzstyle{every picture}+=[remember picture]

        \everymath{\displaystyle}

        \begin{frame}
        \frametitle{Frame Title}

        \tikzstyle{na} = [baseline=-.5ex]

    \begin{equation*}
        \int_s^\infty x(t) e^{-bp}\,dp
         \end{equation*}

        \vspace{0.2cm}

         \begin{equation*}
               ln(z) =
                \tikz[overlay, remember picture, baseline]{
                 \node[anchor=base](t1){$g$};
                }
                \tikz[overlay, remember picture, baseline]{
                   \node[anchor=base, right of=t1, node distance20pt](t2){$(t(b), b)$};
              }
        \end{equation*}
However, when I try that to a different slide where I use the \Max command that you wrote for me earlier, the \Max command ends up not being even with the rest of the equation:

Code: Select all

 \begin{equation*}
            \hspace{-4.5cm} \vspace{2cm}
            \tikz[overlay, remember picture, baseline]{
                 \node[anchor=base](t1){$\Max\limits_x$};
             } \vspace{-2cm}
            \tikz[overlay, remember picture, baseline]{
             \node[anchor=base, right of=t1, node distance=30pt](t2){$L(x) =$};
            } 
            \tikz[overlay, remember picture, baseline]{
                \node[anchor=base, right of=t2, node distance=35pt](t3){$p(x) +$};
            } 
            \tikz[overlay, remember picture, baseline]{
                \node[anchor=base, right of=t3, node distance=29pt](t4){$\gamma d(x)$};
            }
    \end{equation*}
I would very much appreciate any help you can provide in straightening out the Max with respect to the rest of the equation.
Stefan_K wrote:
  1. You could use limits above and below, instead of right of the expression:

    Code: Select all

    \int\limits_s^\infty x(t) e^{-bp}\,dp
  2. Try

    Code: Select all

    \begin{equation*}
         \ln(z) =
          \tikz[overlay, remember picture, baseline=(t1.base)]{
            \node(t1){$g$};
          }
          \tikz[overlay, remember picture, baseline=(t2.base)]{
             \node[anchor=west, right of=t1, node distance=20pt](t2){$(t(b), b)$};
          }
    \end{equation*}
equations.png
Stefan
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

beamer | Reducing horizontal Space in Equations

Post by Stefan Kottwitz »

Specify the base line of the tikzpicture environment to be the baseline of the corresponding node:

Code: Select all

\begin{equation*}
            \hspace{-4.5cm} \vspace{2cm}
            \tikz[overlay, remember picture, baseline=(t1.base)]{
                 \node(t1){$\Max\limits_x$};
             } %\vspace{-2cm}
            \tikz[overlay, remember picture, baseline=(t2.base)]{
             \node[anchor=base, right of=t1, node distance=30pt](t2){$L(x) =$};
            }
            \tikz[overlay, remember picture, baseline=(t3.base))]{
                \node[anchor=base, right of=t2, node distance=35pt](t3){$p(x) +$};
            }
            \tikz[overlay, remember picture, baseline=(t4.base)]{
                \node[anchor=base, right of=t3, node distance=29pt](t4){$\gamma d(x)$};
            }
    \end{equation*}
baselines.png
baselines.png (2.49 KiB) Viewed 6519 times
Stefan
LaTeX.org admin
latexhelp1
Posts: 141
Joined: Sun Jun 12, 2011 6:30 am

beamer | Reducing horizontal Space in Equations

Post by latexhelp1 »

Adding baseline = (t1.base) for each line instead of just baseline fixes the spacing issue. However, every time I compile the file, it shifts the position of the entire equation. So, if I compile it say 40 times, it looks grossly different than when I first compiled it. This problem goes away if it is just baseline.
Stefan_K wrote:Specify the base line of the tikzpicture environment to be the baseline of the corresponding node:

Code: Select all

\begin{equation*}
            \hspace{-4.5cm} \vspace{2cm}
            \tikz[overlay, remember picture, baseline=(t1.base)]{
                 \node(t1){$\Max\limits_x$};
             } %\vspace{-2cm}
            \tikz[overlay, remember picture, baseline=(t2.base)]{
             \node[anchor=base, right of=t1, node distance=30pt](t2){$L(x) =$};
            }
            \tikz[overlay, remember picture, baseline=(t3.base))]{
                \node[anchor=base, right of=t2, node distance=35pt](t3){$p(x) +$};
            }
            \tikz[overlay, remember picture, baseline=(t4.base)]{
                \node[anchor=base, right of=t3, node distance=29pt](t4){$\gamma d(x)$};
            }
    \end{equation*}
baselines.png
Stefan
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

beamer | Reducing horizontal Space in Equations

Post by Stefan Kottwitz »

latexhelp1 wrote:However, every time I compile the file, it shifts the position of the entire equation. So, if I compile it say 40 times, it looks grossly different than when I first compiled it.
You can fix the position of the equation by absolutely positioning the reference node, the first one, referring to the current page node:

Code: Select all

\node(t1) at ([xshift=.4\textwidth, yshift=-.5\textheight]
    current page.north west) {$\Max\limits_x$};
Complete example with your code:

Code: Select all

\documentclass[professionalfonts, smaller]{beamer}
\usetheme{CambridgeUS}
\usepackage[latin1]{inputenc}
\usefonttheme{professionalfonts}
\usepackage{tikz}
\usepackage{iwona}
\usepackage{amsmath}
\usepackage{verbatim}
\usepackage[T1]{fontenc}
\usepackage{mathtools}
\usepackage{fix-cm}
\usetikzlibrary{arrows,shapes}
\DeclareMathOperator*{\Max}{Max}
\newcommand\deriv{^{\mkern4mu\prime}}
\begin{document}
\begin{frame}
    \begin{equation*}
            \hspace{-4.5cm} \vspace{2cm}
            \tikz[overlay, remember picture, baseline=(t1.base)]{
                 \node(t1) at ([xshift=.4\textwidth, yshift=-.5\textheight]
                    current page.north west) {$\Max\limits_x$};
             } %\vspace{-2cm}
            \tikz[overlay, remember picture, baseline=(t2.base)]{
             \node[anchor=base, right of=t1, node distance=30pt](t2){$L(x) =$};
            }
            \tikz[overlay, remember picture, baseline=(t3.base))]{
                \node[anchor=base, right of=t2, node distance=35pt](t3){$p(x) +$};
            }
            \tikz[overlay, remember picture, baseline=(t4.base)]{
                \node[anchor=base, right of=t3, node distance=29pt](t4){$\gamma d(x)$};
            }
    \end{equation*}
\end{frame}
\end{document}
Stefan
LaTeX.org admin
Post Reply