Tengo la siguiente tabla:
\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}
Me interesa ajustar la quinta columna a su texto. Sólo para parecerse a la primera columna. Intenté cambiar algunos de los tabularx
parámetros pero no logré obtener el resultado deseado.
Respuesta1
No lo use tabularx
para tablas numéricas, está diseñado para establecer el ancho objetivo parasalto de líneadentro de una celda.
Si solo lo usas tabular
y r
todo encaja, podrías mejorar con c
encabezados y otras pequeñas mejoras, pero simplemente no usar mi código es la principal mejora que necesitas aquí.
\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}
Respuesta2
Para una tabla con datos numéricos, recomiendo usar siunitx
. No es necesario ampliar artificialmente la tabla para cubrir todo el ancho del texto (pero puedes usar el tabular*
formulario si realmente lo necesitas).
La única configuración complicada está en la tercera columna, donde el formato -2.2
parece mejor (un signo menos es más ancho que un dígito). La sintaxis es sencilla: -
significa que hay un signo menos en alguna fila, 2.2
significa que los números tienen dos dígitos en la parte integral y dos en la parte decimal. La alineación en el punto decimal es automática. Tenga en cuenta también que los encabezados de las columnas S deben estar entre llaves.
Creo que también es mejor usar una sola mesa.
\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}
Respuesta3
Quitaría completamente una columna de la tabla y reestructuraría el encabezado para dejar claro al lector cómo están organizadas las pruebas del informe. También usaría el dcolumn
paquete para alinear las entradas numéricas con los respectivos puntos decimales. Para que el material tabular abarque todo el ancho del bloque de texto, considere utilizar un tabular*
entorno.
Aparte: como econometrista de series temporales, inmediatamente noté que la "P" en "KPSS", así como la primera "P" en "PP", denotan la primera inicial del nombre de mi asesor doctoral: "Phillips". :-)
\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}