# Row lines in table too long

I created a table with the following code:

\documentclass[12 pt,Times New Roman] {article}

\usepackage[utf8]{inputenc}
\usepackage { amsmath }
\usepackage{setspace}
\setstretch{1.5}

\usepackage{hyperref}
\usepackage[toc,page]{appendix}

\usepackage[a4paper,lmargin={2.5cm},rmargin={2.5cm},
tmargin={2.5cm},bmargin = {2.5cm}]{geometry}

\usepackage{caption}
\usepackage{booktabs}

\usepackage{fancyhdr}
\pagestyle{fancy}
\lfoot{}
\cfoot{}
\rfoot{}
\sloppy

\begin{document}
\begin{table}[h!]

\selectfont\centering

\caption[Caption]{Caption}
\begin{tabular}{p{1cm} p{1cm} p{1cm} p{1cm} p{1cm}  c c c c c}

\hline\hline

&      title     &     title     &       title       &   title    \\
\hline
A           &       1.2      &       2.3     &       5.6\sym{**} &    4        \\
&      (5.06)    &      (5.56)   &      (3.42)       &  (0.59)         \\
[1em]
B           &  -9.87\sym{*}  & -9.63\sym{*}  &      0.58         & 1.98\sym{***}\\
&      (5.07)    &      (5.66)   &      (3.58)       &      (0.59)         \\

\hline
Adjusted $$R^{2}$$  &      ...        &       ...        &       ...         &       ...         \\
\hline\hline
\multicolumn{5}{l}{\footnotesize Robust standard errors in parentheses, \sym{*} $$p<0.10$$, \sym{**} $$p<0.05$$, \sym{***} $$p<0.01$$}\\
\multicolumn{5}{p{\ylength}}{\footnotesize note note note}\\
\\
\end{tabular}
\end{table}
\end{document}


The problem is that the table has the same width as the text and therefore the lines of the rows are too long. Any help is appreciated.

• Welcome to TX.SX. Would you mind to convert the snippet into a complete minimal working example which could be compiled? Start from \documentclass and finish at \end{document}, including all important packages and definitions. – Ignasi Oct 24 '16 at 10:17
• I have now included everything – eandj Oct 24 '16 at 11:22
• Undefined control sequence \sym and \ylength – Salim Bou Oct 24 '16 at 11:27
• I think you have removed too much (e.g. what is \sym?). Apart from that, you are declaring ten columns but you use only five of them. – campa Oct 24 '16 at 11:28
• article doesn't have a Times New Roman option, and 12 pt only works by accident (the option name is 12pt) – David Carlisle Oct 24 '16 at 12:08

\documentclass[12pt] {article}
\usepackage[a4paper,margin=2.5cm]{geometry}

\usepackage[utf8]{inputenc}
\usepackage {amsmath}
\usepackage{setspace}
\setstretch{1.5}

\usepackage{caption}
\usepackage{calc}
\usepackage{booktabs,tabularx}
\newlength\mylength
\setlength\mylength{0.5\textwidth}
\newcommand\mcp[1]{\multicolumn{5}{p{\mylength-2\tabcolsep}}{\footnotesize #1}}

\usepackage{showframe}
\renewcommand*\ShowFrameColor{\color{red}}

\begin{document}
\begin{table}[htb]
\centering
\setlength\tabcolsep{4pt}
\caption[Caption]{Caption}
\label{my table}
\begin{tabularx}{\mylength}{l X X X X}
\toprule
&   title   &   title   &   title   &   title       \\
\midrule
A       &   1.2     &   2.3     &   5.6{**} &   4           \\
&   (5.06)  &   (5.56)  &   (3.42)  &  (0.59)       \\  [1em]
B       &  -9.87{*} &  -9.63{*} &   0.58    &  1.98{***}    \\
&   (5.07)  &   (5.66)  &   (3.58)  &  (0.59)       \\
\midrule
Adjusted $$R^{2}$$
&   ...     &   ...     &   ...     &  ...          \\
\midrule
\mcp{Robust standard errors in parentheses,
{*} $$p<0.10$$, {**} $$p<0.05$$, {***} $$p<0.01$$}      \\
\mcp{note note note}                                        \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}