Restriction on size of matrix? - latex

The difference between this code:
\begin{align*}
I &= \begin{pmatrix}
0 & 1 & 0.5 & 0.5 & 0 & 0.5 & 0.5 & 1 & 0 & 1 & 1\\
0 & 1 & 0.5 & 0.5 & 0 & 0.5 & 0.5 & 1 & 0 & 1 & 1\\
1 & 1 & 0.5 & 0.5 & 0 & 0.5 & 0.5 & 1 & 0 & 1 & 0\\
1 & 1 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 0\\
1 & 1 & 0.5 & 0.5 & 0 & 0.5 & 1 & 1 & 1 & 0 & 0\\
0 & 0 & 0.5 & 0.5 & 0 & 0.5 & 1 & 1 & 0 & 0 & 1\\
0 & 0 & 0.5 & 0.5 & 1 & 1 & 1 & 1 & 1 & 0 & 0\\
\end{pmatrix}\\
\end{align*}
which does not compile, and this one which does compile
\begin{align*}
I &= \begin{pmatrix}
0 & 1 & 0.5 & 0.5 & 0 & 0.5 & 0.5 & 1 & 0 & 1\\
0 & 1 & 0.5 & 0.5 & 0 & 0.5 & 0.5 & 1 & 0 & 1\\
1 & 1 & 0.5 & 0.5 & 0 & 0.5 & 0.5 & 1 & 0 & 1\\
1 & 1 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0\\
1 & 1 & 0.5 & 0.5 & 0 & 0.5 & 1 & 1 & 1 & 0\\
0 & 0 & 0.5 & 0.5 & 0 & 0.5 & 1 & 1 & 0 & 0\\
0 & 0 & 0.5 & 0.5 & 1 & 1 & 1 & 1 & 1 & 0\\
\end{pmatrix}\\
\end{align*}
is that the one tha does compile does not have the last column. What gives?

According to this site, the max number of columns a matrix can have by default is 10. You can override this by using the command
\setcounter{MaxMatrixCols}{n}
where n is the number of desired columns.

Related

Latex with both a thousand separator comma and decimal point [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 days ago.
Improve this question
I am trying to include both a decimal point and comma separator in a table. Even though the table input includes both the commas and the decimal separators, the latex table converts all the comma separating the thousands digits to decimal points. Is there a way to have both at the same time and align the numbers at the decimal and comma separators?
Thank you!
\documentclass{wptemp}
\usepackage{adjustbox}
\usepackage{setspace}\doublespacing
\usepackage{booktabs}
\usepackage{siunitx}
\newcolumntype{d}{S[input-symbols = ()]}
\usepackage{lscape}
\newcommand{\source}[1]{\caption*{Source: {#1}} }
% *****************************************************************
% Estout LaTeX wrapper
% *****************************************************************
%%Original code developed by Jörg Weber: see
%% https://www.jwe.cc/2012/03/stata-latex-tables-estout/
%% and
%% https://www.jwe.cc/blog/
\let\estinput=\input % define a new input command so that we can still flatten the document
\newcommand{\estwide}[3]{
\vspace{.75ex}{
%\textsymbols% Note the added command here
\begin{tabular*}
{\textwidth}{#{\hskip\tabcolsep\extracolsep\fill}l*{#2}{#3}}
\toprule
\estinput{#1}
\bottomrule
\addlinespace[.75ex]
\end{tabular*}
}
}
\newcommand{\estauto}[3]{
\vspace{.75ex}{
%\textsymbols% Note the added command here
\begin{tabular}{l*{#2}{#3}}
\toprule
\estinput{#1}
\bottomrule
\addlinespace[.75ex]
\end{tabular}
}
}
% Allow line breaks with \ in specialcells
\newcommand{\specialcell}[2][c]{%
\begin{tabular}[#1]{#{}c#{}}#2\end{tabular}
}
\newcommand{\sym}[1]{\rlap{#1}}% Thanks David Carlisle
%%%%%%%%%%% End of wrapper %%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%% TiKz %%%%%%%%%%%%%%%%%%%%%
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\tikzstyle{startstop} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, text width =5cm, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, minimum width=3cm, minimum height=1cm, text centered, text width =5cm, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\linespread{1}{\title{{\fontfamily{ptm}\selectfont{\Large{\MakeUppercase{}}}}
% \thanks{}
}}
\author{}
\date{\fontfamily{pbk}\selectfont\normalsize{\textsc{\today}}}
\maketitle
% \begin{abstract}
% % \keywords{Keyword1; Keyword2; Keyword3.}
% % \JEL{}
% \end{abstract}
\thispagestyle{empty}
\pagenumbering{arabic}
\begin{table}[H]
\caption{Spill Over Effect of depression on GPA \label{tab:reggpa}}
\centering
\resizebox{\linewidth}{!}{
\begin{tabular}[t]{ldddddd}
\toprule
\multicolumn{1}{c}{Dependent Variable} & \multicolumn{1}{c}{Own Depression} & \multicolumn{1}{c}{GPA} & \multicolumn{1}{c}{Skip School} & \multicolumn{1}{c}{Miss School} & \multicolumn{1}{c}{Smoke Cigarettes} & \multicolumn{1}{c}{Get Drunk} \\
\cmidrule(l{3pt}r{3pt}){1-1} \cmidrule(l{3pt}r{3pt}){2-2} \cmidrule(l{3pt}r{3pt}){3-3} \cmidrule(l{3pt}r{3pt}){4-4} \cmidrule(l{3pt}r{3pt}){5-5} \cmidrule(l{3pt}r{3pt}){6-6} \cmidrule(l{3pt}r{3pt}){7-7}
& {\specialcell{(1)}} & {\specialcell{(2)}} & {\specialcell{(3)}} & {\specialcell{(4)}} & {\specialcell{(5)}} & {\specialcell{(6)}}\\
\midrule
\addlinespace[0.5em]
\multicolumn{7}{l}{\textit{Panel A: Full Sample}}\\
\midrule \hspace{1em}\specialcell{Average Depression \\ Index: friends} & 0.74*** & -0.33*** & 0.24*** & 0.15*** & 0.40*** & 0.30***\\
\hspace{1em} & (0.05) & (0.09) & (0.04) & (0.04) & (0.05) & (0.05)\\
\hspace{1em}Observations & 53,912 & 36,065 & 51,813 & 50,816 & 51,941 & 51,579\\
\addlinespace[0.5em]
\multicolumn{7}{l}{\textit{Panel B: Women}}\\
\midrule \hspace{1em}\specialcell{Average Depression \\ Index: friends} & 0.84*** & -0.41*** & 0.25*** & 0.24*** & 0.44*** & 0.28***\\
\hspace{1em} & (0.09) & (0.10) & (0.05) & (0.07) & (0.06) & (0.06)\\
\hspace{1em}Observations & 28,703 & 19,272 & 27,797 & 27,339 & 27,856 & 27,659\\
\addlinespace[0.5em]
\multicolumn{7}{l}{\textit{Panel C: Men}}\\
\midrule \hspace{1em}\specialcell{Average Depression \\ Index: friends} & 0.69*** & -0.23* & 0.25*** & 0.06 & 0.37*** & 0.34***\\
\hspace{1em} & (0.08) & (0.13) & (0.05) & (0.06) & (0.06) & (0.07)\\
\hspace{1em}Observations & 25,195 & 16,784 & 24,003 & 23,465 & 24,071 & 23,906\\
\addlinespace[0.5em]
\multicolumn{7}{l}{\textit{Panel D: Above median \# friends}}\\
\midrule \hspace{1em}\specialcell{Average Depression \\ Index: friends} & 0.89*** & -0.57*** & 0.31*** & 0.17*** & 0.42*** & 0.33***\\
\hspace{1em} & (0.08) & (0.10) & (0.05) & (0.05) & (0.05) & (0.06)\\
\hspace{1em}Observations & 34,654 & 23,653 & 33,558 & 32,948 & 33,640 & 33,400\\
\addlinespace[0.5em]
\multicolumn{7}{l}{\textit{Panel E: Below median \# friends}}\\
\midrule \hspace{1em}\specialcell{Average Depression \\ Index: friends} & 0.60*** & -0.04 & 0.16*** & 0.14** & 0.37*** & 0.27***\\
\hspace{1em} & (0.09) & (0.11) & (0.05) & (0.06) & (0.07) & (0.07)\\
\hspace{1em}Observations & 19,258 & 12,412 & 18,255 & 17,868 & 18,301 & 18,179\\
\midrule
\hspace{1em}School FE & {X} & {X} & {X} & {X} & {X} & {X}\\
\hspace{1em}Clustered Standard Errors & {by: SchoolID} & {by: SchoolID} & {by: SchoolID} & {by: SchoolID} & {by: SchoolID} & {by: SchoolID}\\
Mean Full Sample & 0.00 & 2.86 & 0.30 & 0.45 & 0.36 & 0.31\\
Mean Women Sample & 0.26 & 2.94 & 0.29 & 0.48 & 0.35 & 0.29\\
Mean Men Sample & -0.24 & 2.78 & 0.32 & 0.42 & 0.36 & 0.33\\
Mean Friends > Median & 0.11 & 2.91 & 0.30 & 0.44 & 0.38 & 0.34\\
Mean Friends $\leq$ Median & -0.11 & 2.80 & 0.30 & 0.46 & 0.32 & 0.27\\
\bottomrule
\multicolumn{7}{l}{\rule{0pt}{1em}\textit{Note: }}\\
\multicolumn{7}{l}{\rule{0pt}{1em}I include controls for sex, age, race, parental education, parental work status, parental job, and school fixed effects. }\\
\multicolumn{7}{l}{\rule{0pt}{1em}* p $<$ 0.1, ** p $<$ 0.05, *** p $<$ 0.01}\\
\end{tabular}}
\end{table}
\end{document}

How to merge cells of row in table in latex?

enter image description here
For example i have this table from excel which i want to add in latex. I am trying but ot able to sucesfully manage to do this. any lead to this will great help to me.
I tried using multirow in latex but actually did not work.
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|}
\hline
\multicolumn{2}{|c|}{} & \multicolumn{3}{c|} {\textbf{97\%}}& \multicolumn{3}{c|} {\textbf{146\%}}& \multicolumn{3}{c|} {\textbf{244\%}}\\
\cline{3-5}
\multicolumn{2}{|c|}{} & Latency & Channel Utilisation & Bandwidth Utilisation & Latency & Channel Utilisation & Bandwidth Utilisation & Latency & Channel Utilisation & Bandwidth Utilisation\\
\hline
CCTV Display & 0 & 0 & 0 & 0& 0 & 0 & 0 & 0& 0 & 0 \\
CCTV Recorder & 0 & 0 & 0 & 0& 0 & 0 & 0 & 0& 0 & 0 \\
VCU & 0 & 0 & 0 & 0& 0 & 0 & 0 & 0& 0 & 0 \\
BCU & 0 & 0 & 0 & 0& 0 & 0 & 0 & 0& 0 & 0 \\
TCU & 0 & 0 & 0 & 0& 0 & 0 & 0 & 0& 0 & 0 \\
PECU & 0 & 0 & 0 & 0& 0 & 0 & 0 & 0& 0 & 0 \\
OBCU & 0 & 0 & 0 & 0& 0 & 0 & 0 & 0& 0 & 0 \\
Switch 1 & 0 & 0 & 0 & 0& 0 & 0 & 0 & 0& 0 & 0 \\
Switch 2 & 0 & 0 & 0 & 0& 0 & 0 & 0 & 0& 0 & 0 \\
Switch 3 & 0 & 0 & 0 & 0& 0 & 0 & 0 & 0& 0 & 0 \\
Switch 4 & 0 & 0 & 0 & 0& 0 & 0 & 0 & 0& 0 & 0 \\
Switch 5 & 0 & 0 & 0 & 0& 0 & 0 & 0 & 0& 0 & 0 \\
Switch 6 & 0 & 0 & 0 & 0& 0 & 0 & 0 & 0& 0 & 0 \\
\hline
\end{tabular}
For a professional looking table, I suggest the following layout:
\documentclass{article}
\usepackage[hmargin=1cm]{geometry}
\usepackage{caption}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\begin{document}
\begin{table}[htbp]
\caption{some caption text}
\begin{tblr}{
cells={halign=c,valign=m},
colspec={#{}X[1.3,halign=l]XXXXXXXXX#{}},
colsep={3pt}
}
\toprule
Increase in Data Volume & \SetCell[c=3]{} 97\% &&& \SetCell[c=3]{} 146\% &&& \SetCell[c=3]{} 244\% &&\\
\cmidrule[r]{2-4}\cmidrule[lr]{5-7}\cmidrule[l]{8-10}
Parameter & Latency & Channel Utilisation & Bandwidth Utilisation & Latency & Channel Utilisation & Bandwidth Utilisation & Latency & Channel Utilisation & Bandwidth Utilisation\\
\midrule
CCTV Display & 0 & 0 & 0 & 0& 0 & 0 & 0& 0 & 0 \\
CCTV Recorder & 0 & 0 & 0 & 0& 0 & 0 & 0& 0 & 0 \\
VCU & 0 & 0 & 0 & 0& 0 & 0 & 0 & 0 & 0 \\
BCU & 0 & 0 & 0 & 0& 0 & 0 & 0 & 0 & 0 \\
TCU & 0 & 0 & 0 & 0& 0 & 0 & 0 & 0 & 0 \\
PECU & 0 & 0 & 0 & 0& 0 & 0 & 0 & 0 & 0 \\
OBCU & 0 & 0 & 0 & 0& 0 & 0 & 0 & 0 & 0 \\
Switch 1 & 0 & 0 & 0 & 0& 0 & 0 & 0& 0 & 0 \\
Switch 2 & 0 & 0 & 0 & 0& 0 & 0 & 0& 0 & 0 \\
Switch 3 & 0 & 0 & 0 & 0& 0 & 0 & 0& 0 & 0 \\
Switch 4 & 0 & 0 & 0 & 0& 0 & 0 & 0& 0 & 0 \\
Switch 5 & 0 & 0 & 0 & 0& 0 & 0 & 0& 0 & 0 \\
Switch 6 & 0 & 0 & 0 & 0& 0 & 0 & 0& 0 & 0 \\
\bottomrule
\end{tblr}
\end{table}
\end{document}

Variable labels on multiple lines in LaTeX when exporting results with esttab

I am trying to export some regression results to LaTeX using the community-contributed command estate in Stata. I want to use variable labels instead of variable names, but some of the labels are so long that the width of the table does not fit nicely on the page once I export it to LaTeX.
Example data can be found below:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double areakey float(state d1 d2) int(bfunemp otnenon bmunemp)
1015001100 1 0 1 0 26 0
1033020701 1 0 1 27 1 33
1073003803 1 0 1 208 0 78
1073005702 1 0 1 76 0 88
1073011904 1 0 1 35 0 44
1073013200 1 0 1 11 0 59
1097006407 1 0 0 0 0 9
1097007300 1 0 1 9 0 0
1111000600 1 0 0 6 0 1
1115040201 1 0 0 4 0 2
1115040204 1 0 0 3 5 6
1117030317 1 1 1 0 0 0
1117030320 1 0 0 11 0 0
1117030336 1 0 0 0 0 0
1125011600 1 0 1 91 0 88
1125011701 1 0 1 73 0 41
4013112100 4 0 0 0 0 0
4013112301 4 0 1 8 0 25
4013112601 4 0 1 0 0 0
4013112700 4 0 0 0 0 0
end
label var areakey "GEOID10"
label var state "State FIPS code"
label var d1 "Distance <= 1 Dummy"
label var d2 "Distance <= 2 Dummy"
label var bfunemp "Unemployed Black/Afr. Am. females 16+ yo."
label var otnenon "Pers. 18-64 yo. other lang. not well/no Eng."
label var bmunemp "Unemployed Black/Afr. Am. males 16+ yo."
In addition, the code I am using is the following:
global xvars bfunemp otnenon bmunemp
eststo mreg1: quietly areg d1 $xvars, absorb(state) robust ///
cluster(state)
eststo mreg2: quietly areg d2 $xvars, absorb(state) robust ///
cluster(state)
keep if indicatorvar > 0
eststo mreg3: quietly areg d1 $xvars, absorb(state) robust ///
cluster(state)
eststo mreg4: quietly areg d2 $xvars, absorb(state) robust ///
cluster(state)
esttab mreg1 mreg3 mreg2 mreg4 using ///
"$repodir/output/tables/tract_mregs.tex", ///
replace booktabs longtable mtitles("y1" "y1" "y2" "y2") ///
s(modelsample modelobs, label("Sample" "N")) se ///
noconstant nonumbers nonotes label star(* 0.10 ** 0.05 *** 0.01)
The result after I compile the TeX file is a table where the left margin is fine but the contents of the table extend off the right side of the page such that there is no margin.
Is there a way of specifying the format so that the labels can extend to multiple lines?
Substituting option longtable with wrap will produce the desired output after you compile:
esttab mreg1 mreg3 mreg2 mreg4, tex wrap ///
mtitles("y1" "y1" "y2" "y2") ///
s(modelsample modelobs, label("Sample" "N")) se ///
noconstant nonumbers nonotes label star(* 0.10 ** 0.05 *** 0.01)
{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\begin{tabular}{l*{4}{c}}
\hline\hline
&\multicolumn{1}{c}{y1}&\multicolumn{1}{c}{y1}&\multicolumn{1}{c}{y2}&\multicolumn{1}{c}{y2}
> \\
\hline
Unemployed & -0.0000359 & -0.0000359 & -0.000489 & -0.000489 \\
Black/Afr. Am. females 16+ yo.& (0.0000876) & (0.0000876) & (0.000770) & (0.000770)
> \\
[1em]
Pers. 18-64 yo. & -0.00555\sym{**} & -0.00555\sym{**} & 0.0244\sym{**} & 0.0244\sym{**} \\
other lang. not well/no Eng.& (0.000143) & (0.000143) & (0.00126) & (0.00126)
> \\
[1em]
Unemployed & -0.00180\sym{*} & -0.00180\sym{*} & 0.0109 & 0.0109 \\
Black/Afr. Am. males 16+ yo.& (0.000221) & (0.000221) & (0.00194) & (0.00194)
> \\
\hline
Sample & & & & \\
N & & & & \\
\hline\hline
\end{tabular}
}
In addition, the option varwidth() can also help adjusting the length of the first column.

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 do I type && in latex?

So i'm trying to make a table but it doesn't look to good since the lines break inside the table in a way I don't like.
\begin{tabular}{|p{8cm}|p{1cm}|}
\hline
! (4 < 5) & \\
! false & \\
(2 > 2) ││ ((4 == 4) && (1 < 0)) & \\
(2 > 2) ││ (4 == 4) && (1 < 0) & \\
(34 != 33) && ! false & \\
\hline
end{tabular}
What happens is that it breaks into new lines after every "&&", how do I stop this from happening? How do I make latex type "&&" instead of it thinking "& something empty &"?
Use an escape character: \
(I added a package here for clarity)
\begin{tabular}{|p{8cm}|p{1cm}|}
\hline
! (4 < 5) & \\
! false & \\
(2 > 2) ││ ((4 == 4) \&\& (1 < 0)) & \\
(2 > 2) ││ (4 == 4) \&\& (1 < 0) & \\
(34 != 33) \&\& ! false & \\
\hline
\end{tabular}

Resources