我使用 Excel2Latex 将 Excel 中的表格转换为 Latex,但是当文本太长而无法放入列中时会出现问题,并且会出现许多坏框错误。我的代码是:
% Table generated by Excel2LaTeX from sheet 'Sheet1'
\begin{table}[htbp]
\centering
\caption{Add caption}
\begin{tabular}{rr}
\toprule
\multicolumn{1}{c}{\textbf{Variable}} & \multicolumn{1}{c}{\textbf{Description}} \\
\midrule
\multicolumn{1}{l}{\textit{W\_hours}} & \multicolumn{1}{l}{The average number of hours worked each week by the respondent} \\
\multicolumn{1}{l}{\textit{W\_hours\_dummy}} & \multicolumn{1}{l}{A dummy variable that takes the value of unity if the respondent works more than 0 hours each week, and zero otherwise} \\
\multicolumn{1}{l}{\textit{W\_age}} & \multicolumn{1}{l}{The age (in years) of the woman} \\
\multicolumn{1}{l}{\textit{W\_educ}} & \multicolumn{1}{l}{The number of years of formal education of the woman} \\
\multicolumn{1}{l}{\textit{W\_exper}} & \multicolumn{1}{l}{The woman's work experience (in years)} \\
\multicolumn{1}{l}{\textit{Hus\_age}} & \multicolumn{1}{l}{The age (in years) of the woman's husband} \\
\multicolumn{1}{l}{\textit{Hus\_educ}} & \multicolumn{1}{l}{The number of years of formal education of the woman's husband} \\
\multicolumn{1}{l}{\textit{Hus\_inc}} & \multicolumn{1}{l}{The annual income (in \$'000s) of the woman's husband} \\
\multicolumn{1}{l}{\textit{faminc}} & \multicolumn{1}{l}{The annual income (in \$'000s) of the family unit} \\
\multicolumn{1}{l}{\textit{kids05}} & \multicolumn{1}{l}{The number of children under the age of 6} \\
\multicolumn{1}{l}{\textit{kids618}} & \multicolumn{1}{l}{The number of children aged between 6 and 18} \\
\multicolumn{1}{l}{\textit{largecity}} & \multicolumn{1}{l}{A dummy variable that takes the value of unity if the woman lives in a large city, and zero otherwise} \\
\multicolumn{1}{l}{\textit{W\_mothereduc}} & \multicolumn{1}{l}{The number of years of formal education of the woman's mother} \\
\multicolumn{1}{l}{\textit{W\_fathereduc}} & \multicolumn{1}{l}{The number of years of education of the woman's father} \\
\multicolumn{1}{l}{\textit{W\_motherworked}} & \multicolumn{1}{l}{A dummy variable that takes the value of unity if the woman's mother was herself a working mum, and zero otherwise} \\
\multicolumn{1}{l}{\textit{Hus\_mothereduc}} & \multicolumn{1}{l}{The number of years of formal education of the woman's husband's mother} \\
\multicolumn{1}{l}{\textit{Hus\_fathereduc}} & \multicolumn{1}{l}{The numbger of years education of the woman's husband's father} \\
\multicolumn{1}{l}{\textit{Hus\_motherworked}} & \multicolumn{1}{l}{A dummy variable that takes the value of unity if the woman's husband's mother was herself a working mum, and zero otherwise} \\
\bottomrule
\end{tabular}%
\label{tab:addlabel}%
\end{table}%
生成的结果表如下所示:
有什么解决方案吗?
答案1
\documentclass{article}
\usepackage{booktabs,tabularx}
\begin{document}
\noindent
\begin{tabularx}{\linewidth}{@{} >{\itshape}lX @{}}\toprule
\multicolumn{1}{c}{\textbf{Variable}} & \multicolumn{1}{c}{\textbf{Description}}\\ \midrule
W\_hours & The average number of hours worked each week by the respondent \\
W\_hours\_dummy & A dummy variable that takes the value of unity if the respondent works more than 0 hours each week, and zero otherwise \\
W\_age & The age (in years) of the woman \\
W\_educ & The number of years of formal education of the woman \\
W\_exper & The woman's work experience (in years) \\
Hus\_age & The age (in years) of the woman's husband \\
Hus\_educ & The number of years of formal education of the woman's husband \\
Hus\_inc & The annual income (in \$'000s) of the woman's husband \\
faminc & The annual income (in \$'000s) of the family unit \\
kids05 & The number of children under the age of 6 \\
kids618 & The number of children aged between 6 and 18 \\
largecity & A dummy variable that takes the value of unity if the woman lives in a large city, and zero otherwise \\
W\_mothereduc & The number of years of formal education of the woman's mother \\
W\_fathereduc & The number of years of education of the woman's father \\
W\_motherworked & A dummy variable that takes the value of unity if the woman's mother was herself a working mum, and zero otherwise \\
Hus\_mothereduc & The number of years of formal education of the woman's husband's mother \\
Hus\_fathereduc & The numbger of years education of the woman's husband's father \\
Hus\_motherworked & A dummy variable that takes the value of unity if the woman's husband's mother was herself a working mum, and zero otherwise \\\bottomrule
\end{tabularx}%
\end{document}