TeX - LaTeX Asked by 1049 on December 14, 2020
I am just learning LaTex. I used stata and got the following
{
defsym#1{ifmmode^{#1}else(^{#1})fi}
begin{tabular}{l*{3}{ccc}l}
hline
multicolumn{11}{l}{textit{Panel A: }}
hlinehline
&multicolumn{3}{c}{Overall} &multicolumn{3}{c}{Set Household} &multicolumn{3}{c}{Non-set Household} & multicolumn{1}{l}{T-test}
& count& mean& sd& count& mean& sd& count& mean& sd &
hline
Average Age of the household respondent & 5000& 44.7& 12.8& 3400& 44.4& 12.5& 1016& 44.9& 13.1& 0.511
& & & & & & & & & & (0.87)
Percentage of Married & 4000& 0.86& 0.35& 345& 0.87& 0.34& 800& 0.85& 0.35& -0.014
& & & & & & & & & & (-0.88)
Number of family that are dependent in the income & 99& 0.83& 0.67& 94& 0.79& 0.70& 5000& 0.86& 0.65 & 0.070sym{*}
& & & & & & & & & & (2.29)
hline
multicolumn{11}{l}{textit{Panel B: }}
hlinehline
hline
multicolumn{11}{l}{textit{Panel C: }}
hlinehline
hlinehline
multicolumn{2}{l}{footnotesize textit{t} statistics in parentheses}
multicolumn{2}{l}{footnotesize sym{*} (p<0.05), sym{**} (p<0.01), sym{***} (p<0.001)}
end{tabular}
}
I edited the table and added Panel B and C later on as I generated new tables via stata. I am suing the following tex file to create my document as I have several tables
documentclass[a4paper]{article}
usepackage[utf8]{inputenc}
usepackage[english]{babel}
usepackage{graphicx}
usepackage{booktabs}
usepackage{array}
usepackage{paralist}
usepackage{verbatim}
usepackage{amssymb}
usepackage{amsmath}
usepackage{setspace}
onehalfspacing
usepackage[parfill]{parskip}
%--------------------------------------- Document --------------------------------------%
title{huge{}}
author{}
date{}
begin{document}
maketitle
section*{Introduction}
begin{table}[h]
centering
caption{ }
input{d.tex}
end{table}
begin{table}[h]
centering
caption{}
input{m.tex}
end{table}
end{document}
I have tried the following codes
1st
begin{tabular}{ |p{3cm}||p{3cm}|p{3cm}|p{3cm}| |p{3cm}||p{3cm}|p{3cm}|p{3cm}| |p{3cm}||p{3cm}|}
2nd
begin{tabular}{|l*{3}{ccc}l|}
3rd
resizebox{textwidth}{p{3cm}}{begin{tabular}{l*{3}{ccc}l}
4th
begin{tabular}{linewidth}{l*{3}{ccc}l}
but i got error and/or it did not solve my issue and the table still spilled out of the page. I hope someone here can help me resolve this issue i would be really thankful.
documentclass[a4paper]{article}
usepackage[utf8]{inputenc}
usepackage[english]{babel}
usepackage{graphicx}
usepackage{booktabs}
usepackage{array}
usepackage{paralist}
usepackage{verbatim}
usepackage{amssymb}
usepackage{amsmath}
usepackage{setspace}
onehalfspacing
usepackage[parfill]{parskip}
defsym#1{ifmmode^{#1}else(^{#1})fi}
usepackage{siunitx} % for improved alignment of numbers in tables using the S type column
usepackage{tabularx} % to make sure the table is as wide as the textwidth, for teh X type column
usepackage{booktabs} % for horizontal lines with improved spacing
usepackage{geometry} % for smaller margins, otherwise the table wouldn't fit
usepackage{multirow} % for the multirow command
%--------------------------------------- Document --------------------------------------%
begin{document}
begin{table}[h]
small
setlength{tabcolsep}{4pt}
centering
caption{ }
begin{tabularx}{linewidth}{@{}X
*{3}{
S[table-format=4]
S[table-format=2.2]
S[table-format=2.2]
}
S[table-format=-1.3,
input-symbols = {()},
table-space-text-pre=),
table-space-text-post=sym{*},
table-align-text-post=false,
]@{}}
toprule
multicolumn{11}{@{}l@{}}{textit{Panel A: }}
midrule
& multicolumn{3}{c}{Overall} & multicolumn{3}{c}{Set Household} & multicolumn{3}{c}{Non-set Household} & multicolumn{1}{l}{T-test}
cmidrule(r){2-4} cmidrule(lr){5-7} cmidrule(lr){8-10}
& {count} & {mean} & {sd} & {count} & {mean} & {sd} & {count} & {mean} &{sd} &
midrule
multirow[t]{2}{=}{Average Age of the household respondent}
& 5000 & 44.7 & 12.8 & 3400 & 44.4 & 12.5 & 1016 & 44.9 & 13.1 & 0.511
& & & & & & & & & & (0.87)
Percentage of Married
& 4000 & 0.86 & 0.35 & 345 & 0.87 & 0.34 & 800 & 0.85 & 0.35 & -0.014
& & & & & & & & & & {(}-0.88)
multirow[t]{2}{=}{Number of family that are dependent in the income}
& 99 & 0.83 & 0.67 & 94 & 0.79 & 0.70 & 5000 & 0.86 & 0.65 & 0.070sym{*}
& & & & & & & & & & (2.29)
midrule
multicolumn{11}{@{}l@{}}{textit{Panel B: }}
midrule
midrule
multicolumn{11}{@{}l@{}}{textit{Panel C: }}
midrule
bottomrule
multicolumn{11}{@{}l@{}}{footnotesize textit{t} statistics in parentheses}
multicolumn{11}{@{}l@{}}{footnotesize sym{*} (p<0.05), sym{**} (p<0.01), sym{***} (p<0.001)}
end{tabularx}
end{table}
end{document}
Since you mentioned in the comments, that Panel B and Panel C will contain entries belonging to the same columns as the entries in panel A, I would suggest the following slightly different layout versions. In both, I have places "Panel A" belos the column headers in order to avoid repeating them for every panel. In order to visually separate them "Panel x" from the surrounding table, I have either used two horizontal lnes or a ombination of indentation and small vertical white space:
documentclass[a4paper]{article}
usepackage[utf8]{inputenc}
usepackage[english]{babel}
usepackage{graphicx}
usepackage{booktabs}
usepackage{array}
usepackage{paralist}
usepackage{verbatim}
usepackage{amssymb}
usepackage{amsmath}
usepackage{setspace}
onehalfspacing
usepackage[parfill]{parskip}
defsym#1{ifmmode^{#1}else(^{#1})fi}
usepackage{siunitx} % for improved alignment of numbers in tables using the S type column
usepackage{tabularx} % to make sure the table is as wide as the textwidth, for teh X type column
usepackage{booktabs} % for horizontal lines with improved spacing
usepackage{geometry} % for smaller margins, otherwise the table wouldn't fit
usepackage{multirow} % for the multirow command
%--------------------------------------- Document --------------------------------------%
begin{document}
begin{table}[h]
small
setlength{tabcolsep}{4pt}
centering
caption{ }
begin{tabularx}{linewidth}{@{}X
*{3}{
S[table-format=4]
S[table-format=2.2]
S[table-format=2.2]
}
S[table-format=-1.3,
input-symbols = {()},
table-space-text-pre=),
table-space-text-post=sym{*},
table-align-text-post=false,
]@{}}
toprule
& multicolumn{3}{c}{Overall} & multicolumn{3}{c}{Set Household} & multicolumn{3}{c}{Non-set Household} & multicolumn{1}{l}{T-test}
cmidrule(r){2-4} cmidrule(lr){5-7} cmidrule(lr){8-10}
& {count} & {mean} & {sd} & {count} & {mean} & {sd} & {count} & {mean} &{sd} &
midrule
multicolumn{11}{@{}l@{}}{textit{Panel A: }}
midrule
multirow[t]{2}{=}{Average Age of the household respondent}
& 5000 & 44.7 & 12.8 & 3400 & 44.4 & 12.5 & 1016 & 44.9 & 13.1 & 0.511
& & & & & & & & & & (0.87)
Percentage of Married
& 4000 & 0.86 & 0.35 & 345 & 0.87 & 0.34 & 800 & 0.85 & 0.35 & -0.014
& & & & & & & & & & {(}-0.88)
multirow[t]{2}{=}{Number of family that are dependent in the income}
& 99 & 0.83 & 0.67 & 94 & 0.79 & 0.70 & 5000 & 0.86 & 0.65 & 0.070sym{*}
& & & & & & & & & & (2.29)
midrule
multicolumn{11}{@{}l@{}}{textit{Panel B: }}
midrule
multirow[t]{2}{=}{Average Age of the household respondent}
& 5000 & 44.7 & 12.8 & 3400 & 44.4 & 12.5 & 1016 & 44.9 & 13.1 & 0.511
& & & & & & & & & & (0.87)
Percentage of Married
& 4000 & 0.86 & 0.35 & 345 & 0.87 & 0.34 & 800 & 0.85 & 0.35 & -0.014
& & & & & & & & & & {(}-0.88)
midrule
multicolumn{11}{@{}l@{}}{textit{Panel C: }}
midrule
multirow[t]{2}{=}{Average Age of the household respondent}
& 5000 & 44.7 & 12.8 & 3400 & 44.4 & 12.5 & 1016 & 44.9 & 13.1 & 0.511
& & & & & & & & & & (0.87)
Percentage of Married
& 4000 & 0.86 & 0.35 & 345 & 0.87 & 0.34 & 800 & 0.85 & 0.35 & -0.014
& & & & & & & & & & {(}-0.88)
bottomrule
multicolumn{11}{@{}l@{}}{footnotesize textit{t} statistics in parentheses}
multicolumn{11}{@{}l@{}}{footnotesize sym{*} (p<0.05), sym{**} (p<0.01), sym{***} (p<0.001)}
end{tabularx}
end{table}
begin{table}[h]
small
setlength{tabcolsep}{3.5pt}
centering
caption{ }
begin{tabularx}{linewidth}{X
*{3}{
S[table-format=4]
S[table-format=2.2]
S[table-format=2.2]
}
S[table-format=-1.3,
input-symbols = {()},
table-space-text-pre=),
table-space-text-post=sym{*},
table-align-text-post=false,
]@{}}
toprule
& multicolumn{3}{c}{Overall} & multicolumn{3}{c}{Set Household} & multicolumn{3}{c}{Non-set Household} & multicolumn{1}{l}{T-test}
cmidrule(r){2-4} cmidrule(lr){5-7} cmidrule(lr){8-10}
& {count} & {mean} & {sd} & {count} & {mean} & {sd} & {count} & {mean} &{sd} &
midrule
multicolumn{11}{@{}l@{}}{textit{Panel A: }}
addlinespace
multirow[t]{2}{=}{Average Age of the household respondent}
& 5000 & 44.7 & 12.8 & 3400 & 44.4 & 12.5 & 1016 & 44.9 & 13.1 & 0.511
& & & & & & & & & & (0.87)
Percentage of Married
& 4000 & 0.86 & 0.35 & 345 & 0.87 & 0.34 & 800 & 0.85 & 0.35 & -0.014
& & & & & & & & & & {(}-0.88)
multirow[t]{2}{=}{Number of family that are dependent in the income}
& 99 & 0.83 & 0.67 & 94 & 0.79 & 0.70 & 5000 & 0.86 & 0.65 & 0.070sym{*}
& & & & & & & & & & (2.29)
midrule
multicolumn{11}{@{}l@{}}{textit{Panel B: }}
addlinespace
multirow[t]{2}{=}{Average Age of the household respondent}
& 5000 & 44.7 & 12.8 & 3400 & 44.4 & 12.5 & 1016 & 44.9 & 13.1 & 0.511
& & & & & & & & & & (0.87)
Percentage of Married
& 4000 & 0.86 & 0.35 & 345 & 0.87 & 0.34 & 800 & 0.85 & 0.35 & -0.014
& & & & & & & & & & {(}-0.88)
midrule
multicolumn{11}{@{}l@{}}{textit{Panel C: }}
addlinespace
multirow[t]{2}{=}{Average Age of the household respondent}
& 5000 & 44.7 & 12.8 & 3400 & 44.4 & 12.5 & 1016 & 44.9 & 13.1 & 0.511
& & & & & & & & & & (0.87)
Percentage of Married
& 4000 & 0.86 & 0.35 & 345 & 0.87 & 0.34 & 800 & 0.85 & 0.35 & -0.014
& & & & & & & & & & {(}-0.88)
bottomrule
multicolumn{11}{@{}l@{}}{footnotesize textit{t} statistics in parentheses}
multicolumn{11}{@{}l@{}}{footnotesize sym{*} (p<0.05), sym{**} (p<0.01), sym{***} (p<0.001)}
end{tabularx}
end{table}
end{document}
Answered by leandriis on December 14, 2020
Here is a proposition with makecell, multirow, booktabs
and geometry
, reducing slightly the font size and the intercolumn spacing:
documentclass[a4paper]{article}
usepackage[showframe]{geometry}
usepackage[english]{babel}
usepackage{booktabs}
usepackage{array, makecell, multirow}%
usepackage{siunitx}
usepackage{amssymb}
usepackage{setspace}
onehalfspacing
usepackage[parfill]{parskip}
begin{document}
{
defsym#1{ifmmode^{#1}else(^{#1})fi}
setlength{tabcolsep}{3pt}
renewcommand{theadset}{renewcommand{arraystretch}{0.6}}
renewcommand{theadalign}{lc}
renewcommand{theadfont}{small}
sisetup{table-format=2.2, table-number-alignment=center}
small
begin{center}
begin{tabular}{@{}l*{3}{S[table-format=4.0]SS}S[table-format=-1.3, table-space-text-post=sym{*}]}
toprule
multicolumn{11}{l}{textit{Panel A: }}
midrulemidrule
&multicolumn{3}{c}{Overall} &multicolumn{3}{c}{Set Household} &multicolumn{3}{c}{Non-set Household} & {multirowcell{2}{T-test}}
cmidrule(lr){2-4}cmidrule(r){5-7}cmidrule(r){8-10}
& {count} & {mean} & {sd} & {count} & {mean} & {sd} & {count} & {mean} & {sd}&
midrule
multirowthead{2}{Average Age of the household respondent} & 5000& 44.7& 12.8& 3400& 44.4& 12.5& 1016& 44.9& 13.1& 0.511
& & & & & & & & & &{$ (0.87) $}
addlinespace
thead { Percentage of Married} & 4000& 0.86& 0.35& 345& 0.87& 0.34& 800& 0.85& 0.35& -0.014
& & & & & & & & & & {$ (-0.88) $}
addlinespace
multirowthead{2}{Number of families that are dependent in the income} & 99& 0.83& 0.67& 94& 0.79& 0.70& 5000& 0.86& 0.65 & 0.070sym{*}
& & & & & & & & & &{$ (2.29) $}
addlinespace[2ex]
midrule
multicolumn{11}{l}{textit{Panel B: }}
midrulemidrule
midrule
multicolumn{11}{l}{textit{Panel C: }}
midrulemidrule
bottomrule
multicolumn{3}{@{}l}{footnotesize textit{t} statistics in parentheses}
multicolumn{3}{@{}l}{footnotesize sym{*} (p<0.05), sym{**} (p<0.01), sym{***} (p<0.001)}
end{tabular}
end{center}
}
end{document}
Answered by Bernard on December 14, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP