how to write inline matrix in Latex - latex

\begin{pmatrix} 2 \\ 4 \\ -2 \end{pmatrix}
This is 3*1 vector matrix and i want to write another matrix or x and y s beside that one.
Is there any method to write matrix inline ?

Are you using in-line delimiters around the math? E.g.,
$\begin{pmatrix} 2 \\ 4 \\ -2 \end{pmatrix}$
If you put another matrix inside these delimiters, they will be put in-line next to it. For instance, see this live example:
<script>
MathJax = {
tex: {inlineMath: [['$','$']]}
}
</script>
<script src="https://cdn.jsdelivr.net/npm/mathjax#3/es5/tex-chtml.js" id="MathJax-script"></script>
This math is in line, $
\begin{pmatrix}
a & b & c \\
d & e & f \\
g & h & i
\end{pmatrix}
\begin{pmatrix} 2\\ 4\\ -2 \end{pmatrix}
$, with text following it.

Simply put your code inside two dollar signs ($) and it's done.
$ \begin{pmatrix} 2 \\ 4 \\ -2 \end{pmatrix} $
Note that if you put double dollar signs ($$) it will write the matrix in a new line and then continues the rest of the sentence in the line after that.
$$ \begin{pmatrix} 2 \\ 4 \\ -2 \end{pmatrix} $$

Related

Stata - Esttab to Latex Decimal Alignment

I am trying to output a LaTex file using Stata's esttab command. I cannot get the decimals to align, nor can I get the nice formatting from the "booktabs" option to work. I also would like to increase the width of the columns. I have been tinkering with this for hours and have had no luck. Below is my Stata code and the LaTex code that I am running through Overleaf. Any help would be greatly appreciated!
Here is my Stata code:
#delimit ;
esttab r1 r2 r3 r4 using "C:\Users\user\Dropbox\Private
Code\Code\STATA\latex\table1.tex", replace
b(3) nomtitle label star(* 0.10 ** 0.05 *** 0.01)
booktabs alignment(D{.}{.}{-1})
title(Placeholder)
s(N DAY FFE FIRM_QUARTER r2_a,
fmt(%9.0fc 0 0 0 3)
label("Observations" "Day FE" "Firm FE" "Firm-Quarter FE" "Adj. R-Sq{\super 2}"))
compress nocons;
Here is the LaTex code it spits out:
\begin{table}[htbp]\centering
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{Placeholder}
\begin{tabular}{l*{4}{D{.}{.}{-1}}}
\toprule
&\multicolumn{1}{c}{(1)} &\multicolumn{1}{c}{(2)} &\multicolumn{1}
{c}{(3)} &\multicolumn{1}{c}{(4)} \\
\midrule
VAR1 & 0.007\sym{***}& 0.007\sym{***}& 0.006\sym{***}& 0.007\sym{***}\\
& (8.55) & (7.82) & (7.67) & (8.54) \\
\addlinespace
VAR2 & 0.132\sym{***}& 0.131\sym{***}& 0.131\sym{***}& 0.132\sym{***}\\
& (20.35) & (20.15) & (20.15) & (20.35) \\
\midrule
Observations &1,315,077 &1,315,077 &1,315,077 &1,315,077
\\
Day FE & No & Yes & Yes & No \\
Firm FE & Yes & No & Yes & No \\
Firm-Quarter FE & No & No & No & Yes \\
Adj. R-Sq{\super 2}& 0.045 & 0.027 & 0.046 & 0.044
\\
\bottomrule
\multicolumn{5}{l}{\footnotesize \textit{t} statistics in parentheses}\\
\multicolumn{5}{l}{\footnotesize \sym{*} \(p<0.10\), \sym{**} \(p<0.05\), \sym{***} \(
p<0.01\)}\\
\end{tabular}
\end{table}
Since you haven't provided the full code, I can't see what would your output be. When I add \documentclass{article} with missing packages in a preamble, I get very wide table which does not fit a page. Also, I don't know whether the code is automatically generated or created/altered by you.
Assuming the latter, I would do the following. Since you add footnotes in the table, I would enclose tabular within threeparttable, which splits the area for table into three parts: top for captions, middle for a table definition e.g. tabular, and bottom part for footnotes. It also adds a convenient macro \tnote{}.
Secondly, dcolumn causes big numbers to be pushed way too much to the left. You should let dcolumn suppress their alignment. I personally don't know how, although I assume there is a way.
I prefer siunitx for formatting numbers in tables. However siunitx needs a bit more work. It automatically parses numbers in cells and any non-number content generates errors. Therefore, non-numbers need to be enclosed within {...} which instructs siunitx to leave the content intact. It also forces numbers not to be formatted, aligned etc., which is what I did for the big numbers you have in the table. There's also option to format thousands and millions with any separator of your choice. For instance you could use one of the macros: \,, :, or \; for thin, mid or thick space, respectively instead of ,.
Below is my suggestion for your table based on siunitx and threeparttable, so you can compare it with your approach.
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{threeparttable}
\newcommand\super[1]{\textsuperscript{#1}}
\sisetup{
group-separator={,},
table-format=1.3,
table-align-text-after = false,
}
\begin{document}
\begin{table}[htbp]
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\centering
\begin{threeparttable}
\caption{Placeholder}
\begin{tabular}{l *{4}{S}}
\toprule
& \multicolumn{1}{c}{(1)}
& \multicolumn{1}{c}{(2)}
& \multicolumn{1}{c}{(3)}
& \multicolumn{1}{c}{(4)} \\
\midrule
{VAR1} & 0.007\tnote{***} & 0.007\tnote{***} & 0.006\tnote{***} & 0.007\tnote{***} \\
& {(8.55)} & {(7.82)} & {(7.67)} & {(8.54)} \\
\addlinespace
VAR2 & 0.132\tnote{***} & 0.131\tnote{***} & 0.131\tnote{***} & 0.132\tnote{***} \\
& {(20.35)} & {(20.15)} & {(20.15)} & {(20.35)} \\
\midrule
Observations
& \multicolumn{1}{c}{\num{1315077}}
& \multicolumn{1}{c}{\num{1315077}}
& \multicolumn{1}{c}{\num{1315077}}
& \multicolumn{1}{c}{\num{1315077}} \\
Day FE & {No} & {Yes} & {Yes} & {No} \\
Firm FE & {Yes} & {No} & {Yes} & {No} \\
Firm-Quarter FE & {No} & {No} & {No} & {Yes} \\
Adj. R-Sq{\super2} & 0.045 & 0.027 & 0.046 & 0.044 \\
\bottomrule
\end{tabular}
\par\(t\) statistics in parentheses
\par\tnote{*} \(p < 0.10\),\quad\tnote{**} \(p < 0.05\),\quad\tnote{***} \(p < 0.01\)
\end{threeparttable}
\end{table}
\end{document}
EDIT. I also enclosed statistics in{...} because siunitx does not recognised brackets as part of a number.

Table title with outreg2

I am working with the community-contributed command outreg2 to export regression estimates from a logit model to LaTeX.
Is there a way to show the table reference/label, for example, "Table 1: Some Title"?
I cannot seem to be able to do this using outreg2:
logit v1 v2 v43, or
outreg2 using "table", label cti(odds ratio) eform tex replace ctitle(Logit)
With esttab, using \label in the title option to get the desired result works:
esttab using "Table.tex",tex eform label replace title("Logit"\label{tab1})
Any suggestions?
EDIT:
Note that even when i do the following:
outreg2 using "table", label cti(odds ratio) eform tex replace ///
ctitle(Logit) title("Logit"\label{tab1})
This only produces the following:
Consider the following toy example:
webuse lbw
logit low age lwt i.race smoke ptl ht ui, or
Both esttab and outreg2 produce the same result when their title() option is used:
esttab, tex eform label replace title("Logit"\label{tab1})
outreg2 using "table", tex label cti(odds ratio) eform replace title("Logit"\label{tab1})
However, this will not work when typesetting as outreg2 produces
different markup than esttab.
The way to do what you want with outreg2 is to run the following from Stata:
outreg2 using table, tex replace label cti(odds ratio) eform
Unlike esttab, the outreg2 command does not have an option to insert markup
directly from within Stata. Thus you will have to add the markup below manually:
.
.
.
\begin{table}[htbp]\centering
\caption{Logit \label{tab1}}
.
.
.
\end{table}
.
.
.
The produced tex file should then look as follows:
\documentclass[]{article}
\setlength{\pdfpagewidth}{8.5in} \setlength{\pdfpageheight}{11in}
\begin{document}
\begin{table}[htbp]\centering
\caption{Logit \label{tab1}}
\begin{tabular}{lc} \hline
& (1) \\
VARIABLES & odds ratio \\ \hline
& \\
birthweight<2500g & \\
& \\
age of mother & 0.973 \\
& (0.0355) \\
weight at last menstrual period & 0.985** \\
& (0.00682) \\
race = 2, black & 3.535** \\
& (1.861) \\
race = 3, other & 2.368** \\
& (1.040) \\
smoked during pregnancy & 2.518** \\
& (1.009) \\
premature labor history (count) & 1.719 \\
& (0.595) \\
has history of hypertension & 6.250*** \\
& (4.322) \\
presence, uterine irritability & 2.135* \\
& (0.981) \\
Constant & 1.586 \\
& (1.910) \\
& \\
Observations & 189 \\ \hline
\multicolumn{2}{c}{ seEform in parentheses} \\
\multicolumn{2}{c}{ *** p$<$0.01, ** p$<$0.05, * p$<$0.1} \\
\end{tabular}
\end{table}
\end{document}
Leaving this here for future reference.
Actually, if you add the option tex(fragment) to outreg2, the resulting file will only contain the tabular environment. Then, you can create the table environment, with the caption that you desire, and use \input only to replace the tabular environment.

How to place a \figure*\minipage\eqnarray at the bottom of the SAME PAGE

I have a big equation that must be placed at the bottom of the page in a two columns paper. The call of the equation is at the end of the first column of a given page, but no matter what place holder I set([h!],[ht],etc), the equation goes to the next page. When I use [H] the equation dont even appear in the document.
I am using...
\documentclass[journal]{IEEEtran}
...
\usepackage{dblfloatfix}
...
The rotational torque that each motor generates is based on the signal compositions with the servomotor tilting angles. Thus, considering $ \dl = l \frac {\sqrt {2}} {2} $ and the right hand rule, resultant propulsion forces and torques on the $ \Fb $ are presented in Equation (\ref{eq1:gen_forces_torquesa}), suppressing the term $ (t) $:
\begin{figure*}[h!]
\begin{minipage}{.6\textwidth}
\begin{eqnarray} \label{eq1:gen_forces_torquesa}
\bm{\tau^b_p} &=&
\left(\begin{array}{cccccc}
X_{p}^{b} & Y_{p}^{b} & Z_{p}^{b} & L_{p}^{b} & M_{p}^{b} & N_{p}^{b}
\end{array}
\right)^T = \nonumber \\
&=&
\left(\begin{array}{c}
k_1\delta_1s(\gamma_1) + k_1\delta_2s(\gamma_2) + k_1\delta_3s(\gamma_3) + k_1\delta_4s(\gamma_4) \\
0 \\
-k_1\delta_1c(\gamma_1) - k_1\delta_2c(\gamma_2) - k_1\delta_3c(\gamma_3) - k_1\delta_4c(\gamma_4) \\
(-k_1\dl c(\gamma_1) - k_2s(\gamma_1))\delta_1 + (k_1\dl c(\gamma_2) - k_2s(\gamma_2))\delta_2 + (k_1\dl c(\gamma_3) + k_2s(\gamma_3))\delta_3 + (-k_1\dl c(\gamma_4) + k_2s(\gamma_4))\delta_4 \\
A_2 \\
A_3
\end{array}
\right) \nonumber \\
\end{eqnarray}
\end{minipage}
\end{figure*}
It always helps to have a complete minimal example.
It might be worth trying [b] instead. Perhaps also try inserting \newpage after the figure.

Latex Equation and bmatrix

I'm trying to use official equation, and it's giving me some trouble. I have this equation of a simple matrix operation, and LaTeX isn't liking it. What's wrong with this statement?
\begin{equation}
$M=\begin{bmatrix}
V_{1,1} & . & . & V_{1,n}\\
. & . & & \\
. & &. & \\
V_{m,1}& & & V_{m,n}
\end{bmatrix}$
\end{equation}
The error is:
! Display math should end with $$.
M
l.186 $M
=\begin{bmatrix}
? )
Delete the two dollar signs:
\begin{equation}
M=\begin{bmatrix}
V_{1,1} & . & . & V_{1,n}\\
. & . & & \\
. & &. & \\
V_{m,1}& & & V_{m,n}
\end{bmatrix}
\end{equation}
Removing the two $s, you have no more error.
Then, you may want to use the commands \cdots, \vdots, \ddots available from LaTeX (package amsmath is not even necessary for these three, while it is required for environment bmatrix):
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
M=\begin{bmatrix}
V_{1,1} & \cdots & V_{1,n}\\
\vdots & \ddots & \vdots\\
V_{m,1} & \cdots & V_{m,n}
\end{bmatrix}
\end{equation}
\end{document}
produces
(numbered equation). Notice how this is a 3-x-3 matrix, not 4-x-4.

LaTeX: Numbering only last line of multi-line equation in \align

I want to number and make a reference to just the last line of a multi-line equation in \align. Here is an example:
\begin{align}
z_1^2 &= \left( 2 e^{i \frac{\pi}{3}} \right) \left( 2 e^{i \frac{\pi}{3}} \right)\\
&= 4 e^{i \frac{2 \pi}{3}}
\end{align}
I only want to number the &= 4 e^{i \frac{2 \pi}{3}} part, rather than both lines of the \align. How do I do this?
From the amsmath documentatiom (amsldoc.pdf):
You can suppress the number on any
particular line by putting \notag
before the \\;
So your equation should look like this (some bits removed from your equation to make it shorter):
\begin{align}
z_1^2 &= \left( ... \right) \left( ... \right)\notag\\
&= 4 e^{i \frac{2 \pi}{3}}
\end{align}

Resources