PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : longtable: Spalten gleichmäßig verteilen



likelihood
13-03-2013, 17:57
Hi zusammen,

bisher wurden die Spalten in meinen longtables immer automatisch gleichmäßig verteilt. Leider geschieht dies in der folgenden longtable aus mir unerklärlichen Gründen nicht:




\documentclass{article}

\usepackage{lscape}

\usepackage{longtable}
\usepackage[singlelinecheck=off]{caption}

\begin{document}

\begin{landscape}

\begin{center}

{\small \begin{longtable}{lccccccc}

\hline
& \multicolumn{7}{c}{Income} \\
Regressors & (1) & (2) & (3) & (4) & (5) & (6) & (7) \\
\hline
\endfirsthead
\multicolumn{8}{c}{\textit{Continued from previous page}} \\
\hline
& \multicolumn{7}{c}{Income} \\
Regressors & (1) & (2) & (3) & (4) & (5) & (6) & (7) \\
\hline
\endhead
\multicolumn{8}{c}{\textit{Continued on next page}} \\
\endfoot
\endlastfoot
Employment*Year & -0.15 & -0.15 & -0.17 & -0.12 & -0.18 & -0.21* & -0.04 \\
& (0.10) & (0.12) & (0.19) & (0.14) & (0.13) & (0.13) & (0.15) \\
Employment*Month & -0.04 & -0.00 & -0.14 & -0.13 & 0.07 & -0.16 & 0.21 \\
& (0.30) & (0.34) & (0.54) & (0.43) & (0.40) & (0.41) & (0.37) \\
\hline
Number of Observations & 110,301 & 85,829 & 24,472 & 50,285 & 60,016 & 83,894 & 26,407 \\
Number of Individuals & 13,136 & 10,956 & 2,180 & 6,345 & 6,791 & 10,001 & 3,135 \\
R2 & 0.03 & 0.04 & 0.03 & 0.03 & 0.04 & 0.04 & 0.03 \\
Adjusted R2 & 0.03 & 0.03 & 0.03 & 0.03 & 0.04 & 0.04 & 0.03 \\
\hline
\hline
\multicolumn{8}{c}{(1) Full Sample, (2) Old-Age Sub-Sample, (3) Young-Age Sub-Sample, (4) Female Sub-Sample, (5) Male Sub-Sample} \\
\multicolumn{8}{c}{(6) High-Income Sub-Sample, (7) Low-Income Sub-Sample} \\
\multicolumn{8}{c}{\textit{Standard errors in parantheses}} \\
\multicolumn{8}{c}{\textit{*** p\textless0.01, ** p\textless0.05, * p\textless0.1}} \\
\multicolumn{8}{l}{} \\
\multicolumn{8}{p{\linewidth}}{\textit{Note:} All regression equations include the demographic and human capital characteristics, as well as economic conditions and household characteristics of parents as controls. Moreover, they include the regressors of interest. All figures are rounded to two decimal places.} \\
\multicolumn{8}{l}{\textit{Source:} Own calculations} \\

\end{longtable}}

\end{center}

\end{landscape}

\end{document}



Die longtable ist sehr groß und hat 8 Spalten. Zwischen der 7. und der 8. Spalte entsteht eine große "Lücke". Diese behebt sich automatisch, sobald ich die Tabellenunterschrift entferne. Bei anderen longtables von mir entstehen allerdings keine Lücken bei gleicher Tabellenunterschrift.

Kurzum: Ich verstehe nicht, warum diese Lücke gerade hier entsteht.

Vielen Dank für euren Rat!

Chris

PS: Eine PDF-Datei ist angehängt, um das Problem zu veranschaulichen.

hakaze
13-03-2013, 20:57
Die Lücke entseht, weil du einige sehr breite multicolumns eingebaut hast. Diese erhöhen die Gesamtbreite der Tabelle; die letzte Spalte wird dann automatisch auf die notwendige Breite angepasst. Auch die übrigen c-Spalten werden nicht gleich breit verteilt. Jede c-Spalte wird wird individuell so breit wie nötig gemacht (wie der Inhalt der entsprechenden Spalte es erfordert.

In diesem Fall ist es vielleicht ratsam, die Ergänzungen separat unter Tabelle zu setzen:

\documentclass{article}

\usepackage{lscape}

\usepackage{longtable}
\usepackage[singlelinecheck=off]{caption}

\begin{document}

\begin{landscape}

\centering % einfaches Umschalten reicht hier
\small % zusätzliche Klammer ist nicht nötig
% small und centering bleiben auf den Inhalt von landscape beschränkt

\begin{longtable}{lccccccc}
\hline
& \multicolumn{7}{c}{Income} \\
Regressors & (1) & (2) & (3) & (4) & (5) & (6) & (7) \\
\hline
\endfirsthead
\multicolumn{8}{c}{\textit{Continued from previous page}} \\
\hline
& \multicolumn{7}{c}{Income} \\
Regressors & (1) & (2) & (3) & (4) & (5) & (6) & (7) \\
\hline
\endhead
\multicolumn{8}{c}{\textit{Continued on next page}} \\
\endfoot
\endlastfoot
Employment*Year & -0.15 & -0.15 & -0.17 & -0.12 & -0.18 & -0.21* & -0.04 \\
& (0.10) & (0.12) & (0.19) & (0.14) & (0.13) & (0.13) & (0.15) \\
Employment*Month & -0.04 & -0.00 & -0.14 & -0.13 & 0.07 & -0.16 & 0.21 \\
& (0.30) & (0.34) & (0.54) & (0.43) & (0.40) & (0.41) & (0.37) \\
\hline
Number of Observations & 110,301 & 85,829 & 24,472 & 50,285 & 60,016 & 83,894 & 26,407 \\
Number of Individuals & 13,136 & 10,956 & 2,180 & 6,345 & 6,791 & 10,001 & 3,135 \\
R2 & 0.03 & 0.04 & 0.03 & 0.03 & 0.04 & 0.04 & 0.03 \\
Adjusted R2 & 0.03 & 0.03 & 0.03 & 0.03 & 0.04 & 0.04 & 0.03 \\
\hline
\hline
\end{longtable}

\begin{flushleft}
(1) Full Sample, (2) Old-Age Sub-Sample, (3) Young-Age Sub-Sample, (4) Female Sub-Sample, (5) Male Sub-Sample,
(6) High-Income Sub-Sample, (7) Low-Income Sub-Sample \\
\textit{Standard errors in parantheses} \\
\textit{*** p\textless0.01, ** p\textless0.05, * p\textless0.1} \\[\baselineskip] % Extra-Abstand statt leerer Tabellenzeile
\textit{Note:} All regression equations include the demographic and human capital characteristics, as well as economic conditions and household characteristics of parents as controls. Moreover, they include the regressors of interest. All figures are rounded to two decimal places. \\
\textit{Source:} Own calculations
\end{flushleft}

\end{landscape}

\end{document}

likelihood
14-03-2013, 10:45
Lieber hakaze,

vielen Dank für deine Hilfe - das war schon der erste Schritt.

Das Problem ist jetzt, dass ein Abstand zwischen der Tabelle und der Legende entstanden ist, der vorher nicht da war und der auch nicht da sein soll. Außerdem ist die Tabelle nicht mehr zentriert.

Letzteres bekomme ich noch hin, aber wie kann man den Abstand zwischen Tabelle und Legende los werden? Weißt du das zufällig?

Ganz herzlichen Dank!

Chris

likelihood
14-03-2013, 10:49
Danke für den Tipp mit \small und \center! :)

hakaze
14-03-2013, 12:20
Außerdem ist die Tabelle nicht mehr zentriert. Das kann ich nicht reproduzieren. In meinem Beispiel ist die Tabelle sehr wohl zentriert.


Das Problem ist jetzt, dass ein Abstand zwischen der Tabelle und der Legende entstanden ist, der vorher nicht da war und der auch nicht da sein soll. Die longtable- und flushleft-Umgebung bringen zusätzliche vertikale Abstände ein.

Statt der flushleft-Umgebung kannst du auch einfach mit \raggedright auf rechtsbündigen Satz nach der Tabelle umschalten. Bei longtable lässt sich der untere Abstand wie folgt abschalte (siehe Paket-Doku (http://texdoc.net/texmf-dist/doc/latex/tools/longtable.pdf)):

\setlength{\LTpost}{0pt} % vor \begin{longtable}

likelihood
14-03-2013, 14:06
Lieber hakaze,

ich habe das Problem jetzt wie folgt gelöst:




\documentclass{article}

\usepackage{lscape}

\usepackage{longtable}
\usepackage[singlelinecheck=off]{caption}

\def\flushright{\trivlist \raggedleft\item\relax}
\def\endflushleft{\endtrivlist}


\begin{document}

\begin{landscape}

\centering % einfaches Umschalten reicht hier
\small % zusätzliche Klammer ist nicht nötig
% small und centering bleiben auf den Inhalt von landscape beschränkt

\setlength{\LTpost}{0pt} % vor \begin{longtable}

\begin{longtable}{lccccccc}

\hline
& \multicolumn{7}{c}{Income} \\
Regressors & (1) & (2) & (3) & (4) & (5) & (6) & (7) \\
\hline
\endfirsthead
\multicolumn{8}{c}{\textit{Continued from previous page}} \\
\hline
& \multicolumn{7}{c}{Income} \\
Regressors & (1) & (2) & (3) & (4) & (5) & (6) & (7) \\
\hline
\endhead
\multicolumn{8}{c}{\textit{Continued on next page}} \\
\endfoot
\endlastfoot
Employment*Year & -0.15 & -0.15 & -0.17 & -0.12 & -0.18 & -0.21* & -0.04 \\
& (0.10) & (0.12) & (0.19) & (0.14) & (0.13) & (0.13) & (0.15) \\
Employment*Month & -0.04 & -0.00 & -0.14 & -0.13 & 0.07 & -0.16 & 0.21 \\
& (0.30) & (0.34) & (0.54) & (0.43) & (0.40) & (0.41) & (0.37) \\
\hline
Number of Observations & 110,301 & 85,829 & 24,472 & 50,285 & 60,016 & 83,894 & 26,407 \\
Number of Individuals & 13,136 & 10,956 & 2,180 & 6,345 & 6,791 & 10,001 & 3,135 \\
R2 & 0.03 & 0.04 & 0.03 & 0.03 & 0.04 & 0.04 & 0.03 \\
Adjusted R2 & 0.03 & 0.03 & 0.03 & 0.03 & 0.04 & 0.04 & 0.03 \\
\hline
\hline
\end{longtable}

\begingroup\setlength\topsep{0pt}


(1) Full Sample, (2) Old-Age Sub-Sample, (3) Young-Age Sub-Sample, (4) Female Sub-Sample, (5) Male Sub-Sample,\\
(6) High-Income Sub-Sample, (7) Low-Income Sub-Sample \\
\textit{Standard errors in parantheses} \\
\textit{*** p\textless0.01, ** p\textless0.05, * p\textless0.1} \\[\baselineskip] % Extra-Abstand statt leerer Tabellenzeile

\endgroup

\begin{flushleft}
\textit{Note:} All regression equations include the demographic and human capital characteristics, as well as economic conditions and household characteristics of parents as controls. Moreover, they include the regressors of interest. All figures are rounded to two decimal places. \\
\textit{Source:} Own calculations

\end{flushleft}

\end{landscape}

\end{document}



Angehängt findest du auch noch einmal eine PDF, die alles verdeutlich.

Nochmals vielen Dank,

Chris

hakaze
14-03-2013, 15:28
Ich weiß ja nicht, wo du diese Umdefinitionen her hast, aber eigentlich reicht doch ein \raggedright statt dem rumdoktorn mittels def-Anweisungen:

\documentclass{article}

\usepackage{lscape}

\usepackage{longtable}
\usepackage[singlelinecheck=off]{caption}


\begin{document}

\begin{landscape}

\centering % einfaches Umschalten reicht hier
\small % zusätzliche Klammer ist nicht nötig
% small und centering bleiben auf den Inhalt von landscape beschränkt
\setlength{\LTpost}{0pt}

\begin{longtable}{lccccccc}

\hline
& \multicolumn{7}{c}{Income} \\
Regressors & (1) & (2) & (3) & (4) & (5) & (6) & (7) \\
\hline
\endfirsthead
\multicolumn{8}{c}{\textit{Continued from previous page}} \\
\hline
& \multicolumn{7}{c}{Income} \\
Regressors & (1) & (2) & (3) & (4) & (5) & (6) & (7) \\
\hline
\endhead
\multicolumn{8}{c}{\textit{Continued on next page}} \\
\endfoot
\endlastfoot
Employment*Year & -0.15 & -0.15 & -0.17 & -0.12 & -0.18 & -0.21* & -0.04 \\
& (0.10) & (0.12) & (0.19) & (0.14) & (0.13) & (0.13) & (0.15) \\
Employment*Month & -0.04 & -0.00 & -0.14 & -0.13 & 0.07 & -0.16 & 0.21 \\
& (0.30) & (0.34) & (0.54) & (0.43) & (0.40) & (0.41) & (0.37) \\
\hline
Number of Observations & 110,301 & 85,829 & 24,472 & 50,285 & 60,016 & 83,894 & 26,407 \\
Number of Individuals & 13,136 & 10,956 & 2,180 & 6,345 & 6,791 & 10,001 & 3,135 \\
R2 & 0.03 & 0.04 & 0.03 & 0.03 & 0.04 & 0.04 & 0.03 \\
Adjusted R2 & 0.03 & 0.03 & 0.03 & 0.03 & 0.04 & 0.04 & 0.03 \\
\hline
\hline
\end{longtable}

\raggedright % von zentriert auf rechtsbündig umschalten
(1) Full Sample, (2) Old-Age Sub-Sample, (3) Young-Age Sub-Sample, (4) Female Sub-Sample, (5) Male Sub-Sample,
(6) High-Income Sub-Sample, (7) Low-Income Sub-Sample \\
\textit{Standard errors in parantheses} \\
\textit{*** p\textless0.01, ** p\textless0.05, * p\textless0.1} \\[\baselineskip] % Extra-Abstand statt leerer Tabellenzeile
\textit{Note:} All regression equations include the demographic and human capital characteristics, as well as economic conditions and household characteristics of parents as controls. Moreover, they include the regressors of interest. All figures are rounded to two decimal places. \\
\textit{Source:} Own calculations

\end{landscape}

\end{document}PS. Ich habe die gesamte Unterschrift rechtsbündig gesetzt, weil das Zentrieren von so langen Zeilen meiner Meinung nach unleserlich ist. Wenn du das nicht möchtest, schiebe den \raggedright-Befehl einfach weiter nach unten!