I am getting a really strange error while using longtable.
When I run the following code in a standalone file, I get a neat table with perfect alignment (see picture).
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{longtable}
\usepackage{geometry}
\author{Parul Gupta}
\date{March 2021}
\begin{document}
\maketitle
\section{Introduction}
{
\def\sym#1{\ifmmode^{#1}\else(^{#1})\fi}
\begin{longtable}{l{4}{c}}
\caption{Private tutoring demand, hurdle model (IHDS, 2012) \label{ihds}}\
\hline\hline\endfirsthead\hline\endhead\hline\endfoot\endlastfoot
&\multicolumn{2}{c}{Rural}&\multicolumn{2}{c}{Urban}\
\cline{2-3}
\cline{4-5}
&\multicolumn{1}{c}{1st stage}&\multicolumn{1}{c}{2nd stage}&\multicolumn{1}{c}{1st stage}&\multicolumn{1}{c}{2nd stage}\
&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}\
&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}\
\hline
Male 1 & 0.0372\sym{}& 0.0698\sym{}& 0.0365\sym{}& 0.0451 \
& (8.45) & (3.30) & (4.37) & (1.69) \
[1em]
Attends government school=1& -0.0453\sym{}& -0.122\sym{} & -0.0236 & 0.0403 \
& (-6.03) & (-3.01) & (-1.83) & (1.03) \
[1em]
Distance from school (km)& 0.000139 & 0.00576\sym{} &-0.000536 & 0.00651\sym{} \
& (0.29) & (2.95) & (-0.38) & (2.18) \
[1em]
classes=1 & 0.0278\sym{*}& 0.171\sym{}& 0.00682 & 0.216\sym{}\
& (5.00) & (5.20) & (0.60) & (5.96) \
[1em]
classes=2 & 0.111\sym{}& 0.511\sym{}& 0.0631\sym{}& 0.518\sym{}\
& (13.69) & (13.16) & (4.70) & (12.67) \
[1em]
EQ4 2.11 Homework hours/week& 0.00139\sym{}& 0.00303\sym{} & 0.00273\sym{} & 0.00691\sym{}\
& (3.34) & (2.75) & (3.28) & (3.86) \
[1em]
EQ4 2.13 Days/month absent& -0.00151\sym{} &-0.0000962 & -0.00209 & -0.00328 \
& (-2.93) & (-0.05) & (-1.85) & (-0.98) \
[1em]
EQ5 2.24 Scholarship (rupees)&0.0000165\sym{*}&0.0000475\sym{}&-0.00000440 &0.0000617 \
& (3.33) & (5.51) & (-0.55) & (1.58) \
[1em]
Attends English medium school=1& 0.0157 & 0.151\sym{} & 0.0443\sym{} & 0.166\sym{}\
& (1.43) & (3.11) & (2.95) & (3.96) \
[1em]
Muslim 2 & 0.0110 & -0.0243 & 0.0349\sym{} & -0.0548 \
& (1.16) & (-0.48) & (2.49) & (-1.14) \
[1em]
Others 3 & 0.0184 & 0.0783 & -0.0211 & -0.0877 \
& (1.27) & (1.10) & (-0.94) & (-1.48) \
[1em]
OBC & -0.00470 & -0.0141 & 0.0231 & -0.0353 \
& (-0.61) & (-0.44) & (1.70) & (-0.94) \
[1em]
SC & -0.0178\sym{} & -0.0323 & -0.00242 & 0.000542 \
& (-2.16) & (-0.89) & (-0.15) & (0.01) \
[1em]
ST & -0.0260\sym{*} & -0.0268 & 0.0273 & -0.0435 \
& (-2.14) & (-0.36) & (0.93) & (-0.41) \
[1em]
Father's years of education& 0.00256\sym{}& 0.0202\sym{}& 0.00223 & 0.0122\sym{*} \
& (3.30) & (4.35) & (1.42) & (2.46) \
[1em]
Mother's years of education& 0.00333\sym{}& 0.00209 &-0.000313 & 0.0157\sym{} \
& (4.14) & (0.51) & (-0.20) & (3.14) \
[1em]
Yes 1 & -0.0176\sym{} & 0.0135 & -0.0301\sym{} & -0.0731 \
& (-3.03) & (0.40) & (-2.32) & (-1.94) \
[1em]
No. of siblings in age group 0-5& -0.0113\sym{} & -0.0222 & -0.0244\sym{} & -0.0291 \
& (-2.28) & (-0.67) & (-2.26) & (-0.73) \
[1em]
Eldest child=1 & 0.0275\sym{*}& 0.00254 & 0.0673\sym{}& 0.0524 \
& (6.50) & (0.12) & (8.05) & (1.95) \
[1em]
HQ23 14. household expenditure /capita&0.000000725\sym{} &0.00000147\sym{} &0.000000744\sym{} &0.00000389\sym{}\
& (2.90) & (2.01) & (2.99) & (6.47) \
[1em]
Average tuition participation in village& 0.00579\sym{}& & 0.00726\sym{}& \
& (42.37) & & (37.34) & \
[1em]
Average tuition spending in village (Rs.)& & 0.000127\sym{}& &0.0000489\sym{}\
& & (9.10) & & (5.37) \
\hline
State controls & Yes & & Yes & \
N & 20955 & 20955 & 9211 & 9211 \
\hline\hline
\multicolumn{5}{l}{\footnotesize \textit{t} statistics in parentheses}\
\multicolumn{5}{l}{\footnotesize Source: IHDS, 2012}\
\multicolumn{5}{l}{\footnotesize Robust standard errors, clustered at PSU level}\
\multicolumn{5}{l}{\footnotesize \sym{} (p<0.05), \sym{} (p<0.01), \sym{*} (p<0.001)}\
\end{longtable}
}
\end{document}
But when I run the exact same code in the actual file where I want it to be placed, it gives me a strange-looking table with the last column runnning into the right margin (see picture). I am using longtable and geometry packages in the preamble. However, I am writing a dissertation, and am using a LaTeX template designed for my institute. Could that be causing a problem? Please suggest a workaround, if any. Thank you!





And yes, the template is available publicly at https://github.com/Saipraneet/iitdthesis
– PGupta Mar 13 '21 at 06:50