5

I have the following table:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{booktabs,array, caption,fixltx2e}
\usepackage[flushleft]{threeparttable}
\usepackage{tablefootnote}
\usepackage[margin=2cm]{geometry}% http://ctan.org/pkg/geometry
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}% raggedleft column X
\begin{document}
\begin{table}[htb!]
    \caption{Unit root tests}
    \label{tbl:unitroot}
    \renewcommand{\arraystretch}{1.2}%
    \begin{tabularx}{\textwidth}{l*{7}{Y}}
        \toprule
        \multicolumn{8}{l}{\textbf{Confidence Indicators}} \\
        \midrule
        Level & ADF & PP & KPSS& Differenced& ADF& PP& KPSS\\ 
        \hline
        Market & 360 & 101.77 & 10.71  & $\Delta$ Market & 360 & 101.77 & 10.71  \\ 
        (p-value) & 360 & 101.77 & 10.71 & (p-value) & 360 & 101.77 & 10.71  \\ 
        Manufacturing & 360 & -7.33 & 12.63  & $\Delta$ Manufacturing & 360 & 7.33 & 12.63  \\
        (p-value) & 360 & 101.77 & 10.71 & (p-value) & 360 & 101.77 & 10.71  \\
        Construction & 360 & -17.23 & 23.43  & $\Delta$ Retail trade & 360 & 3.40 & 13.84 \\
        (p-value) & 360 & 101.77 & 10.71& (p-value) & 360 & 101.77 & 10.71  \\  
        Services  & 216 & 3.99 & 19.19 & $\Delta$ Services  & 216 & 3.99 & 19.19  \\
        (p-value) & 360 & 101.77 & 10.71  & (p-value) & 360 & 101.77 & 10.71  \\  
        Consumer & 360 & -9.31 & 8.64  & $\Delta$ Consumer & 360 & -9.31 & 8.64  \\
        (p-value) & 360 & 101.77 & 10.71 & (p-value) & 360 & 101.77 & 10.71  \\  
    \end{tabularx}
    \begin{tabularx}{\linewidth}{l*{7}{Y}}
        \toprule
        \multicolumn{8}{l}{\textbf{Stock Returns}} \\
        \midrule
        Level & ADF & PP & KPSS& Differenced& ADF& PP& KPSS\\ 
        \hline
        Market & 360 & 101.77 & 10.71  & $\Delta$ Market & 360 & 101.77 & 10.71  \\ 
        (p-value) & 360 & 101.77 & 10.71 & (p-value) & 360 & 101.77 & 10.71  \\ 
        Manufacturing & 360 & -7.33 & 12.63  & $\Delta$ Manufacturing & 360 & 7.33 & 12.63  \\
        (p-value) & 360 & 101.77 & 10.71 & (p-value) & 360 & 101.77 & 10.71  \\
        Construction & 360 & -17.23 & 23.43  & $\Delta$ Retail trade & 360 & 3.40 & 13.84 \\
        (p-value) & 360 & 101.77 & 10.71& (p-value) & 360 & 101.77 & 10.71  \\  
        Services  & 216 & 3.99 & 19.19 & $\Delta$ Services  & 216 & 3.99 & 19.19  \\
        (p-value) & 360 & 101.77 & 10.71  & (p-value) & 360 & 101.77 & 10.71  \\  
        Consumer & 360 & -9.31 & 8.64  & $\Delta$ Consumer & 360 & -9.31 & 8.64  \\
        (p-value) & 360 & 101.77 & 10.71 & (p-value) & 360 & 101.77 & 10.71  \\  
        \hline
    \end{tabularx}
    \end{table}
\end{document}

enter image description here

I am interested in fitting the fifth column to its text. Just to look like the first column. I have tried to change some of the tabularx parameters but faild to do the desired output.

3 Answers 3

6

Don't use tabularx for numeric tables, it is designed to set the target width for line breaking within a cell.

If you just use tabular and r it all fits, you could improve with c for headings and other small improvements, but simply not using my code is the main improvement you need here,

enter image description here

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{booktabs,array, caption,fixltx2e}
\usepackage[flushleft]{threeparttable}
\usepackage{tablefootnote}
\usepackage[margin=2cm]{geometry}% http://ctan.org/pkg/geometry
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\newcolumntype{Y}{>{\raggedleft\arraybackslash}X}% raggedleft column X
\begin{document}
\begin{table}[htb!]
    \caption{Unit root tests}
    \label{tbl:unitroot}
    \renewcommand{\arraystretch}{1.2}%
    \begin{tabular}{l*{7}{r}}
        \toprule
        \multicolumn{8}{l}{\textbf{Confidence Indicators}} \\
        \midrule
        Level & ADF & PP & KPSS& Differenced& ADF& PP& KPSS\\ 
        \hline
        Market & 360 & 101.77 & 10.71  & $\Delta$ Market & 360 & 101.77 & 10.71  \\ 
        (p-value) & 360 & 101.77 & 10.71 & (p-value) & 360 & 101.77 & 10.71  \\ 
        Manufacturing & 360 & -7.33 & 12.63  & $\Delta$ Manufacturing & 360 & 7.33 & 12.63  \\
        (p-value) & 360 & 101.77 & 10.71 & (p-value) & 360 & 101.77 & 10.71  \\
        Construction & 360 & -17.23 & 23.43  & $\Delta$ Retail trade & 360 & 3.40 & 13.84 \\
        (p-value) & 360 & 101.77 & 10.71& (p-value) & 360 & 101.77 & 10.71  \\  
        Services  & 216 & 3.99 & 19.19 & $\Delta$ Services  & 216 & 3.99 & 19.19  \\
        (p-value) & 360 & 101.77 & 10.71  & (p-value) & 360 & 101.77 & 10.71  \\  
        Consumer & 360 & -9.31 & 8.64  & $\Delta$ Consumer & 360 & -9.31 & 8.64  \\
        (p-value) & 360 & 101.77 & 10.71 & (p-value) & 360 & 101.77 & 10.71  \\  
    \end{tabular}


    \begin{tabular}{l*{7}{l}}
        \toprule
        \multicolumn{8}{l}{\textbf{Stock Returns}} \\
        \midrule
        Level & ADF & PP & KPSS& Differenced& ADF& PP& KPSS\\ 
        \hline
        Market & 360 & 101.77 & 10.71  & $\Delta$ Market & 360 & 101.77 & 10.71  \\ 
        (p-value) & 360 & 101.77 & 10.71 & (p-value) & 360 & 101.77 & 10.71  \\ 
        Manufacturing & 360 & -7.33 & 12.63  & $\Delta$ Manufacturing & 360 & 7.33 & 12.63  \\
        (p-value) & 360 & 101.77 & 10.71 & (p-value) & 360 & 101.77 & 10.71  \\
        Construction & 360 & -17.23 & 23.43  & $\Delta$ Retail trade & 360 & 3.40 & 13.84 \\
        (p-value) & 360 & 101.77 & 10.71& (p-value) & 360 & 101.77 & 10.71  \\  
        Services  & 216 & 3.99 & 19.19 & $\Delta$ Services  & 216 & 3.99 & 19.19  \\
        (p-value) & 360 & 101.77 & 10.71  & (p-value) & 360 & 101.77 & 10.71  \\  
        Consumer & 360 & -9.31 & 8.64  & $\Delta$ Consumer & 360 & -9.31 & 8.64  \\
        (p-value) & 360 & 101.77 & 10.71 & (p-value) & 360 & 101.77 & 10.71  \\  
        \hline
    \end{tabular}
    \end{table}
\end{document}
2

For a table with numeric data, I recommend using siunitx. There's no need to artificially widen the table to cover all the textwidth (but you can use the tabular* form if you really need this).

The only tricky setting is in the third column, where a format -2.2 seems better (a minus sign is wider than a digit). The syntax is easy: - means a minus sign is present in some row, 2.2 means that the numbers have two digits in the integral part and two in the decimal part. Alignment at the decimal point is automatic. Note also that headers in the S columns must be braced.

I think it's also better to use a single table.

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{booktabs,array, caption,fixltx2e}
\usepackage[flushleft]{threeparttable}
\usepackage{tablefootnote}
\usepackage[margin=2cm]{geometry}

\usepackage{siunitx}

\begin{document}

\begin{table}[htb!]
\centering

\caption{Unit root tests} \label{tbl:unitroot}

\begin{tabular}{
  @{}
  l
  S[table-format=3.0]
  S[table-format=-2.2]
  S[table-format=2.2]
  l
  S[table-format=3.0]
  S[table-format=3.2]
  S[table-format=2.2]
  @{}
}
\toprule
\textit{Level} & {ADF} & {PP} & {KPSS} &
  \textit{Differenced} & {ADF} & {PP} & {KPSS} \\
\midrule
\multicolumn{8}{c}{\textbf{Confidence Indicators}} \\
\midrule
Market        & 360 & 101.77 & 10.71 & $\Delta$ Market        & 360 & 101.77 & 10.71 \\
(p-value)     & 360 & 101.77 & 10.71 & (p-value)              & 360 & 101.77 & 10.71 \\
\addlinespace
Manufacturing & 360 &  -7.33 & 12.63 & $\Delta$ Manufacturing & 360 &   7.33 & 12.63 \\
(p-value)     & 360 & 101.77 & 10.71 & (p-value)              & 360 & 101.77 & 10.71 \\
\addlinespace
Construction  & 360 & -17.23 & 23.43 & $\Delta$ Retail trade  & 360 &   3.40 & 13.84 \\
(p-value)     & 360 & 101.77 & 10.71 & (p-value)              & 360 & 101.77 & 10.71 \\
\addlinespace
Services      & 216 &   3.99 & 19.19 & $\Delta$ Services      & 216 &   3.99 & 19.19 \\
(p-value)     & 360 & 101.77 & 10.71 & (p-value)              & 360 & 101.77 & 10.71 \\
\addlinespace
Consumer      & 360 &  -9.31 &  8.64 & $\Delta$ Consumer      & 360 &  -9.31 &  8.64 \\
(p-value)     & 360 & 101.77 & 10.71 & (p-value)              & 360 & 101.77 & 10.71 \\
\midrule[\heavyrulewidth]
\multicolumn{8}{c}{\textbf{Stock Returns}} \\
\midrule
Market        & 360 & 101.77 & 10.71 & $\Delta$ Market        & 360 & 101.77 & 10.71 \\
(p-value)     & 360 & 101.77 & 10.71 & (p-value)              & 360 & 101.77 & 10.71 \\
\addlinespace
Manufacturing & 360 &  -7.33 & 12.63 & $\Delta$ Manufacturing & 360 &   7.33 & 12.63 \\
(p-value)     & 360 & 101.77 & 10.71 & (p-value)              & 360 & 101.77 & 10.71 \\
\addlinespace
Construction  & 360 & -17.23 & 23.43 & $\Delta$ Retail trade  & 360 &   3.40 & 13.84 \\
(p-value)     & 360 & 101.77 & 10.71 & (p-value)              & 360 & 101.77 & 10.71 \\
\addlinespace
Services      & 216 &   3.99 & 19.19 & $\Delta$ Services      & 216 &   3.99 & 19.19 \\
(p-value)     & 360 & 101.77 & 10.71 & (p-value)              & 360 & 101.77 & 10.71 \\
\addlinespace
Consumer      & 360 &  -9.31 &  8.64 & $\Delta$ Consumer      & 360 &  -9.31 &  8.64 \\
(p-value)     & 360 & 101.77 & 10.71 & (p-value)              & 360 & 101.77 & 10.71 \\
\bottomrule
\end{tabular}

\end{table}
\end{document}

enter image description here

2

I would remove one column from the table entirely, and I would restructure the header so as to make clear to the reader how the report's tests are organized. I would also use the dcolumn package to align the numeric entries on the respective decimal points. To make the tabular material span the width of the text block, consider using a tabular* environment.

Aside: As a time series econometrician, I immediately noticed that the "P" in "KPSS", as well as the first "P" in "PP", denote the first initial of my doctoral adviser's name -- "Phillips". :-)

enter image description here

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{booktabs,array, caption,fixltx2e}
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{.}{#1}}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}}
\usepackage[margin=2cm]{geometry}% 
\begin{document}
\begin{table}[htb!]
    \caption{Unit root tests}
    \label{tbl:unitroot}
    \renewcommand{\arraystretch}{1.2}
    \setlength\tabcolsep{0pt}
    \begin{tabular*}{\textwidth}{@{}
           l @{\extracolsep{\fill}} c *{2}{d{3.2}} c *{2}{d{3.2}} @{} }
        \toprule
        Variable & \multicolumn{3}{c}{Level} & \multicolumn{3}{c}{Differenced}\\
        \cmidrule{2-4} \cmidrule{5-7}
        & \mc{ADF} & \mc{PP} & \mc{KPSS} 
        & \mc{ADF} & \mc{PP} & \mc{KPSS}\\ 
        \midrule
        \addlinespace
        \multicolumn{7}{l}{\textbf{Confidence Indicators}} \\[0.5ex]
        Market & 360 & 101.77 & 10.71  &  360 & 101.77 & 10.71  \\ 
        (p-value) & 360 & 101.77 & 10.71 &  360 & 101.77 & 10.71  \\ 
        Manufacturing & 360 & -7.33 & 12.63  &  360 & 7.33 & 12.63  \\
        (p-value) & 360 & 101.77 & 10.71 &  360 & 101.77 & 10.71  \\
        Construction & 360 & -17.23 & 23.43  &  360 & 3.40 & 13.84 \\
        (p-value) & 360 & 101.77 & 10.71&  360 & 101.77 & 10.71  \\  
        Services  & 216 & 3.99 & 19.19 &  216 & 3.99 & 19.19  \\
        (p-value) & 360 & 101.77 & 10.71  &  360 & 101.77 & 10.71  \\  
        Consumer & 360 & -9.31 & 8.64  &  360 & -9.31 & 8.64  \\
        (p-value) & 360 & 101.77 & 10.71 &  360 & 101.77 & 10.71  \\[2ex]
        \multicolumn{7}{l}{\textbf{Stock Returns}} \\[0.5ex]
        Market & 360 & 101.77 & 10.71  &  360 & 101.77 & 10.71  \\ 
        (p-value) & 360 & 101.77 & 10.71 &  360 & 101.77 & 10.71  \\ 
        Manufacturing & 360 & -7.33 & 12.63  &  360 & 7.33 & 12.63  \\
        (p-value) & 360 & 101.77 & 10.71 &  360 & 101.77 & 10.71  \\
        Construction & 360 & -17.23 & 23.43  &  360 & 3.40 & 13.84 \\
        (p-value) & 360 & 101.77 & 10.71&  360 & 101.77 & 10.71  \\  
        Services  & 216 & 3.99 & 19.19 &  216 & 3.99 & 19.19  \\
        (p-value) & 360 & 101.77 & 10.71  &  360 & 101.77 & 10.71  \\  
        Consumer & 360 & -9.31 & 8.64  &  360 & -9.31 & 8.64  \\
        (p-value) & 360 & 101.77 & 10.71 &  360 & 101.77 & 10.71  \\  
        \bottomrule
    \end{tabular*}
    \end{table}
\end{document}
1
  • That is a better structure.
    – mallet
    May 1, 2015 at 8:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .