Math & ScienceUnderbrace with Subarray in Text

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
tho_mi
Posts: 20
Joined: Tue Sep 11, 2012 6:57 pm

Underbrace with Subarray in Text

Post by tho_mi »

Hey,

I have several formulas with underbraces and text where i need line breaks. In order to split the text I use subarrays, but it gives me a lot of errors (although I get a PDF file with the formatting I want).

Code: Select all

\documentclass[mathserif,10pt]{beamer}
\usepackage{lmodern}
\usepackage{amsmath,amssymb}

\begin{document}

\begin{frame}[c]{}
  $
    \underbrace{a}_\text{\begin{subarray}{c}\text{Gross}\end{subarray}}
  $
\end{frame}

\end{document}
Does anyone know why Latex misses several $s?

Thanks in advance

Recommended reading 2024:

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

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

hugovdberg
Posts: 133
Joined: Sat Feb 25, 2012 6:12 pm

Underbrace with Subarray in Text

Post by hugovdberg »

Yes I do know ;) The problem is that subarray as the name says is meant as part of another math environment. However, your subscript is entirely in a \text macro, and so effectively outside math mode. The solution is pretty simple, remove the \text command, and all is fine (output attached as PDF):

Code: Select all

\documentclass[mathserif,10pt]{beamer}
\usepackage{lmodern}
\usepackage{amsmath,amssymb}

\begin{document}

\begin{frame}[c]{}
  $
    \underbrace{a}_{\begin{subarray}{c}\text{Gross}\end{subarray}}
  $
\end{frame}

\end{document}
Attachments
test2.pdf
(23.41 KiB) Downloaded 677 times
Ubuntu 13.10 + Tex Live 2013 + Texmaker / Windows 7 Pro + MikTex 2.9 + TexnicCenter / Android 4.3 + TexPortal + DroidEdit
tho_mi
Posts: 20
Joined: Tue Sep 11, 2012 6:57 pm

Underbrace with Subarray in Text

Post by tho_mi »

Thanks :)

Well, now I have another problem/question (see below code).

Code: Select all

\documentclass[mathserif,10pt]{beamer}
\usepackage{lmodern}
\usepackage{amsmath,amssymb}

\begin{document}

\begin{frame}[c]{}
  %\begin{center}
  $
  \underbrace{GDP}_{\begin{subarray}{c}\text{Gross}\\\text{domestic}\\\text{product}\end{subarray}}
  \quad = \quad \underbrace{C + I + G}_{\begin{subarray}{c}\text{Gross}\\\text{national}\\\text{expenditure}\\GNE\end{subarray}}
  \quad + \quad \underbrace{\left(\underbrace{EX}_{\begin{subarray}{c}\text{All exports,}\\\text{final \& intermediate}\end{subarray}} - \underbrace{IM}_\text{\begin{subarray}{c}\text{All exports,}\\\text{final \& intermediate}\end{subarray}}\right)}_{\begin{subarray}{c}\text{Trade balance}\\TB\end{subarray}}
  $
  %\end{center}
\end{frame}

\end{document}
It gives me eight errors, always "missing $ inserted" and I have no idea why.
hugovdberg
Posts: 133
Joined: Sat Feb 25, 2012 6:12 pm

Underbrace with Subarray in Text

Post by hugovdberg »

First of all, use some new lines and indentation in nested commands such as these. That makes it a lot easier to debug them, both for yourself and when requesting support. Second, an inline MWE helps in getting support too, since someone else doesn't have to download your file first, I often already spot the problem in the browser, and prefer not to switch to a texteditor first ;)

Having said that, I indented your code for you, I think you'll spot the problem yourself soon enough ;) Hint: it's the same problem as before, please take a look at what I posted yesterday for an explanation and the solution.

Code: Select all

\documentclass[mathserif,10pt]{beamer}
\usepackage{lmodern}
\usepackage{amsmath,amssymb}

\begin{document}

%>--- Slide --------------------------------------
\begin{frame}[c]{}
	%\begin{center}
	$
	\underbrace{GDP}_{
		\begin{subarray}{c}
			\text{Gross}\\
			\text{domestic}\\
			\text{product}
		\end{subarray}}
	\quad = \quad \underbrace{C + I + G}_{
		\begin{subarray}{c}
			\text{Gross}\\
			\text{national}\\
			\text{expenditure}\\
			GNE
		\end{subarray}}
	\quad + \quad \underbrace{\left(
		\underbrace{EX}_{
			\begin{subarray}{c}
				\text{All exports,}\\
				\text{final \& intermediate}
			\end{subarray}}
		 - \underbrace{IM}_\text{
		 	\begin{subarray}{c}
		 		\text{All exports,}\\
		 		\text{final \& intermediate}
		 	\end{subarray}
		 	}
		\right)}_{
		 	\begin{subarray}{c}
		 		\text{Trade balance}\\
		 		TB
		 	\end{subarray}}
	$
	%\end{center}
\end{frame}

\end{document}
Ubuntu 13.10 + Tex Live 2013 + Texmaker / Windows 7 Pro + MikTex 2.9 + TexnicCenter / Android 4.3 + TexPortal + DroidEdit
tho_mi
Posts: 20
Joined: Tue Sep 11, 2012 6:57 pm

Re: Underbrace with Subarray in Text

Post by tho_mi »

Usually I use indendations, but in this case I was a bit lazy :|

Aaaah, thanks. I thought that there are not "\text" left... -.-" :roll:
Post Reply