1

I am having the problem of fitting a latex table to my document:

\begin{longtable}{|p{2cm}|p{2cm}|l|l|l|p{2cm}|l|l|}
\hline
\textbf{}                         & {\ul \textbf{oenb\_dependent}} & {\ul \textbf{carReg}} & {\ul \textbf{cpi}} & {\ul \textbf{primConstTot}} & {\ul \textbf{resProp.Dwell}} & {\ul \textbf{cbre.office.primeYield}} & {\ul \textbf{cbre.retail.capitalValue}} \\ \hline
\textit{Number of Values}         & 57,00                          & 57,00                 & 57,00              & 57,00                       & 57,00                        & 57,00                                 & 57,00                                   \\ \hline
\textit{Number of Missing Values} & 0,00                           & 0,00                  & 0,00               & 0,00                        & 0,00                         & 0,00                                  & 0,00                                    \\ \hline
\textit{Min}                      & -9,23                          & -27,11                & -5,38              & -3,36                       & -12,10                       & -1,00                                 & -1882,35                                \\ \hline
\textit{Max}                      & 11,26                          & 17,55                 & 1,28               & 2,40                        & 11,30                        & 0,40                                  & 1386,67                                 \\ \hline
\textit{Range}                    & 20,49                          & 44,66                 & 6,66               & 5,76                        & 23,40                        & 1,40                                  & 3269,02                                 \\ \hline
\textit{Sum}                      & 0,77                           & -2,53                 & -88,41             & -37,13                      & -45,90                       & 2,40                                  & -12800,35                               \\ \hline
\textit{Median}                   & -0,22                          & 0,24                  & -1,40              & -0,43                       & -0,40                        & 0,05                                  & 0,00                                    \\ \hline
\textit{Mean}                     & 0,01                           & -0,04                 & -1,55              & -0,65                       & -0,81                        & 0,04                                  & -224,57                                 \\ \hline
\textit{SE of Mean}               & 0,57                           & 1,05                  & 0,21               & 0,11                        & 0,48                         & 0,04                                  & 69,92                                   \\ \hline
\textit{95\% CI of Mean}          & 1,13                           & 2,09                  & 0,42               & 0,23                        & 0,96                         & 0,07                                  & 140,08                                  \\ \hline
\textit{Variance}                 & 18,25                          & 62,31                 & 2,49               & 0,74                        & 13,06                        & 0,08                                  & 278697,92                               \\ \hline
\textit{Std. Dev.}                & 4,27                           & 7,89                  & 1,58               & 0,86                        & 3,61                         & 0,28                                  & 527,92                                  \\ \hline
\textit{Coef. Var.}               & 317,97                         & -177,59               & -1,02              & -1,32                       & -4,49                        & 6,64                                  & -2,35                                   \\ \hline
\caption{Output of pre-selected and finally chosen variables of the variable selection process.}
\label{table:initialDataSet}
\end{longtable}

As you can see the table goes beyond the border:

enter image description here

I am trying to use p{2cm} for fitting the table, but it still does not work.

Any suggestions, how to fit the table properly to my document?

3
  • 1
    Of course the problem are the column headers, which are too long.
    – egreg
    Oct 4, 2015 at 10:27
  • By the way, I'm not sure about longtable: won't a standard tabular do? It doesn't seem like a table that should be split across pages.
    – egreg
    Oct 4, 2015 at 10:34
  • @egreg I also tried a standard tabular, but this also does not fit...
    – Carol.Kar
    Oct 4, 2015 at 10:40

2 Answers 2

2

There is no hope of fitting a table with such long headers. A way out can be using symbols for them, that are explained at the bottom of the table:

\documentclass{article}
\usepackage{array,siunitx,booktabs}

\begin{document}

\begin{table}
\centering

\addtolength{\tabcolsep}{-3pt}

\begin{tabular}{
  @{}
  >{\itshape}l
  S[table-format=3.2]
  S[table-format=-3.2]
  S[table-format=-2.2]
  S[table-format=-2.2]
  S[table-format=-2.2]
  S[table-format=-1.2]
  S[table-format=-5.2]
  @{}
}
\toprule
& {(1)} &{(2)} &{(3)} &{(4)} & {(5)} &{(6)} & {(7)} \\
\midrule
\textit{Values}          &  57,00 &   57,00 &  57,00 &  57,00 &  57,00 & 57,00 &     57,00 \\
\textit{Missing Values}  &   0,00 &    0,00 &   0,00 &   0,00 &   0,00 &  0,00 &      0,00 \\
\textit{Min}             &  -9,23 &  -27,11 &  -5,38 &  -3,36 & -12,10 & -1,00 &  -1882,35 \\
\textit{Max}             &  11,26 &   17,55 &   1,28 &   2,40 &  11,30 &  0,40 &   1386,67 \\
\textit{Range}           &  20,49 &   44,66 &   6,66 &   5,76 &  23,40 &  1,40 &   3269,02 \\
\textit{Sum}             &   0,77 &   -2,53 & -88,41 & -37,13 & -45,90 &  2,40 & -12800,35 \\
\textit{Median}          &  -0,22 &    0,24 &  -1,40 &  -0,43 &  -0,40 &  0,05 &      0,00 \\
\textit{Mean}            &   0,01 &   -0,04 &  -1,55 &  -0,65 &  -0,81 &  0,04 &   -224,57 \\
\textit{SE of Mean}      &   0,57 &    1,05 &   0,21 &   0,11 &   0,48 &  0,04 &     69,92 \\
\textit{95\% CI of Mean} &   1,13 &    2,09 &   0,42 &   0,23 &   0,96 &  0,07 &    140,08 \\
\textit{Variance}        &  18,25 &   62,31 &   2,49 &   0,74 &  13,06 &  0,08 & 278697,92 \\
\textit{Std.\ Dev.}      &   4,27 &    7,89 &   1,58 &   0,86 &   3,61 &  0,28 &    527,92 \\
\textit{Coef.\ Var.}     & 317,97 & -177,59 &  -1,02 &  -1,32 &  -4,49 &  6,64 &     -2,35 \\
\midrule[\heavyrulewidth]
%%% Headers
\multicolumn{8}{l}{(1) \textbf{oenb\_dependent}} \\
\multicolumn{8}{l}{(2) \textbf{carReg}} \\
\multicolumn{8}{l}{(3) \textbf{cpi}} \\
\multicolumn{8}{l}{(4) \textbf{primConstTot}} \\
\multicolumn{8}{l}{(5) \textbf{resProp.Dwell}} \\
\multicolumn{8}{l}{(6) \textbf{cbre.office.primeYield}} \\
\multicolumn{8}{l}{(7) \textbf{cbre.retail.capitalValue}} \\
\bottomrule
\end{tabular}

\caption{Output of pre-selected and finally chosen variables of the variable selection process.}
\label{table:initialDataSet}
\end{table}

\end{document}

I also recommend siunitx and booktabs, that give more professional appearance to the table. The value after table-format is the number of digits in the integer and decimal part, with an optional sign if present in the column. In column one I don't specify the sign, because it's taken care of by the last entry; similarly for the sixth column, the two digit first entry is taken care of by the minus sign.

Since the table was still overfull by about 41pt, I removed 3pt of separation between columns (two spaces are inserted between columns, and 6 times 7 makes 42).

enter image description here

1
  • you declare the first column to be in \itshape, so the text in it not need to be enclosed with \textit{ ...} any more :-)
    – Zarko
    Oct 4, 2015 at 12:16
2

A variant, using ltablex which combines the possibilities of tabularx and longtable,. The description of the letters in column head are done with the threeparttablex package, which brings the functionalities of threeparttable to long tables splitting across pages. Finally I loaded the geometry package for more sensible margins, if you don't need wide marginal notes, and booktabs for its vertical padding of horizontal rules.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage[labelfont=sc]{caption}

%\usepackage{float}
\usepackage{geometry}
\usepackage{siunitx}
\sisetup{output-decimal-marker ={,}, table-format=-2.2}
\usepackage{ltablex, threeparttablex, booktabs}

\begin{document}

\begin{ThreePartTable}
  \setTableNoteFont{\bfseries}
  \begin{TableNotes}[para, flushleft]\smallskip
    \item[A] oenb\_dependent
    \item[B] carReg
    \item[C] cpi
    \item[D] primConstTot
    \item[E] resProp.Dwell
    \item[F] cbre.office.primeYield
    \item[G] cbre.retail.capitalValue
  \end{TableNotes}
  \begin{tabularx}{\linewidth}{
      @{}
      >{\itshape}X
      S[table-format=3.2]
      S[table-format=-3.2]
      SSS
      S[table-format=-1.2]
      S[table-format=-5.2]
      @{}}
      %
      & {\bfseries A} & {\bfseries B} & {\bfseries C} & {\bfseries D} & {\bfseries E} & {\bfseries F} & {\bfseries G} \\ \midrule[\heavyrulewidth]
      Number of Values & 57,00 & 57,00 & 57,00 & 57,00 & 57,00 & 57,00 & 57,00 \\ \midrule
      Number of Missing Values & 0,00 & 0,00 & 0,00 & 0,00 & 0,00 & 0,00 & 0,00 \\ \midrule
      Min & -9,23 & -27,11 & -5,38 & -3,36 & -12,10 & -1,00 & -1882,35 \\ \midrule
      Max & 11,26 & 17,55 & 1,28 & 2,40 & 11,30 & 0,40 & 1386,67 \\ \midrule
      Range & 20,49 & 44,66 & 6,66 & 5,76 & 23,40 & 1,40 & 3269,02 \\ \midrule
      Sum & 0,77 & -2,53 & -88,41 & -37,13 & -45,90 & 2,40 & -12800,35 \\ \midrule
      Median & -0,22 & 0,24 & -1,40 & -0,43 & -0,40 & 0,05 & 0,00 \\ \midrule
      Mean & 0,01 & -0,04 & -1,55 & -0,65 & -0,81 & 0,04 & -224,57 \\ \midrule
      SE of Mean & 0,57 & 1,05 & 0,21 & 0,11 & 0,48 & 0,04 & 69,92 \\ \midrule
      95\% CI of Mean & 1,13 & 2,09 & 0,42 & 0,23 & 0,96 & 0,07 & 140,08 \\ \midrule
      Variance & 18,25 & 62,31 & 2,49 & 0,74 & 13,06 & 0,08 & 278697,92 \\ \midrule
      Std. Dev. & 4,27 & 7,89 & 1,58 & 0,86 & 3,61 & 0,28 & 527,92 \\ \midrule
      Coef. Var. & 317,97 & -177,59 & -1,02 & -1,32 & -4,49 & 6,64 & -2,35 \\
      \bottomrule
      \insertTableNotes \\
      \caption{Output of pre-selected and finally chosen variables of the variable selection process.}
      \label{table:initialDataSet}
    \end{tabularx}
  \end{ThreePartTable}

\end{document} 

enter image description here

You must log in to answer this question.

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