Showing entries of a vector one after another - latex

Overflow Community! I'm working on a Latex Beamer - Document and I cant think of a nice looking solution for what I am planning to do.
So I have a vector, which entries I want to show one after another. But the right bracket is missing in the first steps when I'm using \pause in my equation, which looks quite ugly. So what I want is both brackets to be visible, while the vectors entries are not. Do you guys have a solution for this?
\documentclass[mathserif, 10pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,bm,amsthm,graphicx,skmath}
\begin{document}
\begin{frame}
\frametitle{Function $g$}
\[
g(x)=\begin{pmatrix}
g_1(x)\\ \vdots \\ g_n(x) \\ g_{n+1}(x) \\ \vdots \\ g_{2n}(x) \\ g_{2n+1}(x)\\ \vdots \\ g_{3n}(x)
\end{pmatrix}
\pause = \begin{pmatrix}
x_1^2 + x_{n+1}^2 - 1 \\ \vdots \\ x_n^2 + x_{2n}^2 - 1\\ \pause -x_{2n+1}\\ \vdots \\ -x_{3n} \\ \pause x_{2n+1}-L \\ \vdots \\x_{3n}-L
\end{pmatrix}
\]
\end{frame}
\end{document}

\pause is a very crude command, for more fine control you can use commands like \visible<...>{...}.
Please note that you don't need graphicx, amsmath or amsthm with beamer and that the mathserif option is obsolete. This should have caused a warning with a detailed description how this option should be replaced, please don't ignore such warnings.
\documentclass[10pt]{beamer}
\usepackage[utf8]{inputenc}
\usefonttheme[onlymath]{serif}
\usepackage{amsmath,bm,amsthm,
%graphicx,
skmath}
\begin{document}
\begin{frame}
\frametitle{Function $g$}
\[
g(x)=\begin{pmatrix}
g_1(x)\\ \vdots \\ g_n(x) \\ g_{n+1}(x) \\ \vdots \\ g_{2n}(x) \\ g_{2n+1}(x)\\ \vdots \\ g_{3n}(x)
\end{pmatrix}
\visible<2->{ = \begin{pmatrix}
x_1^2 + x_{n+1}^2 - 1 \\ \vdots \\ x_n^2 + x_{2n}^2 - 1\\ \visible<3->{ -x_{2n+1}}\\ \visible<3->{\vdots} \\ \visible<3->{-x_{3n}} \\ \visible<4->{x_{2n+1}-L} \\ \visible<4->{\vdots} \\\visible<4->{x_{3n}-L}
\end{pmatrix}}
\]
\end{frame}
\end{document}

You'll want Beamer's \uncover command, which hides its argument but still makes it take up space:
\[
g(x)=\begin{pmatrix}
g_1(x)\\ \vdots \\ g_n(x) \\ g_{n+1}(x) \\ \vdots \\ g_{2n}(x) \\ g_{2n+1}(x)\\ \vdots \\ g_{3n}(x)
\end{pmatrix}
\pause = \begin{pmatrix}
x_1^2 + x_{n+1}^2 - 1 \\ \vdots \\ x_n^2 + x_{2n}^2 - 1\\ \uncover<3->{-x_{2n+1} \\ \vdots \\ -x_{3n}} \\ \uncover<4->{x_{2n+1}-L \\ \vdots \\x_{3n}-L}
\end{pmatrix}
\]
The bit in the angle brackets (e.g. <3->) indicates that the argument should be uncovered (visible) on frames 3 onwards.
You can also use \visible instead, the difference being:
The \visible command does nearly the same as \uncover. However one difference occurs if the command \setbeamercovered{transparent} has been used to make covered text “transparent” instead, \visible still makes the text completely “invisible” on non-specified slides.

Related

How to fit a Latex table to a given document size?

I tried a lot of things to fit the table to the given size of the document. Unfortunately it did not work without destroying the format.
\documentclass[10pt,a4paper,twocolumn]{article}
\usepackage[top=30pt,bottom=30pt,left=48pt,right=120pt]{geometry}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage[latin1]{inputenc}
\begin{document}
\begin{table}[!htbp] \centering
\begin{tabular} {#{\extracolsep{1pt}}lcc}
\\[-1.8ex]\hline
& \multicolumn{2}{c}{\textit{First Stage Regression}} \
\cr \cline{2-3}
\hline \\[-1.8ex]
\\[-1.8ex] & \multicolumn{1}{c}{ \% foreign born
while in college} & \multicolumn{1}{c}{\% foreign born
while in high
school} \\
\\[-1.8ex] & (1) & (2) \\
\hline \\[-1.8ex]
1960 Distribution
of Immigrants across States & 3.613e+07$^{***}$ & 1.204e+07 $^{***}$ \\
& (8.26e+04) & (2.74e+04) \\
\hline \\[-1.8ex]
Observations & 3,588,372 & 3,588,372 \\
$R^2$ & 0.051 & 0.051 \\
Adjusted $R^2$ & 0.051 & 0.051 \\
Residual Std. Error & 26.649(df = 3588371) & 8.834(df = 3588371) \\
F Statistic & 191184.297$^{***}$ (df = 1.0; 3588371.0) & 193328.460$^{***}$ (df = 1.0; 3588371.0) \\
\hline
\hline \\[-1.8ex]
\textit{Note:} & \multicolumn{2}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\
\end{tabular}
\end{table}
\end{document}
Does anyone have an idea? Thanks
I suggest to use a table* environment so that your table will span over both columns.
You can safe some room by making very long cells into multi-line cells. The tabularray package makes this easy.
Are you 100% sure that your document is really encoded in latin1? That sounds very usual this millennium...
You should load the hyperref package after the other packages.
\documentclass[10pt,a4paper,twocolumn]{article}
\usepackage[top=30pt,bottom=30pt,left=48pt,right=120pt]{geometry}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{tabularray}
\usepackage{hyperref}
\begin{document}
\begin{table*}
\begin{tblr}{
colspec={X[l]X[c]X[c]},
}
\hline
& \SetCell[c=2]{} \textit{First Stage Regression} & \\
\cline{2-3}
& \% foreign born while in college (1) & \% foreign born while in high school (2)\\
\hline
\SetCell[r=2]{} 1960 Distribution of Immigrants across States & 3.613e+07$^{***}$ & 1.204e+07$^{***}$ \\
& (8.26e+04) & (2.74e+04) \\
\hline
Observations & 3,588,372 & 3,588,372 \\
$R^2$ & 0.051 & 0.051 \\
Adjusted $R^2$ & 0.051 & 0.051 \\
Residual Std. Error & 26.649(df = 3588371) & 8.834(df = 3588371) \\
F Statistic & 191184.297$^{***}$ (df = 1.0; 3588371.0) & 193328.460$^{***}$ (df = 1.0; 3588371.0) \\
\hline
\hline
\textit{Note:} & \SetCell[c=2]{r} $^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01 \\
\end{tblr}
\end{table*}
\end{document}
Just add the \resizebox parameter before tabular and don't forget to add the brackets before and after the tabular. You can put it in different ways, such as \resizebox{\textwidth}{!}, \resizebox{0.5\textwidth}{!}, \resizebox{3cm}{!}, ...
\documentclass[10pt,a4paper,twocolumn]{article}
\usepackage[top=30pt,bottom=30pt,left=48pt,right=120pt]{geometry}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage[latin1]{inputenc}
\begin{document}
\begin{table}[!htbp] \centering
\resizebox{\textwidth}{!}{
\begin{tabular} {#{\extracolsep{1pt}}lcc}
\\[-1.8ex]\hline
& \multicolumn{2}{c}{\textit{First Stage Regression}} \
\cr \cline{2-3}
\hline \\[-1.8ex]
\\[-1.8ex] & \multicolumn{1}{c}{ \% foreign born
while in college} & \multicolumn{1}{c}{\% foreign born
while in high
school} \\
\\[-1.8ex] & (1) & (2) \\
\hline \\[-1.8ex]
1960 Distribution
of Immigrants across States & 3.613e+07$^{***}$ & 1.204e+07 $^{***}$ \\
& (8.26e+04) & (2.74e+04) \\
\hline \\[-1.8ex]
Observations & 3,588,372 & 3,588,372 \\
$R^2$ & 0.051 & 0.051 \\
Adjusted $R^2$ & 0.051 & 0.051 \\
Residual Std. Error & 26.649(df = 3588371) & 8.834(df = 3588371) \\
F Statistic & 191184.297$^{***}$ (df = 1.0; 3588371.0) & 193328.460$^{***}$ (df = 1.0; 3588371.0) \\
\hline
\hline \\[-1.8ex]
\textit{Note:} & \multicolumn{2}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\
\end{tabular}
}
\end{table}
\end{document}

Overfull \hbox and Package array Errors. Latex tabular

I am getting trouble to fit my table - tabular to the paragraph width.
This is the error:
Overfull \hbox (341.06795pt too wide) in paragraph at lines 391--411
Package array Error: Illegal pream-token (M): `c' used.
Package array Error: Illegal pream-token (4cm): `c' used
I have been trying one thousand things and nothing seems to work.
I am using this template from Overleaf, where you can find the document class.
This is my code.
\documentclass{JASSS}
\usepackage{amsmath,systeme}
\usepackage{tabularx,colortbl}
\usepackage{booktabs}
\title{XXXXX}
\reviewcopy{true}
\author[1]{}
\affil[1]{}
\email{XX}
\usepackage{natbib}
\setcitestyle{authoryear,round,aysep={}}
\begin{document}
\maketitle
\begin{abstract}
Bla bla
\end{abstract}
\section{xxxx}
\begin{table}[h!]
\centering
\begin{tabular}{ |M{4cm}||M{4cm}|M{4cm}|M{4cm}|}
% \begin{tabular}{|c|c|c|c|}
\cline{2-4}
\multicolumn{1}{c|}{} & \multicolumn{3}{c|}{Initial value parameter combinations ($t_0=1932$)} \\
\hline
Scenarios from 2020 & $\phi_{B}=\phi_{C}=0.05$ and 1932 electoral results & $\phi_{B}=0.05, \phi_{C}=0.055$ and 1932 electoral results & $\phi_{B}=\phi_{C}=0.05$ and electoral tie \\
\hline
$\phi_{D}=\phi_{E}=0.01$, $\gamma_{B}=\gamma_{C}=\gamma_{D}=\gamma_{E}=0.01$ & S0000 & S0100 & S1000 \\
\hline
\rowcolor{blue!20}
$\phi_{D}=0.015,\phi_{E}=0.01$, $\gamma_{B}=\gamma_{C}=\gamma_{D}=\gamma_{E}=0.01$ & S0001 & S0101 & S1001 \\
\hline
\rowcolor{red!20}
$\phi_{D}=0.01,\phi_{E}=0.015$, $\gamma_{B}=\gamma_{C}=\gamma_{D}=\gamma_{E}=0.01$ & S0010 & S0110 & S1010 \\
\hline
\rowcolor{yellow!20}
$\phi_{D}=0.01,\phi_{E}=0.01$, $\gamma_{B}=\gamma_{C}=\gamma_{D}=\gamma_{E}=0.015$ & S0011 & S0111 & S1011 \\
\hline
\end{tabular}
\bibliographystyle{jasss}
\bibliography{references}
\end{document}
The M column type is not defined by default. If you want to use it, you have to somehow define it. I don't know what you indent it to do, but here some dummy code:
\documentclass{JASSS}
\usepackage{array}
\usepackage{amsmath,systeme}
\usepackage{tabularx,colortbl}
\usepackage{booktabs}
\newcolumntype{M}[1]{p{#1}}
\begin{document}
\begin{table}[h!]
\centering
\begin{tabular}{ |M{4cm}||M{4cm}|M{4cm}|M{4cm}|}
% \begin{tabular}{|c|c|c|c|}
\cline{2-4}
\multicolumn{1}{c|}{} & \multicolumn{3}{c|}{Initial value parameter combinations ($t_0=1932$)} \\
\hline
Scenarios from 2020 & $\phi_{B}=\phi_{C}=0.05$ and 1932 electoral results & $\phi_{B}=0.05, \phi_{C}=0.055$ and 1932 electoral results & $\phi_{B}=\phi_{C}=0.05$ and electoral tie \\
\hline
$\phi_{D}=\phi_{E}=0.01$, $\gamma_{B}=\gamma_{C}=\gamma_{D}=\gamma_{E}=0.01$ & S0000 & S0100 & S1000 \\
\hline
\rowcolor{blue!20}
$\phi_{D}=0.015,\phi_{E}=0.01$, $\gamma_{B}=\gamma_{C}=\gamma_{D}=\gamma_{E}=0.01$ & S0001 & S0101 & S1001 \\
\hline
\rowcolor{red!20}
$\phi_{D}=0.01,\phi_{E}=0.015$, $\gamma_{B}=\gamma_{C}=\gamma_{D}=\gamma_{E}=0.01$ & S0010 & S0110 & S1010 \\
\hline
\rowcolor{yellow!20}
$\phi_{D}=0.01,\phi_{E}=0.01$, $\gamma_{B}=\gamma_{C}=\gamma_{D}=\gamma_{E}=0.015$ & S0011 & S0111 & S1011 \\
\hline
\end{tabular}
\end{table}
\end{document}

Long equation spread across the whole page in two column format

I use the strip environment for a long equation in a two-column page format, but the equation number appears at the edge of the first column and not after the equation ends.
\begin{strip}
\begin{equation}
f_{k+i,j} \left(
\bar{A}^{k+i+1}\hat{x}_{-1} +
\bar{A}^{i+1}\bar{B}_k \begin{bmatrix} \Tilde{y}_0 \\ \vdots \\ \Tilde{y}_{k-1} \end{bmatrix} +
\bar{B}_{i+1} \left(
\begin{bmatrix} {y}_k \\ CA\hat{x}_k \\ \vdots \\ CA^i\hat{x}_k \end{bmatrix}
+
\begin{bmatrix} M_s\delta_k \\ M_s\delta_{k+1} \\ \vdots \\ M_s\delta_{k+i} \end{bmatrix} \right) \right) \leq h_{k+i,j}
- \sqrt{f_{k+i,j}\Sigma_{\zeta_i}f_{k+i,j}^T}\Phi^{-1}\left(1 - \frac{\alpha}{s_{k+i}}\right)
- \max_{\eta \in \Gamma} f_{k+i,j}\bar{A}^{k+i+1}\eta
\end{equation}
\end{strip}

How can somene create two tables side by side in beamer?

How can somene create two tables side by side in beamer? I use the following to insert one table
\begin{table}
\begin{tabular}{l | c | c | c | c | c}
Model & intercept & X & Y & Adjusted $R^2$ & \\
\hline \hline
Coeff & 2.229 & -0.274 & 1.221 & 38\%\\
t-value & 3.404 & -0.49 & 3.907 \\
GMM-t & 2.542 & -0.444 & 3.814\\
\end{tabular}
\end{table}
which command should I use to have two tables side by side like the aforementioned table?
If your tables are narrow enough to fit side by side, you can simply place them next to each other like you would do for any normal letter.
\documentclass{beamer}
\begin{document}
\begin{frame}
\begin{table}
\begin{tabular}{l | c | c | }
Model & intercept & X \\
\hline \hline
Coeff & 2.229 & -0.274 \\
t-value & 3.404 & -0.49\\
GMM-t & 2.542 & -0.444 \\
\end{tabular}
\hfill
\begin{tabular}{l | c | c | }
Model & intercept & X \\
\hline \hline
Coeff & 2.229 & -0.274 \\
t-value & 3.404 & -0.49\\
GMM-t & 2.542 & -0.444 \\
\end{tabular}
\end{table}
\end{frame}
\end{document}
As suggested by this blog, you can try columns environment. For example, with code like
\begin{frame}{Example}
\begin{columns}
\begin{column}{0.3\textwidth}
\begin{table}
\begin{tabular}{c|c|c}
sid & bid & day \\ \hline \hline
22 & 101 & 10/10/96 \\
58 & 103 & 11/12/96 \\
\end{tabular}
\caption{reserves}
\end{table}
\end{column}
\begin{column}{0.3\textwidth}
\begin{table}
\begin{tabular}{c|c|c|c}
sid & sname & rating & age \\ \hline \hline
22 & dustin & 7 & 45.0 \\
31 & lubber & 8 & 55.5 \\
58 & rusty & 10 & 35.0 \\
\end{tabular}
\caption{Sailors}
\end{table}
\end{column}
\end{columns}
\end{frame}
You can get something like below (ignoring the background image)

Equation error in Latex table

I'd like to create a table with two parameters and the corresponding equation.
Somehow Latex gives me the error:
'! Missing $ inserted.'
and I don't know what that means...
\begin{table}[H]
\centering
\caption{XXX}
\label{tab:XXX}
\begin{adjustbox}{max width=\textwidth}
\begin{tabular}{c c}
\hline\hline
\vspace{0.25cm}
Parameter & Mathematical Equation \\ \hline
\vspace{0.25cm}
Standard Deviation & \sigma=\sqrt{\frac{\sum(X-\mu)$^2$}{N}} \\
\vspace{0.25cm}
Variance & \sigma^2=\frac{\sum(X-\mu)$^2$}}{N} \\
\\ \hline
\end{tabular}
\end{adjustbox}
\end{table}
In TeX, $ signs enclose inline math code (see here). Your example already uses it around ^2. However, you also use other macros that are only valid inside a math environment, such as e.g. \sigma. Hence, you should surround all macros that require math mode with $ signs:
\begin{table}[H]
\centering
\caption{XXX}
\label{tab:XXX}
\begin{adjustbox}{max width=\textwidth}
\begin{tabular}{c c}
\hline\hline
\vspace{0.25cm}
Parameter & Mathematical Equation \\ \hline
\vspace{0.25cm}
Standard Deviation & $\sigma=\sqrt{\frac{\sum(X-\mu)^2}{N}}$ \\
\vspace{0.25cm}
Variance & $\sigma^2=\frac{\sum(X-\mu)^2}{N}$ \\
\\ \hline
\end{tabular}
\end{adjustbox}
\end{table}
If you prefer not to mix TeX and LaTeX commands, consider using \(...\) instead of $...$.

Resources