Math & Sciencebeamer | Align Equation with Text and Box around Variable

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

beamer | Align Equation with Text and Box around Variable

Post by latexhelp1 »

I have two questions about a beamer slide I'm trying to make with an equation and corresponding text.

First, how do I left align the equation with the text? I'm using \hspace{} and adjusting it with trial and error. Is there a better approach?

Second, how do I place a box -- preferably red -- around a variable in the equation? For example, in the following equation, how would I place a box around the gamma?

Code: Select all

\documentclass[professionalfont]{beamer}
\mode<presentation>
\usetheme{CambridgeUS}
\useoutertheme{miniframes}
\usepackage{amsfonts}

\beamertemplatenavigationsymbolsempty

\begin{document}

\section{Section 1}
\subsection{}

\frame
{
\frametitle{Slide Title}
\begin{equation*}
\hspace{-3.9cm} y_{icb} = \gamma_c + \mu_b + \eta_{t} + \theta_{s(c)} b + \rho Z_c b + X_{icb}\delta + \varepsilon_{icb} 
\end{equation*}

\vspace{0.4cm}
\textbf{Fixed effects:} county ($\gamma_c$), birth cohort ($\mu_b$), year recorded ($\eta_{t}$)

\vspace{0.4cm}
\textbf{Linear time trends:} state ($\theta_{s(c)} b$) and county characteristics ($Z_c b$)
}

\end{document}
I would very much appreciate any help that you can provide.
Last edited by latexhelp1 on Mon Feb 06, 2012 10:53 pm, edited 1 time in total.

Recommended reading 2024:

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

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

User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

beamer | Align Equation with Text and Box around Variable

Post by Stefan Kottwitz »

latexhelp1 wrote:First, how do I left align the equation with the text?
Use the fleqn class option for flushed left equations, and set \mathindent to 0pt.

Code: Select all

\documentclass[professionalfont,fleqn]{beamer}
\setlength{\mathindent}{0pt}
latexhelp1 wrote:Second, how do I place a box -- preferably red -- around a variable in the equation?
Use boxed of amsmath. Here's a redefinition with color, you could place that in your preamble:

Code: Select all

\newcommand*{\boxedcolor}{red}
\makeatletter
\renewcommand{\boxed}[1]{\textcolor{\boxedcolor}{%
  \fbox{\normalcolor\m@th$\displaystyle#1$}}}
\makeatother
And in the text:

Code: Select all

\begin{equation*}
  y_{icb} = \boxed{\gamma_c} + \mu_b + \eta_{t} + \dots
\end{equation*
slide.png
slide.png (10.27 KiB) Viewed 22273 times
Stefan

PS: for solved topics, please click the solution post solved button, not the button in the first post (the question). The reason is, that the new feature sets a link from the checkmark to the solution. Could be good for longer threads with many posts.
LaTeX.org admin
latexhelp1
Posts: 141
Joined: Sun Jun 12, 2011 6:30 am

beamer | Align Equation with Text and Box around Variable

Post by latexhelp1 »

This works incredibly well! May I please ask a follow up question?

Suppose I would like to do 2 overlays? The first has the box around gamma. The second has the box around theta. Also, I'd like for the first overlay to not have the line, "Linear time trends." That would change the spacing of where the equation is vertically and also where the "Fixed effects" line appears vertically. It would make it lower without the line "Linear time trends" Is is possible to set the first overlay such that the equation would appear in the same spot vertically in the two overlays?

Thank you so much for your help!
Stefan_K wrote:
latexhelp1 wrote:
latexhelp1 wrote:Second, how do I place a box -- preferably red -- around a variable in the equation?
Use boxed of amsmath. Here's a redefinition with color, you could place that in your preamble:

Code: Select all

\newcommand*{\boxedcolor}{red}
\makeatletter
\renewcommand{\boxed}[1]{\textcolor{\boxedcolor}{%
  \fbox{\normalcolor\m@th$\displaystyle#1$}}}
\makeatother
And in the text:

Code: Select all

\begin{equation*}
  y_{icb} = \boxed{\gamma_c} + \mu_b + \eta_{t} + \dots
\end{equation*
slide.png
Stefan
latexhelp1
Posts: 141
Joined: Sun Jun 12, 2011 6:30 am

beamer | Align Equation with Text and Box around Variable

Post by latexhelp1 »

Could I use this command, \boxed, to make a similar box in a table?
Stefan_K wrote: Use boxed of amsmath. Here's a redefinition with color, you could place that in your preamble:

Code: Select all

\newcommand*{\boxedcolor}{red}
\makeatletter
\renewcommand{\boxed}[1]{\textcolor{\boxedcolor}{%
  \fbox{\normalcolor\m@th$\displaystyle#1$}}}
\makeatother
And in the text:

Code: Select all

\begin{equation*}
  y_{icb} = \boxed{\gamma_c} + \mu_b + \eta_{t} + \dots
\end{equation*
User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

beamer | Align Equation with Text and Box around Variable

Post by Stefan Kottwitz »

latexhelp1 wrote:Could I use this command, \boxed, to make a similar box in a table?
Sure, for math content. For text content, you should define a different macro, which could be done similarly, just remove the math code \m@th$\displaystyle...$ from the definition.

Stefan
LaTeX.org admin
latexhelp1
Posts: 141
Joined: Sun Jun 12, 2011 6:30 am

beamer | Align Equation with Text and Box around Variable

Post by latexhelp1 »

Thank you! And if I may please follow up on my earlier question:

Suppose I would like to do 2 overlays. The first overlay has the box around gamma. The second overlay has the box around theta. Also, I'd like for the first overlay to not have the line, "Linear time trends." That would change the spacing of where the equation appears vertically on the slide and also where the "Fixed effects" line appears vertically on the slide. It would make it lower without the line "Linear time trends" Is it possible to set the first overlay such that the equation would appear in the exact same spot vertically in the two overlays?
Stefan_K wrote:
latexhelp1 wrote:Could I use this command, \boxed, to make a similar box in a table?
Sure, for math content. For text content, you should define a different macro, which could be done similarly, just remove the math code \m@th$\displaystyle...$ from the definition.

Stefan
User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

Re: beamer | Align Equation with Text and Box around Variabl

Post by Stefan Kottwitz »

I noticed the other question. It's just not good to mix topics and threads (who reads the last question about overlays, at the end of this answered equation alignmenr topic?). I just don't work much with overlays. Perhaps somebody else may answer. If not, you could post an update with some information, so the post is pushed up, becoming good visible again - after some time.

Any marking topic as solved helps in this regard, as potential answerers often filter out solved topic with the menu on the right, so we see unsolved topics better, such as the overlay topic.

Stefan
LaTeX.org admin
latexhelp1
Posts: 141
Joined: Sun Jun 12, 2011 6:30 am

beamer | Align Equation with Text and Box around Variable

Post by latexhelp1 »

Hi Stefan:

Is there another way of doing the same thing:

Code: Select all

\documentclass[professionalfont,fleqn]{beamer}
    \setlength{\mathindent}{0pt}
I ask because I have another part of my beamer code that is not compatible with \setlength{\mathindent}{0pt}

My original concern was to ensure that the equations are left-aligned.

Thank you!
User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

beamer | Align Equation with Text and Box around Variable

Post by Stefan Kottwitz »

You could use \setlength{\mathindent}{0pt} with in a group (such as within curly braces) or within an environment, to limit the effect.

A different way would be using flalign or similar of amsmath, adding a & at the right for pushing to the left.

Stefan
LaTeX.org admin
latexhelp1
Posts: 141
Joined: Sun Jun 12, 2011 6:30 am

beamer | Align Equation with Text and Box around Variable

Post by latexhelp1 »

Thank you for getting back to me! I don't quite understand what you mean, however. Could you please show me a quick example? Do you mean to do this with the each equation within the slide rather than in the preamble?
Stefan_K wrote:You could use \setlength{\mathindent}{0pt} with in a group (such as within curly braces) or within an environment, to limit the effect.

A different way would be using flalign or similar of amsmath, adding a & at the right for pushing to the left.

Stefan
Post Reply