Latex Equation and bmatrix - latex

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.

Related

Is it possible to use multicolumn and multirow simultaneously in a single cell?

I'm trying to draw a table, but I faced a problem with the extra column line.
\documentclass[lettersize,journal]{IEEEtran}
\usepackage{array,tabularx}
\usepackage{pifont}
\usepackage{multirow,booktabs,tabu}
\begin{table*}[!t]
\caption{A. \label{table8}}
\centering
\begin{tabu}{|c|c|c|c|c|c|c|}
\hline
\multirow{2}{*}{A} & \multicolumn{2}{c|}{\multirow{2}{*}{B}} & \multicolumn{4}{c|}{C} \\
\cline{4-7}
& & & E & F & G & H \\
\cline{1-7}
\multirow{3}{*}{D} &
\multirow{3}{*}{K} & $1.0612e-09$ & $1.0610e-09$ & $5.2760e-10$ & $3.7844e-08$ & $7.6545e-06 $\\
\cline{3-7}
& & $9.724e-10$ & $9.7239e-10$ & $4.8758e-10$ & $4.9127e-08$ & $7.7153e-06 $\\
\cline{3-7}
& & $9.132e-10$ & $9.131e-10$ & $4.1633e-10$ & $4.3932e-08$ & $8.2672e-06$\\[-1pt]
%\cline{2-7
\hline
\end{tabu}
\end{table*}
Does anyone know how to remove this extra line that shown in
Don't use the tabu package - it is more or less completely broken. The only thing which helds this package together is a lot of ducktape by the latex team.
Instead you could use tabularray package, which makes merging cells much easier and you'll also don't have to worry how long all your lines should be.
You might also want to choose another column type, like S from siunitx, to avoid the incorrect spacing around your minus signs ....
\documentclass[lettersize,journal]{IEEEtran}
\usepackage{array,tabularx}
\usepackage{pifont}
\usepackage{multirow,booktabs,tabularray}
\UseTblrLibrary{siunitx}
\begin{document}
\begin{table*}[!t]
\caption{A. \label{table8}}
\centering
\begin{tblr}{
colspec={|c|c|S[table-format=1.3e-2]|S[table-format=1.3e-2]|S[table-format=1.3e-2]|S[table-format=1.3e-2]|S[table-format=1.3e-2]|},
vlines,
hlines,
row{1-2} = {guard}
}
\SetCell[r=2]{} A & \SetCell[c=2,r=2]{} B && \SetCell[c=4]{} C &&& \\
& & & E & F & G & H \\
\SetCell[r=3]{} D &
\SetCell[r=3]{} K & 1.0612e-09 & 1.0610e-09 & 5.2760e-10 & 3.7844e-08 & 7.6545e-06\\
& & 9.724e-10 & 9.7239e-10 & 4.8758e-10 & 4.9127e-08 & 7.7153e-06\\
& & 9.132e-10 & 9.131e-10 & 4.1633e-10 & 4.3932e-08 & 8.2672e-06\\
\end{tblr}
\end{table*}
\end{document}

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.

How to create this complex (for me) table in latex

How can I recreate this table in latex? I didn't want to create a simple document in Word for my documentation and I'm trying my hand.
For now I have trivially solved the problem by integrating this table as a png.
Thank you for your time
Have a look at https://www.tablesgenerator.com/
Here is a sample based on your query:
Sample table LaTeX code
% Please add the following required packages to your document preamble:
% \usepackage{multirow}
\begin{table}[]
\begin{tabular}{llll}
use case \#6 & \multicolumn{3}{l}{Aggiungi} \\
& \multicolumn{3}{l}{} \\
& \multicolumn{3}{l}{} \\
& \multicolumn{3}{l}{} \\
\multirow{2}{*}{Description} & Step & Iscritto & Sistema \\
& & &
\end{tabular}
\end{table}
Here is a sketch:
\documentclass{article}
\usepackage{multirow}
\usepackage[table]{xcolor}
\begin{document}
\setlength{\tabcolsep}{.5em}
\renewcommand{\arraystretch}{1.2}
\begin{table}[htbp]
\begin{tabular}{|p{.2\textwidth}|p{.08\textwidth}|p{.33\textwidth}|p{.33\textwidth}|}
\hline
\cellcolor{blue!20}\textbf{Use} & \multicolumn{3}{l|}{\cellcolor{blue!20}Aggiungi}\\\hline
Goal & \multicolumn{3}{l|}{L'utente}\\\hline
Pre & \multicolumn{3}{l|}{L'utente}\\\hline
Success & \multicolumn{3}{l|}{L'utente}\\\hline
Failed & \multicolumn{3}{l|}{L'utente}\\\hline
Primary & \multicolumn{3}{l|}{Iscritto}\\\hline
Trigger & \multicolumn{3}{l|}{L'utente}\\\hline
\multirow{5}{*}{Description} & \cellcolor{blue!20}Step & \cellcolor{blue!20}Iscritto & \cellcolor{blue!20}Sistema\\\cline{2-4}
& 1 & Preme & \\\cline{2-4}
& 2 & & Mostra\\\cline{2-4}
& 3 & Seleziona & \\\cline{2-4}
& 4 & & Mostra\\\hline
\multirow{2}{*}{\parbox{.19\textwidth}{Extension \#1\\ blah blah}} %
& \cellcolor{blue!20}Step & \cellcolor{blue!20}Iscritto & \cellcolor{blue!20}Sistema\\\cline{2-4}
& In un qual\-sia\-si pun\-to & 2 & 3\\\hline
\multirow{2}{*}{\parbox{.19\textwidth}{Extension \#1\\ blah blah}} %
& \cellcolor{blue!20}Step & \cellcolor{blue!20}Iscritto & \cellcolor{blue!20}Sistema\\\cline{2-4}
& 1 & 2 & 3\\\hline
\multirow{2}{*}{\parbox{.19\textwidth}{Extension \#1\\ blah blah}} %
& \cellcolor{blue!20}Step & \cellcolor{blue!20}Iscritto & \cellcolor{blue!20}Sistema\\\cline{2-4}
& 1 & 2 & 3\\\hline
\end{tabular}
\end{table}
\end{document}
Check the two package in the header, needed to run.
You can also implement sans serif font, if you want.
This is the output of the above code:

Extra space between text of first and second rows in LaTex tabular environment

How to remove the extra space between the text of the first and second rows? Thanks in advance!
\documentclass[jou]{apa7}
\usepackage{siunitx}
\usepackage{textcomp}
\begin{document}
\begin{tabular}{m{13em}m{1cm}m{1cm}m{1cm}m{13em}m{1cm}m{1cm}m{1cm}} \hline
& A & B & C & & D & E & F \\ \hline
Model 1: Name of the first model inserted here & & & & Model 2: Name of the second model inserted here & & & & \\
\hspace{3mm} Integration strategies & .03 & .10 & .000 & Integration strategies & .34 & .08 & .000 \\
\hspace{3mm} Integration strategies & .12 & .03 & .56 & Integration strategies & .12 & .19 & .404\\
\end{tabular}
\end{document}
Your table is defined with 9 columns, but in the second row you use 10. You will get an error about this, so you shouldn't even look at what might or might not be a valid pdf.
If the error is fixed, the table will look like this:
\documentclass[jou]{apa7}
\usepackage{siunitx}
\usepackage{textcomp}
\begin{document}
\begin{tabular}{m{13em}m{1cm}m{1cm}m{1cm}m{13em}m{1cm}m{1cm}m{1cm}} \hline
& A & B & C & & D & E & F \\ \hline
Model 1: Name of the first model inserted here & & & & Model 2: Name of the second model inserted here & & & \\
\hspace{3mm} Integration strategies & .03 & .10 & .000 & Integration strategies & .34 & .08 & .000 \\
\hspace{3mm} Integration strategies & .12 & .03 & .56 & Integration strategies & .12 & .19 & .404\\
\end{tabular}
\end{document}
Instead of hard-coding the widths of all columns, it might be easier to use the tabularx package (and maybe the booktabs package for better spacing):
\documentclass[jou]{apa7}
\usepackage{siunitx}
\usepackage{textcomp}
\usepackage{tabularx}
\usepackage{booktabs}
\begin{document}
\begin{tabularx}{\linewidth}{XlllXlll}
\toprule
& A & B & C & & D & E & F \\
\midrule
Model 1: Name of the first model inserted here & & & & Model 2: Name of the second model inserted here & & & \\
\quad Integration strategies & .03 & .10 & .000 & Integration strategies & .34 & .08 & .000 \\
\quad Integration strategies & .12 & .03 & .56 & Integration strategies & .12 & .19 & .404\\
\bottomrule
\end{tabularx}
\end{document}
Normally I would also suggest to use #{}XlllXlll#{} to remove the space in front and after the columns, but for this specific example, this lead to a really bad linebreak

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.

Resources