Adding footnote to latex table - latex

Regarding the following latex table, I would like to add footnotes to define the * in the last column. For example, The * refers to Parametric Model, ** semi-parametric and *** non-parametric, and the distance between the table and the footnote is the minimum possible.
\noindent\begin{tblr}{
colspec={#{}l|[white]Xc#{}},
hline{1,Z}={wd=1.2pt},
hline{2}={wd=0.4pt},
cell{2-Z}{2}={mode=imath}
}
Number & Model & Type\\
Model 1 & \text{BC\_WS} = \beta _0 + \beta _1\cdot {\text{M\_WS}} + \epsilon & *\\
Model 2 & \text{BC\_WS} = \beta _0 + f(\text{M\_WS}) + \epsilon & *** \\
Model 3 & \text{BC\_WS} = \beta _0 + \beta _1\cdot W\_WS+ \beta _2\cdot \text{\text{W\_Direction}}+ \beta _3\cdot \text{Temperature} + \beta _4\cdot \text{Pressure} + \epsilon & *\\
Model 4 & \text{BC\_WS} = \beta _0 + f(\text{M\_WS})+ f(\text{W\_Direction})+ f(\text{Temperature}) + f(\text{Pressure}) + \epsilon & *** \\
Model 5 & \text{BC\_WS} =\beta _0 + \beta _1\cdot (\text{M\_WS})+ f(\text{W\_Direction})+ f(\text{Temperature}) + f(\text{Pressure}) + \epsilon & **\\
Model 6 & \text{BC\_WS} = \beta _0 + \beta _1\cdot \text{M\_V}+ \beta _2\cdot \text{M\_V}+ \beta _3\cdot \text{Temperature} + \beta _4\cdot \text{Pressure} + \epsilon & *\\
Model 7 & \text{BC\_WS} = \beta _0 + f(\text{M\_V})+ f(\text{M\_V})+ f(\text{Temperature}) + f(\text{Pressure}) + \epsilon & ***\\
\end{tblr}

Use long tables (longtblr environment) and for table-footnotes use note{} = {table note ....} option.
---
title: "footnotes"
output: pdf_document
header-includes:
- \usepackage{tabularray}
---
## R Markdown
\noindent\begin{longtblr}[
note{} = { * Parametric ** Semi-parametric *** Non-parametric}
]{
colspec={#{}l|[white]Xc#{}},
hline{1,Z}={wd=1.2pt},
hline{2}={wd=0.4pt},
cell{2-Z}{2}={mode=imath}
}
Number & Model & Type\\
Model 1 & \text{BC\_WS} = \beta _0 + \beta _1\cdot {\text{M\_WS}} + \epsilon & *\\
Model 2 & \text{BC\_WS} = \beta _0 + f(\text{M\_WS}) + \epsilon & *** \\
Model 3 & \text{BC\_WS} = \beta _0 + \beta _1\cdot W\_WS+ \beta _2\cdot \text{\text{W\_Direction}}+ \beta _3\cdot \text{Temperature} + \beta _4\cdot \text{Pressure} + \epsilon & *\\
Model 4 & \text{BC\_WS} = \beta _0 + f(\text{M\_WS})+ f(\text{W\_Direction})+ f(\text{Temperature}) + f(\text{Pressure}) + \epsilon & *** \\
Model 5 & \text{BC\_WS} =\beta _0 + \beta _1\cdot (\text{M\_WS})+ f(\text{W\_Direction})+ f(\text{Temperature}) + f(\text{Pressure}) + \epsilon & **\\
Model 6 & \text{BC\_WS} = \beta _0 + \beta _1\cdot \text{M\_V}+ \beta _2\cdot \text{M\_V}+ \beta _3\cdot \text{Temperature} + \beta _4\cdot \text{Pressure} + \epsilon & *\\
Model 7 & \text{BC\_WS} = \beta _0 + f(\text{M\_V})+ f(\text{M\_V})+ f(\text{Temperature}) + f(\text{Pressure}) + \epsilon & ***\\
\end{longtblr}
See the chapter 4 of this tabularray documentation for more a complete example with many more options.

Related

What's the meaning of "double superscript" in overleaf?

I wrote a wrapped equation in overleaf:
\begin{equation}
\begin{aligned}
\y & = \argmin_{\y'} \sum_{i,j}\W_{ij}||\y'_i - \y'_j||_2^2 \\
& = \argmin_{\y'} \sum_{i,j}(\y'_i - \y'_j)^2\W_{ij} \\
& = \argmin_{\y'} \sum_{i,j}(\y'_i^2 + \y'_j^2 - 2\y'_i\y'_j)\W_{ij} \\
& = \argmin_{\y'} \sum_{i,j}\y'_i^2\W_{ij} + \sum_{i,j}\y'_j^2\W_{ij} - 2\sum_{i,j}\y'_i\y'_j\W_{ij} \\ & = \argmin_{\y'} \sum_{i}\y'_i^2D_{ii} + \sum_{j}\y'_j^2D_{jj} - 2\sum_{i,j}\y'_i\y'_j\W_{ij} \\ & = \argmin_{\y'} 2 (\sum_{i}\y'_i^2D_{ii} - \sum_{i,j}\y'_i\y'_j\W_{ij}) \\
& = \argmin_{\y'} 2 {\y'}^\top \L{\y'} \\
\end{aligned}
\end{equation}
The overleaf shows that there are three "double superscript" error in this code, what is that and how can I fix this (although I can compile it successfully)?
I expect to find the solution to this problem.
A double sub-/superscript error occurs when you have more than one sub-/superscript associated with an element. An example is $x^2^2$ which can be interpreted in two ways: ${x^2}^2$ or $x^{2^2}$. Mathematically they mean the same, but from a typesetting point of view they are interpreted differently:
The first - ${x^2}^2$ - sets both exponents in \scriptstyle (so they're the same size) while the second sets the exponents in staggering (reducing) sizes (first one uses \scriptstyle while the second uses \scriptscriptstyle). This difference in typesetting is rather pushed to the user to fix to avoid confusion or misinterpreting what the result should look like. A similar concept holds for subscripts (like $x_2_2$) and combinations of scripts (like `$x_2^2_2$).
What is hidden in your is the use of a prime (like $y'$) which is similar to $y^\prime$:
$x' = x^\prime \neq x\prime$
As such, $y'^2$ is similar to $y^\prime^2$ which is interpreted as a double superscript, causing the error you see.
The way around it is to appropriately group the elements to denote the way you want it represented in output. In your case, this is most likely ${y'}^2$. I've done that below, with some adjustments to other elements:
\documentclass{article}
\usepackage{mathtools}
% https://tex.stackexchange.com/q/5223/5764
\DeclareMathOperator*{\argmax}{arg\,max}
\DeclareMathOperator*{\argmin}{arg\,min}
\DeclarePairedDelimiter{\norm}{\|}{\|}
\newcommand{\y}{\mathcal{Y}}
\newcommand{\W}{\mathcal{W}}
\begin{document}
\begin{equation}
\begin{aligned}
\y & = \argmin_{\y'} \sum_{i, j} \W_{ij} \norm[\big]{ \y'_i - \y'_j }_2^2 \\
& = \argmin_{\y'} \sum_{i, j} \bigl(\y'_i - \y'_j \bigr)^2 \W_{ij} \\
& = \argmin_{\y'} \sum_{i, j} \bigl( {\y'}_i^2 + {\y'}_j^2 - 2 \y'_i \y'_j \bigr) \W_{ij} \\
& = \argmin_{\y'} \sum_{i, j}{\y'}_i^2 \W_{ij} + \sum_{i, j} {\y'}_j^2 \W_{ij} - 2\sum_{i, j} \y'_i \y'_j \W_{ij} \\
& = \argmin_{\y'} \sum_i {\y'}_i^2 D_{ii} + \sum_j {\y'}_j^2 D_{jj} - 2 \sum_{i, j} \y'_i \y'_j \W_{ij} \\
& = \argmin_{\y'} 2 \biggl( \sum_i {\y'}_i^2 D_{ii} - \sum_{i, j} \y'_i \y'_j \W_{ij} \biggr) \\
& = \argmin_{\y'} 2 {\y'}^\top \L \y'
\end{aligned}
\end{equation}
\end{document}

customizing latex table color and adding footnote

Given the following code, I would like to remove the colours and add a third column including *, **, *** to show the grouping of, for example, 2,4 and 7 and... and then in the footnote what each start group mean.
\documentclass{article}
\usepackage{geometry}
\usepackage{xcolor}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{
colspec={l|[white]l},
cell{1}{2}={halign=c},
rows={bg=lightgray},
row{1}={bg=brown!80,fg=white,font=\bfseries},
row{2}={bg=brown!80!black,fg=white},
row{4}={bg=brown!80!black,fg=white},
row{6}={bg=brown!80!green,fg=white},
row{7}={bg=brown!80!black,fg=white},
}
Number & Model \\
\hline[white,wd=1pt]
Model 1 & \(\text{BC\_WS} = \beta _0 + \beta _1\cdot {\text{M\_WS}} + \epsilon\) \\
Model 2 & \(\text{BC\_WS} = \beta _0 + f(\text{M\_WS}) + \epsilon\) \\
Model 3 & \(\text{BC\_WS} = \beta _0 + \beta _1\cdot W\_WS+ \beta _2\cdot \text{\text{W\_Direction}}+ \beta _3\cdot \text{Temperature} + \beta _4\cdot \text{Pressure} + \epsilon\) \\
Model 4 & \(\text{BC\_WS} = \beta _0 + f(\text{M\_WS})+ f(\text{W\_Direction})+ f(\text{Temperature}) + f(\text{Pressure}) + \epsilon\) \\
Model 5 & \(\text{BC\_WS} =\beta _0 + \beta _1\cdot (\text{M\_WS})+ f(\text{W\_Direction})+ f(\text{Temperature}) + f(\text{Pressure}) + \epsilon\) \\
Model 6 & \(\text{BC\_WS} = \beta _0 + \beta _1\cdot M\_U+ \beta _2\cdot \text{M\_V}+ \beta _3\cdot \text{Temperature} + \beta _4\cdot \text{Pressure} + \epsilon\) \\
Model 7 & \(\text{BC\_WS} = \beta _0 + f(M\_U)+ f(\text{M\_V})+ f(\text{Temperature}) + f(\text{Pressure}) + \epsilon\)
\end{tblr}
\end{document}
The output from the code above looks like this:
I tried to remove the, for example, row{2}={bg=brown!80!black,fg=white}, to remove the colouring, but I received the following error:
! Paragraph ended before \environment tblr was complete.
<to be read again>
\par
l.113
I want the output to look like this with footnotes about the stars(header row and first column are aligned centre, the remaining are aligned left):
The error has nothing to do with the row colours, you are missing the amsmath package. Without this package you can't use the \text{...} macro.
\documentclass{article}
\usepackage{geometry}
\usepackage{xcolor}
\usepackage{tabularray}
\usepackage{amsmath}
\UseTblrLibrary{booktabs}
\begin{document}
\noindent\begin{tblr}{
colspec={#{}l|[white]Xc#{}},
hline{1,Z}={wd=1.2pt},
hline{2}={wd=0.4pt},
cell{2-Z}{2}={mode=imath}
}
Number & Model & Type\\
Model 1 & \text{BC\_WS} = \beta _0 + \beta _1\cdot {\text{M\_WS}} + \epsilon & LM*\\
Model 2 & \text{BC\_WS} = \beta _0 + f(\text{M\_WS}) + \epsilon& \\
Model 3 & \text{BC\_WS} = \beta _0 + \beta _1\cdot W\_WS+ \beta _2\cdot \text{\text{W\_Direction}}+ \beta _3\cdot \text{Temperature} + \beta _4\cdot \text{Pressure} + \epsilon & LM*\\
Model 4 & \text{BC\_WS} = \beta _0 + f(\text{M\_WS})+ f(\text{W\_Direction})+ f(\text{Temperature}) + f(\text{Pressure}) + \epsilon &\\
Model 5 & \text{BC\_WS} =\beta _0 + \beta _1\cdot (\text{M\_WS})+ f(\text{W\_Direction})+ f(\text{Temperature}) + f(\text{Pressure}) + \epsilon &\\
Model 6 & \text{BC\_WS} = \beta _0 + \beta _1\cdot M\_U+ \beta _2\cdot \text{M\_V}+ \beta _3\cdot \text{Temperature} + \beta _4\cdot \text{Pressure} + \epsilon & LM*\\
Model 7 & \text{BC\_WS} = \beta _0 + f(M\_U)+ f(\text{M\_V})+ f(\text{Temperature}) + f(\text{Pressure}) + \epsilon&\\
\end{tblr}
\end{document}

How to align math equations even when some variables are missing?

I want the variables and signs aligned in a set of equations.
Desired output:
What I am trying in Mathjax:
\[
\begin{align}
2&x_1 - x_2 &+ 1.5&x_3 &= 8 \\
&x_1 &- 4&x_3 &= -1
\end{align}
\]
What I got:
So, what do I have to do to have the same alignment as in the "desired output" image?
There are a number of ways to achieve this. Below I use an array (with appropriate stretch and spacing), alignat and align coupled with eqparbox for measuring similarly-tagged boxes (this latter approach requires two compilations with every change in the largest element associated with every <tag>):
\documentclass{article}
\usepackage{amsmath,eqparbox}
%\usepackage{xparse}% If you have LaTeX2e < 2020-10-01
% https://tex.stackexchange.com/a/34412/5764
\makeatletter
% \eqmathbox[<tag>][<align>]{<math>}
\NewDocumentCommand{\eqmathbox}{o O{c} m}{%
\IfValueTF{#1}
{\def\eqmathbox###1##2{\eqmakebox[#1][#2]{$##1##2$}}}
{\def\eqmathbox###1##2{\eqmakebox{$##1##2$}}}
\mathpalette\eqmathbox#{#3}
}
\makeatother
\begin{document}
\[
\renewcommand{\arraystretch}{1.2}
\setlength{\arraycolsep}{0pt}
\begin{array}{ r c r c r c r }
2 x_1 & {}-{} & x_2 & {}+{} & 1.5 x_3 & {}={} & 8 \\
x_1 & & & {}-{} & 4 x_3 & {}={} & -7
\end{array}
\]
\begin{alignat*}{4}
2 x_1 & {}-{} & x_2 & {}+{} & 1.5 x_3 = {} && 8 \\
x_1 & & & {}-{} & 4 x_3 = {} && -7
\end{alignat*}
\begin{align*}
\eqmathbox[x1][r]{2 x_1} - \eqmathbox[x2][r]{x_2} + \eqmathbox[x3][r]{1.5 x_3} &= \eqmathbox[c][r]{8} \\
\eqmathbox[x1][r]{ x_1} \phantom{{}-{}} \eqmathbox[x2][r]{} - \eqmathbox[x3][r]{4 x_3} &= \eqmathbox[c][r]{-7}
\end{align*}
\end{document}
All yield similar output:

How can I \label \subsection in \intertext inside flalign? (LATEX)

I have one flalign environment, so columns are aligned same way whole page. I need \subsections inside this flalign, so I used \intertext. And I need \label these \subsections. And thats where I failed. It \label first equation after \subsection but not \subsection itself or error occurs.
Image:
When I tried to use more flalign environments and place subsections between them they were not aligned same way and it looked terible.
Thanks for help.
\begin{flalign}
&\text{Značení: } &&X\sim \text{Exp($\lambda$)} &&
\\
&\text{Parametry: } &&\lambda > 0 &&
\\
&\text{Nosič: } &&X \in (0,\infty) &&
\\
&\text{Hustota: } &&f(x)=
\begin{cases}
\lambda e^{-\lambda x} & x>0
\\
0 & x\leq 0
\end{cases}
\\
&\text{Distribuční funkce: } &&F(x)=
\begin{cases}
1-e^{-\lambda x} & x>0
\\
0 & x\leq 0
\end{cases} &&
\\
&\text{Střední hodnota: } && \E X = \frac{1}{\lambda} &&
\\
&\text{Rozptyl: } && \var X = \frac{1}{\lambda^2} &&
\\
\intertext{\subsection{Weibullovo rozdělení}}\label{priloha:weibdist}
&\text{Značení: } &&X\sim \text{Weib($\alpha$, $\beta$)}&&
\\
&\text{Parametry: } &&\text{$\alpha$, $\beta>0$}&&
\\
&\text{Nosič: } &&X \in \langle 0,\infty)&&
\\
&\text{Hustota: } &&f(x)=
\begin{cases}
\alpha \beta^\alpha x^{\alpha-1} e^{-(\beta x)^\alpha} & x\geq 0
\\
0 & x< 0
\end{cases}&&
\\
&\text{Distribuční funkce: } &&F(x)=
\begin{cases}
1-e^{-(\beta x)^\alpha} & x\geq 0
\\
0 & x< 0
\end{cases}
\\
&\text{Střední hodnota: } &&\E X = \frac{1}{\beta} \Gamma\left(1+\frac{1}{\alpha}\right)
\\
&\text{Rozptyl: } &&\var X = \frac{1}{\beta^2} \left\lbrace\Gamma \left(1+\frac{2}{\alpha}\right)-\left[\Gamma\left(1+\frac{1}{\alpha}\right)\right]^2\right\rbrace
\\
\intertext{\subsection{Gama rozdělení}}\label{priloha:gammadist}
&\text{Značení: } &&X\sim \Gamma(\alpha,\;\beta)&&
\\
&\text{Parametry: } &&\alpha,\; \beta > 0
\\
&\text{Nosič: } &&X \in (0,\infty)
\\
&\text{Hustota: } &&f(x)=
\begin{cases}
\frac{\alpha^\beta}{\Gamma(\beta)}x^{\beta-1}e^{-\alpha x} & x>0
\\
0 & x\leq 0
\end{cases}
\\
&\text{Střední hodnota: } && \E X = \frac{\beta}{\alpha}
\\
&\text{Rozptyl: } && \var X = \frac{\beta}{\alpha^2}
\end{flalign}
From the images you show, I would suggest to use a tabular with a fixed width instead. This will allow you to break for things like subsections:
\documentclass[12pt,fleqn]{article}
\usepackage{amsmath}
\usepackage{array}
\begin{document}
\subsection{First part}
\noindent%
{%
\abovedisplayskip=-\baselineskip
\belowdisplayskip=-.5\baselineskip
\begin{tabular}{#{}p{.3\textwidth}#{}p{.7\textwidth}#{}}
First equation: & \begin{equation} a+b+c=d \end{equation}\\
Second equation: & \begin{equation} a+b+c=d \end{equation}\\
\end{tabular}
}
\subsection{Second part}
\label{sub:1}
\noindent%
{%
\abovedisplayskip=-\baselineskip
\belowdisplayskip=-.5\baselineskip
\begin{tabular}{#{}m{.3\textwidth}#{}m{.7\textwidth}#{}}
Next equation: & \begin{equation} a+b+c+45867+ddlk=d \end{equation}\\
Another equation: & \begin{equation} a+b+c+sdfsdf+565=d \end{equation}\\
\end{tabular}
}
Here alignment is working, but labeling not. Second part is \ref{sub:1}. It referes to 3th equation instead of subsection.
\end{document}

How To Write A Beautiful Brace In Tex

Today I see a beautiful equation:
(Sorry for cannot put the pic directly, I'm new here.)
I don't know how to write it in Tex. I try my best to write like following:
\begin{equation}
\begin{aligned}
r_{t}=\left\{
\begin{array}{crl}
1+\dfrac{\bar{R}_{Q}(t+\Delta t)-R_{Q}(t)}{2\Delta t/T_{single}}\; &+0\qquad &if\,\bar{R}_{Q}(t+\Delta t)>0,\\
0 \; &-P\qquad &if\,R_{Q}(t)\neq 0\wedge R_{Q}(t+\Delta t)=0,\\
0\; &+0\qquad &if\,R_{Q}(t)=0
\label{rforProtRwd}
\end{array}
\right.
\\
\underbrace{\hspace{10em}}_{=:r_{t}^{(1)}}\hspace{1em}\underbrace{\hspace{2em}}_{=:r_{t}^{(2)}}\hspace{17em}
\end{aligned}
\end{equation}
It is obviously that the underbrace is a little far from the main part of the equation. And actually both the method I write and the result are ugle.
So I wonder if there are some better ways to write it.
Hoping someone can help.
Here is an accurate \underbrace that matches the content within a cases environment.
\documentclass{article}
\usepackage{mathtools,eqparbox}
\begin{document}
\begin{align}
r_t = \begin{cases}
\eqmakebox[LHS]{$1 + \dfrac{\bar{R}_Q(t + \Delta t) - R_Q(t)}{2 \Delta t / T_{\text{single}}}$}
+ 0 & \text{if $\bar{R}_Q(t + \Delta t) > 0$}, \\
\eqmakebox[LHS]{$0$}
- P & \text{if $R_Q(t) \neq 0 \wedge R_Q(t + \Delta t) = 0$}, \\
\eqmakebox[LHS]{$0$}
+ 0 & \text{if $R_Q(t) = 0$}
\end{cases} \\[-1.2\normalbaselineskip]
\underbrace{\eqmakebox[LHS]{\mathstrut}}_{=:r_t^{(1)}}
\underbrace{\mathstrut\phantom{{} - P}}_{\mathclap{=:r_t^{(2)}}}
\quad\phantom{\text{if $R_Q(t) \neq 0 \wedge R_Q(t + \Delta t) = 0$},} \nonumber
\end{align}
\end{document}

Resources