I have been working with tables spanned over multiple pages as well as I want "x" functionality as well. I have been successfully working with tabularx (along with threeparttable) for now. It seems to me that there isn't any table type which one can do using one package can't be done using another package. So, can we just assume that tabularx and ltablex can replace each other and there is no advantages one offer over another? I am inquisitive what are the pros and cons of one package over another. Any insightful comments would be appreciated.
[Tex/LaTex] tabularx vs ltablex
ltablextabularx
Related Solutions
Actually, ltablex
doesn't work exactly like tabularx
: the calculated size of the X
columns is a maximum width for this column, its actual width depending on its actual content. If you don't want it, use the \keepXColumns
directive.
However, I would rather load siunitx
and use the the S
column type, to get a correct alignment of numerical values on the decimal dot. I need a little hack to get the column heads centred, as some heads are wider than what's required for the numerical values.
Also, I inserted the caption inside the first head (just like for long tables). Here's the result, with the first column of type X
, without the directive:
\documentclass[11pt]{article}
\usepackage{setspace,amssymb,amsmath}
\usepackage[tablename=TABLE,labelsep=newline,
aboveskip=0pt,font=bf,justification=centering]{caption}
\usepackage{booktabs,tabularx}
\usepackage[margin=1in, showframe]{geometry}
\usepackage[autostyle]{csquotes}
\usepackage[table]{xcolor}
\usepackage{ltablex}
\usepackage{siunitx} \newcolumntype{Y}{>{\centering\arraybackslash}X}
\newcommand{\gmc}[3]{\multicolumn{#1}{@{}#2@{}}{#3}}
\doublespacing
\begin{document}
\newpage
\begingroup % keep any font size changes local to group
%\captionof{table}{Descriptive Statistics}
\singlespacing
\small
\setlength\tabcolsep{10pt} %default
%%\renewcommand{\arraystretch}{0.95}
%\keepXColumns
\begin{tabularx}{\linewidth}{@{}X*{2}{S[table-format =-1.3]}S[table-format =1.3]*{2}{S[table-format =-1.3]}@{\enspace}}
\caption{Descriptive Statistics}\\
\addlinespace
\toprule
& {Mean} & {Median} & {\makebox[0pt]{Std. Dev.}} & {\makebox[0pt]{25th Pctl}} & {\makebox[0pt]{75th Pctl}} \\\midrule
\endfirsthead
\toprule
& {Mean} & {Median} & {\makebox[0pt]{Std. Dev.}} & {\makebox[0pt]{25th Pctl}} & {\makebox[0pt]{75th Pctl}} \\\midrule
\endhead
\midrule
\endfoot
\bottomrule
\\
\endlastfoot
$\Delta \text{RealEstate}\textsubscript{region} = 1 $ & 0.004 & 0.003 & 0.010 & -0.003 & 0.010 \\
$\Delta \text{RealEstate}\textsubscript{region} = 2 $ &0.002& 0.003& 0.013& -0.002& 0.008 \\
$\Delta \text{RealEstate}\textsubscript{region} = 3 $ &0.003& 0.003& 0.012& -0.001& 0.009 \\
$\Delta \text{RealEstate}\textsubscript{region} = 4 $ & 0.002& 0.003& 0.009& -0.002& 0.007\\
$\Delta \text{RealEstate}\textsubscript{region} = 5 $ & 0.005& 0.005& 0.011& -0.002& 0.012\\
$\Delta \text{RealEstate}\textsubscript{region} = 6 $ & 0.005& 0.005& 0.013& -0.002& 0.012\\
$\Delta \text{RealEstate}\textsubscript{region} = 7 $ & 0.004& 0.004& 0.008& 0.000& 0.009\\
$\Delta \text{RealEstate}\textsubscript{region} = 8 $ & 0.003& 0.004& 0.011& -0.001& 0.009\\
$\Delta \text{RealEstate}\textsubscript{region} = 9 $ & 0.004& 0.003& 0.010& -0.003& 0.011\\
$\Delta \text{RealEstate}\textsubscript{region} = 10 $ & 0.002& 0.003& 0.006& -0.001& 0.006\\
$\Delta \text{RealEstate}\textsubscript{region} = 11 $ & 0.004& 0.004& 0.009& 0.000& 0.009\\
$\Delta \text{RealEstate}\textsubscript{region} = 12 $ & 0.004& 0.004& 0.010& -0.001& 0.009\\
$\Delta \text{RealEstate}\textsubscript{region} = 13 $ & 0.003& 0.004& 0.013& 0.000& 0.007\\
$\Delta \text{RealEstate}\textsubscript{region} = 14 $ & 0.004& 0.005& 0.011& -0.002& 0.011\\
$\Delta \text{RealEstate}\textsubscript{region} = 15 $ & 0.002& 0.002& 0.009& -0.002& 0.007\\
$\Delta \text{RealEstate}\textsubscript{region} = 16 $ & 0.004& 0.004& 0.010& 0.000& 0.010\\
$\Delta \text{RealEstate}\textsubscript{region} = 17 $ & 0.002& 0.002& 0.010& -0.002& 0.007\\
$\Delta \text{RealEstate}\textsubscript{region} = 18 $ & 0.002& 0.003& 0.011& 0.000& 0.006\\
$\Delta \text{RealEstate}\textsubscript{region} = 19 $ & 0.002& 0.003& 0.014& -0.002& 0.008\\
$\Delta \text{RealEstate}\textsubscript{region} = 20 $ & 0.004& 0.004& 0.012& -0.002& 0.011\\
$\Delta \text{RealEstate}\textsubscript{region} = 21 $ & 0.003& 0.006& 0.011& -0.002& 0.010\\
$\Delta \text{RealEstate}\textsubscript{region} = 22 $ & 0.003& 0.004& 0.009& -0.002& 0.010\\
$\Delta \text{Prof}$& 0.000& 0.001& 0.020& -0.006& 0.008\\
RETURN& 0.020& 0.022& 0.071& -0.019& 0.065\\
GDP& 0.024& 0.025& 0.032& 0.013& 0.042\\
TBILL& 0.057& 0.056& 0.036& 0.033& 0.079\\
INFLATION& 0.043& 0.035& 0.035& 0.024& 0.057\\
CORP& 0.101& 0.067& 0.243& -0.068& 0.222\\
TERM& -0.012& -0.013& 0.012& -0.020& -0.003\\
$\Delta \text{Prof}\textsubscript{region} = 1 $ & 0.002& 0.003& 0.028& -0.008& 0.014\\
$\Delta \text{Prof}\textsubscript{region} = 2 $ & -0.001& 0.000& 0.030& -0.013& 0.014\\
$\Delta \text{Prof}\textsubscript{region} = 3 $ & 0.001& 0.002& 0.042& -0.009& 0.014\\
$\Delta \text{Prof}\textsubscript{region} = 4 $ & 0.000& 0.001& 0.021& -0.008& 0.011\\
$\Delta \text{Prof}\textsubscript{region} = 5 $ & 0.011& 0.007& 0.066& -0.014& 0.043\\
$\Delta \text{Prof}\textsubscript{region} = 6 $ & 0.009& 0.006& 0.035& -0.009& 0.027\\
$\Delta \text{Prof}\textsubscript{region} = 7 $ & -0.001& 0.001& 0.066& -0.028& 0.026\\
$\Delta \text{Prof}\textsubscript{region} = 8 $ & 0.002& 0.000& 0.027& -0.008& 0.007\\
$\Delta \text{Prof}\textsubscript{region} = 9 $ & -0.001& 0.001& 0.035& -0.011& 0.013\\
$\Delta \text{Prof}\textsubscript{region} = 10 $ & -0.002& 0.000& 0.043& -0.010& 0.015\\
$\Delta \text{Prof}\textsubscript{region} = 11 $ & -0.002& 0.000& 0.030& -0.017& 0.015\\
$\Delta \text{Prof}\textsubscript{region} = 12 $ & 0.006& 0.007& 0.052& -0.022& 0.029\\
$\Delta \text{Prof}\textsubscript{region} = 13 $ & 0.004& 0.000& 0.291& -0.020& 0.020\\
$\Delta \text{Prof}\textsubscript{region} = 14 $ & 0.002& 0.004& 0.021& -0.010& 0.015\\
$\Delta \text{Prof}\textsubscript{region} = 15 $ & -0.003& 0.001& 0.039& -0.014& 0.012\\
$\Delta \text{Prof}\textsubscript{region} = 16 $ & 0.000& 0.000& 0.026& -0.013& 0.016\\
$\Delta \text{Prof}\textsubscript{region} = 17 $ & -0.003& 0.001& 0.040& -0.008& 0.012\\
$\Delta \text{Prof}\textsubscript{region} = 18 $ & -0.007& -0.002& 0.046& -0.010& 0.006\\
$\Delta \text{Prof}\textsubscript{region} = 19 $ & 0.010& 0.008& 0.083& -0.015& 0.028\\
$\Delta \text{Prof}\textsubscript{region} = 20 $ & 0.000& 0.002& 0.029& -0.009& 0.012\\
$\Delta \text{Prof}\textsubscript{region} = 21 $ & 0.002& 0.003& 0.028& -0.008& 0.014\\
$\Delta \text{Prof}\textsubscript{region} = 22 $ & 0.002& 0.003& 0.021& -0.007& 0.011
\end{tabularx}
\newpage
\small \hrule\medskip
Notes: The table provides descriptive statistics for key variables. $\Delta \text{RealEstate}\textsubscript{region}$ = x is month-over-month real estate price change on the real estate region x index. $\Delta Prof_{region}$ = x is quarterly accounting profitability change for region x, and $\Delta Prof$ is the quarterly accounting profitability change over all firms in the economy. The regional classification is as follows: region 1 = DC-Washington; region 2 = MI-Detroit; region 3 = MN-Minneapolis; region 4 = OH-Cleveland; region 5 = CA-San Diego; region 6 = CA-San Francisco; region 7 = CO-Denver; region 8 = IL-Chicago; region 9 = MA-Boston; region 10 = NC-Charlotte; region 11 = OR-Portland; region 12 = WA-Seattle; region 13 = AZ-Phoenix; region 14 = CA-Los Angeles; region 15 = TX-Dallas; region 16 = FL-Miami; region 17 = FL-Tampa; region 18 = GA-Atlanta; region 19 = NV-Las Vegas; region 20 = NY-New York; region 21 = 20-city composite; region 22 = 10-city composite. RETURN is the quarterly buy-and-hold return on the stock market index (i.e., the S\&P Stock Composite Index); GDP is the quarterly realization of GDP growth in real terms; TBILL is the yield on the one-year constant maturity Treasury bill; INFLATION is based on the realization of the consumer price index for the quarter; CORP is quarterly growth in corporate profits calculated by the Bureau of Economic Analysis; TERM is the yield on the ten-year constant maturity Treasury bond minus the yield on the one-year constant maturity Treasury bill. To develop measures of regional accounting profitability changes, I sort firms into regions based on the location of their headquarters. Using firms in each region, I construct quarterly indices of regional accounting profitability changes based on earnings reports available in real time. I measure accounting profit for firm $i$ in quarter $q$ ($Prof_{i,q}$) as scaled quarterly operating income before depreciation. I measure accounting profitability change ($\Delta Prof_{i,q}$) as the year-over-year change in $Prof_{i,q}$. To mitigate the effects of outliers, I trim a firm's profits and profit changes based on the top and bottom one percentile of each quarterly cross-section. To avoid negative denominator problems, I scale profits by sales. Regional quarterly time series of profits (Prof) and profit changes ($\Delta Prof$) are based on value-weighted cross-sectional averages, with weights based on market value of equity as of the beginning of each quarter. For a firm-quarter to be included in the sample it must have nonmissing values for market value of equity, $\Delta Prof_{i,q}$, and the quarterly earnings announcement date. Accounting variables are from the Compustat North America Fundamentals Quarterly File (WRDS: FUNDQ) available from WRDS. Treasury bond and bill yields from the Federal Reserve Board of Governors H15 Report; and GDP, inflation, and corporate profits from the Philadelphia's Fed Real-Time Data Research Center, where these Fed's data are quarterly and stated in annual rates. Case-Shiller Home Price Indices are from the S\&P Dow Jones Indices website. The analyses throughout employ varying samples, to allow for feasible information flows and following the Case-Shiller coverage of the housing data that vary by regions. Specifically, following the Case-Shiller coverage, real estate price changes include 182 to 518 observations depending on the region. In terms of alignment with accounting data, analyses of stock investment strategies use observations as reported in the related table. For analyses predicting future real estate price changes I calculate regional accounting profitability changes using quarterly accounting observations over the period from Q4:1972 to Q4:2014 (n = 168 quarters).
\medskip
\hrule
\endgroup
\end{document}
I'd suggest the following layout based on longtable
and booktabs
. With some abbreviations in the column headers there is no need to use \footnotesize
d text or to turn the table to landscape. I have also removed all vertical lines and replaced the horizontal lines by lines and some vertical white spaces from the booktabs
package that you already load. I have also made use of the \endhead
and \endfirsthead
commands from the longtable
package in order to repeat column headers on all pages.
\documentclass[12pt,a4paper,headsepline,oneside,appendixprefix]{scrbook}
\usepackage{booktabs}
\usepackage{geometry}
\usepackage{longtable}
\usepackage{pdflscape}
\begin{document}
\pagestyle{empty}
\pagenumbering{alph}
\mainmatter
\begin{longtable}{cccccccc}
\caption{caption.}\\
\toprule
\multicolumn{2}{c}{Avg. F1} & \multicolumn{2}{c}{Avg. Recall} & \multicolumn{2}{c}{Avg. Precision} & Gap between F1 \\ \cmidrule(r){1-2} \cmidrule(lr){3-4} \cmidrule(lr){5-6}
Train. & Valid. & Train. & Valid. & Train. & Valid. & Train. \& Valid. \\
\midrule
\endfirsthead
\caption{caption. - continued from previous page}\\
\toprule
\multicolumn{2}{c}{Avg. F1} & \multicolumn{2}{c}{Avg. Recall} & \multicolumn{2}{c}{Avg. Precision} & Gap between F1 \\ \cmidrule(r){1-2} \cmidrule(lr){3-4} \cmidrule(lr){5-6}
Train. & Valid. & Train. & Valid. & Train. & Valid. & Train. \& Valid. \\
\midrule
\endhead
0.97& 0.91& 0.95& 0.88& 0.99& 0.95& 0.06\\
0.99& 0.94& 0.98& 0.91& 1.00& 0.96& 0.05\\
0.98& 0.93& 0.97& 0.90& 0.99& 0.95& 0.05\\
0.97& 0.92& 0.95& 0.89& 0.99& 0.95& 0.05\\
0.98& 0.93& 0.96& 0.91& 0.99& 0.95& 0.05\\ \addlinespace
0.92& 0.87& 0.88& 0.82& 0.97& 0.94& 0.05\\
0.98& 0.93& 0.97& 0.91& 0.99& 0.95& 0.05\\
0.98& 0.93& 0.97& 0.91& 0.99& 0.96& 0.05\\
0.98& 0.93& 0.97& 0.91& 0.99& 0.96& 0.05\\
0.98& 0.93& 0.97& 0.91& 0.99& 0.96& 0.05\\ \addlinespace
0.98& 0.93& 0.97& 0.91& 0.99& 0.96& 0.05\\
0.98& 0.93& 0.97& 0.91& 0.99& 0.96& 0.05\\
0.98& 0.93& 0.97& 0.91& 0.99& 0.96& 0.05\\
0.98& 0.93& 0.96& 0.91& 0.99& 0.95& 0.05\\
0.98& 0.93& 0.96& 0.91& 0.99& 0.95& 0.05\\ \addlinespace
0.98& 0.93& 0.96& 0.91& 0.99& 0.95& 0.05\\
0.97& 0.92& 0.95& 0.89& 0.99& 0.96& 0.05\\
0.98& 0.93& 0.96& 0.91& 0.99& 0.95& 0.05\\
0.98& 0.93& 0.96& 0.91& 0.99& 0.96& 0.05\\
0.97& 0.93& 0.96& 0.91& 0.99& 0.95& 0.04\\ \addlinespace
0.97& 0.93& 0.96& 0.91& 0.99& 0.95& 0.04\\
0.97& 0.93& 0.96& 0.91& 0.99& 0.96& 0.04\\
0.92& 0.88& 0.89& 0.83& 0.96& 0.93& 0.04\\
0.97& 0.93& 0.95& 0.90& 0.99& 0.95& 0.04\\
0.96& 0.92& 0.94& 0.89& 0.98& 0.95& 0.04\\ \addlinespace
0.97& 0.92& 0.95& 0.90& 0.98& 0.95& 0.04\\
0.97& 0.93& 0.95& 0.90& 0.99& 0.95& 0.04\\
0.97& 0.93& 0.95& 0.90& 0.99& 0.95& 0.04\\
0.97& 0.93& 0.95& 0.90& 0.99& 0.95& 0.04\\
0.97& 0.93& 0.95& 0.91& 0.99& 0.96& 0.04\\ \addlinespace
0.96& 0.92& 0.94& 0.90& 0.98& 0.94& 0.04\\
0.97& 0.93& 0.95& 0.91& 0.99& 0.96& 0.04\\
0.97& 0.93& 0.95& 0.90& 0.98& 0.95& 0.04\\
0.96& 0.93& 0.94& 0.90& 0.98& 0.95& 0.04\\
0.77& 0.73& 0.67& 0.63& 0.91& 0.88& 0.04\\ \addlinespace
0.96& 0.92& 0.93& 0.89& 0.98& 0.95& 0.04\\
0.95& 0.92& 0.93& 0.89& 0.98& 0.95& 0.03\\
0.96& 0.93& 0.94& 0.90& 0.98& 0.95& 0.03\\
0.95& 0.92& 0.93& 0.89& 0.97& 0.95& 0.03\\
0.95& 0.92& 0.92& 0.88& 0.98& 0.95& 0.03\\ \addlinespace
0.96& 0.92& 0.93& 0.90& 0.98& 0.95& 0.03\\
0.96& 0.92& 0.93& 0.90& 0.98& 0.95& 0.03\\
0.90& 0.87& 0.87& 0.83& 0.94& 0.92& 0.03\\
0.96& 0.93& 0.93& 0.90& 0.98& 0.96& 0.03\\
0.93& 0.90& 0.90& 0.86& 0.97& 0.95& 0.03\\ \addlinespace
0.94& 0.91& 0.91& 0.88& 0.97& 0.95& 0.03\\
0.95& 0.93& 0.93& 0.90& 0.98& 0.95& 0.03\\
0.95& 0.92& 0.92& 0.89& 0.97& 0.95& 0.03\\
0.95& 0.92& 0.93& 0.90& 0.97& 0.94& 0.03\\
0.93& 0.90& 0.89& 0.86& 0.97& 0.95& 0.03\\ \addlinespace
0.95& 0.92& 0.92& 0.90& 0.97& 0.95& 0.03\\
0.95& 0.92& 0.92& 0.89& 0.97& 0.95& 0.03\\
0.92& 0.89& 0.88& 0.85& 0.95& 0.93& 0.03\\
0.94& 0.92& 0.92& 0.89& 0.97& 0.95& 0.03\\
0.87& 0.84& 0.81& 0.78& 0.94& 0.92& 0.02\\ \addlinespace
0.95& 0.92& 0.92& 0.90& 0.97& 0.95& 0.02\\
0.93& 0.90& 0.90& 0.87& 0.96& 0.94& 0.02\\
0.93& 0.91& 0.91& 0.88& 0.96& 0.94& 0.02\\
0.94& 0.91& 0.91& 0.89& 0.96& 0.94& 0.02\\
0.92& 0.90& 0.89& 0.87& 0.96& 0.94& 0.02\\ \addlinespace
0.93& 0.91& 0.91& 0.89& 0.96& 0.94& 0.02\\
0.88& 0.87& 0.85& 0.82& 0.93& 0.91& 0.02\\
0.93& 0.91& 0.90& 0.88& 0.96& 0.94& 0.02\\
0.93& 0.91& 0.90& 0.88& 0.96& 0.95& 0.02\\
0.89& 0.87& 0.84& 0.82& 0.94& 0.93& 0.02\\ \addlinespace
0.72& 0.70& 0.61& 0.59& 0.88& 0.86& 0.02\\
0.89& 0.87& 0.84& 0.82& 0.94& 0.93& 0.02\\
0.88& 0.86& 0.82& 0.81& 0.94& 0.93& 0.01\\
0.91& 0.90& 0.88& 0.86& 0.95& 0.93& 0.01\\
0.88& 0.87& 0.84& 0.82& 0.94& 0.93& 0.01\\ \addlinespace
0.85& 0.84& 0.80& 0.78& 0.92& 0.91& 0.01\\
0.88& 0.87& 0.84& 0.83& 0.93& 0.92& 0.01\\
0.88& 0.87& 0.84& 0.83& 0.93& 0.92& 0.01\\
0.88& 0.86& 0.83& 0.82& 0.93& 0.92& 0.01\\
0.87& 0.86& 0.83& 0.81& 0.93& 0.92& 0.01\\ \addlinespace
0.84& 0.83& 0.78& 0.77& 0.91& 0.90& 0.01\\
0.75& 0.74& 0.70& 0.69& 0.82& 0.81& 0.01\\
0.74& 0.74& 0.67& 0.67& 0.84& 0.83& 0.01\\
0.79& 0.78& 0.72& 0.71& 0.87& 0.86& 0.01\\
0.78& 0.78& 0.71& 0.70& 0.88& 0.88& 0.01\\ \addlinespace
0.75& 0.75& 0.66& 0.66& 0.88& 0.88& 0.00\\
0.74& 0.73& 0.65& 0.65& 0.85& 0.85& 0.00\\
0.62& 0.62& 0.54& 0.54& 0.73& 0.73& 0.00\\
0.74& 0.74& 0.65& 0.65& 0.86& 0.86& 0.00\\
0.70& 0.70& 0.61& 0.61& 0.82& 0.82& 0.00\\ \addlinespace
0.63& 0.63& 0.54& 0.54& 0.76& 0.76& 0.00\\
0.63& 0.63& 0.55& 0.55& 0.73& 0.73& 0.00\\
0.62& 0.62& 0.55& 0.55& 0.70& 0.70& 0.00\\
0.68& 0.68& 0.60& 0.60& 0.77& 0.77& 0.00\\
0.65& 0.65& 0.55& 0.55& 0.79& 0.79& 0.00\\ \addlinespace
0.64& 0.64& 0.54& 0.54& 0.78& 0.78& 0.00\\
0.69& 0.69& 0.60& 0.60& 0.82& 0.82& 0.00\\
0.00& 0.00& 0.00& 0.00& 0.00& 0.00& 0.00\\
0.00& 0.00& 0.00& 0.00& 0.00& 0.00& 0.00\\
0.00& 0.00& 0.00& 0.00& 0.00& 0.00& 0.00\\ \addlinespace
0.00& 0.00& 0.00& 0.00& 0.00& 0.00& 0.00\\
0.00& 0.00& 0.00& 0.00& 0.00& 0.00& 0.00\\
0.00& 0.00& 0.00& 0.00& 0.00& 0.00& 0.00\\
0.00& 0.00& 0.00& 0.00& 0.00& 0.00& 0.00\\
0.00& 0.00& 0.00& 0.00& 0.00& 0.00& 0.00\\
\end{longtable}
\end{document}
Best Answer
The
X
functionality inltablex
is implemented bytabularx
and the multipage functionality inltablex
is implemented bylongtable
.ltablex
just includes both packages and supplies a bit of glue so they work better together.