# Problem with landscape table layout following a normal table in a document

I have landscape tables which span multiple pages and are laid out as three part tables with a notes section at the bottom. The landscape tables in the document are fine at the beginning of the document. But in the landscape tables which come in the text following a normal table, the notes section is narrower (matching the width of the notes section for the preceding non-landscape table.

Here is a working example:

\listfiles
\documentclass[12pt,a4paper,bibtotoc,liststotocnumbered,pointlessnumbers]{scrreprt}

%---------------------------------------%
%       Layout          %
%---------------------------------------%
\usepackage[parfill]{parskip}           %use line breaks instead of
\usepackage[left=3.75cm, right=3.75cm, bottom=3.5cm]{geometry}

\usepackage{pdflscape}          %landscape single pages

%Sets up landscape pages for each landscape page.
\usepackage{pdfpages}           % http://ctan.org/pkg/pdfpages

\usepackage[absolute]{textpos}
\usepackage{fancyhdr}

\fancypagestyle{lscape}{%
\fancyhf{} % clear all header and footer fields
\fancyfoot[LE]{%
\begin{textblock}{20}(1,5){\rotatebox{90}{\leftmark}}\end{textblock}}
\fancyfoot[LO] {%
\begin{textblock}{1}(14,7.5){\rotatebox{90}{\thepage}}\end{textblock}}
\renewcommand{\footrulewidth}{0pt}}

%---------------------------------------%
%   Tables & Figures        %
%---------------------------------------%
\usepackage{booktabs}
\usepackage{multirow}               % Allows rows in tables to be combined.
\usepackage{threeparttable}         % Allows for three part tables with a specified notes section.
\usepackage{threeparttablex}            % Lets threeparttable work with longtable
\usepackage{longtable}              % Allows tables to break across pages

\usepackage{array}
\usepackage{ragged2e}
\newcolumntype{P}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

\usepackage{floatrow}
\floatsetup[table]{capposition = top, font = sf}    %Sets table to sans serif font and puts caption on top
\floatsetup[figure]{capposition = top, font = sf}   %Sets table to sans serif font and puts caption on top

\usepackage{caption}
\captionsetup{font={sf,large},justification=justified, singlelinecheck=false}
\setkomafont{caption}{\sffamily}
\setkomafont{captionlabel}{\upshape\bfseries\sffamily}

\renewcommand{\topfraction}{0.9}% max fraction of floats at top
\renewcommand{\textfraction}{0.07}
\renewcommand{\bottomfraction}{0.9}% max fraction of floats at bottom

%Set table for to be smaller
\usepackage{etoolbox}
\AtBeginEnvironment{tabular}{\small}
\AtBeginEnvironment{longtable}{\small}

% Package for including code in the document
\usepackage{listings}

\usepackage[english]{babel}
\usepackage{blindtext}\def\mytitle{Energy security under climate policies}
\def\myauthor{Jessica Jewell}
\begin{document}

\blindtext

\newgeometry{hmargin=3.5cm,vmargin=3.5cm}
\thispagestyle{lscape}
\pagestyle{lscape}

\begin{landscape}

\begin{ThreePartTable}
\begin{longtable}{C{4.4cm}C{1.2cm}C{1.4cm}C{1.7cm}C{3.6cm}P{8.0cm}}
\caption{\large{Previous studies}} \label{table1} \\

\toprule
\ & & \multicolumn{3}{l}{\hspace{1.0cm}\head{Energy security focus}} & \\
\midrule

\toprule
\ & & \multicolumn{3}{l}{\hspace{1.0cm}\head{Energy security focus}} & \\
\midrule

\multicolumn{6}{r}{{\emph{continues on next page}}} \\
\endfoot

\bottomrule
\endlastfoot

XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\

\end{longtable}
\begin{tablenotes}
\item Notes: These are some long notes to show that on the first table the text runs all the way across the bottom of the page. See? Isn't it lovely how it just lays down at the bottom of the page.

\end{tablenotes}
\end{ThreePartTable}
\end{landscape}
\restoregeometry
\pagestyle{plain}

\blindtext

\begin{table*}
\begin{threeparttable}
\caption{GDP and emissions of major economies} \label{meconomies}
\begin{tabular}{lcccccc}
\toprule
&& XX & XX && XX & XX \\
\midrule
\head{XXXXX} && XX & XX && XX) & XX \\
\head{XXXXX} && XX & XX && XX) & XX \\
\head{XXXXX} && XX & XX && XX) & XX \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\item Notes: This is meaningless not explaining the meaningless table.
\end{tablenotes}
\end{threeparttable}
\end{table*}

\newgeometry{hmargin=3.5cm,vmargin=3.5cm}
\thispagestyle{lscape}
\pagestyle{lscape}

\begin{landscape}

\begin{ThreePartTable}
\begin{longtable}{C{4.4cm}C{1.2cm}C{1.4cm}C{1.7cm}C{3.6cm}P{8.0cm}}
\caption{\large{Previous studies}} \label{table2} \\

\toprule
\ & & \multicolumn{3}{l}{\hspace{1.0cm}\head{Energy security focus}} & \\
\midrule

\toprule
\ & & \multicolumn{3}{l}{\hspace{1.0cm}\head{Energy security focus}} & \\
\midrule

\multicolumn{6}{r}{{\emph{continues on next page}}} \\
\endfoot

\bottomrule
\endlastfoot

XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\

\end{longtable}
\begin{tablenotes}
\item Notes: These are some long notes. See how the margin of these notes is wrong? They match the text width of the preceding threeparttable.

\end{tablenotes}
\end{ThreePartTable}
\end{landscape}
\restoregeometry
\pagestyle{plain}

\blindtext

\end{document}

-
! Undefined control sequence. l.80 \singlespacing – David Carlisle May 22 '13 at 12:41
The comment is edited now. – jjewell May 23 '13 at 12:32

I finally found the proper solution using the ThreePartTable package. The trick is that ThreePartTable (which works with longtable unlike threeparttable which doesn't) requires \TableNotes instead of \tablenotes. Also the way these are inserted into ThreePartTable are slightly different. See the package documentation (first example on Page 3). Also here is the code where i have corrected the minimal working example.

\listfiles
\documentclass[12pt,a4paper,bibtotoc,liststotocnumbered,pointlessnumbers]{scrreprt}

%---------------------------------------%
%       Layout          %
%---------------------------------------%
\usepackage[parfill]{parskip}           %use line breaks instead of
\usepackage[left=3.75cm, right=3.75cm, bottom=3.5cm]{geometry}

\usepackage{pdflscape}          %landscape single pages

%Sets up landscape pages for each landscape page.
\usepackage{pdfpages}           % http://ctan.org/pkg/pdfpages

\usepackage[absolute]{textpos}
\usepackage{fancyhdr}

\fancypagestyle{lscape}{%
\fancyhf{} % clear all header and footer fields
\fancyfoot[LE]{%
\begin{textblock}{20}(1,5){\rotatebox{90}{\leftmark}}\end{textblock}}
\fancyfoot[LO] {%
\begin{textblock}{1}(14,7.5){\rotatebox{90}{\thepage}}\end{textblock}}
\renewcommand{\footrulewidth}{0pt}}

%---------------------------------------%
%   Tables & Figures        %
%---------------------------------------%
\usepackage{booktabs}
\usepackage{multirow}               % Allows rows in tables to be combined.
\usepackage{threeparttable}         % Allows for three part tables with a specified notes section.
\usepackage{threeparttablex}            % Lets threeparttable work with longtable
\usepackage{longtable}              % Allows tables to break across pages

\usepackage{array}
\usepackage{ragged2e}
\newcolumntype{P}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

\usepackage{floatrow}
\floatsetup[table]{capposition = top, font = sf}    %Sets table to sans serif font and puts caption on top
\floatsetup[figure]{capposition = top, font = sf}   %Sets table to sans serif font and puts caption on top

\usepackage{caption}
\captionsetup{font={sf,large},justification=justified, singlelinecheck=false}
\setkomafont{caption}{\sffamily}
\setkomafont{captionlabel}{\upshape\bfseries\sffamily}

% Package for including code in the document
\usepackage{listings}

\usepackage[english]{babel}
\usepackage{blindtext}\def\mytitle{Energy security under climate policies}
\def\myauthor{Jessica Jewell}
\begin{document}

\blindtext

\newgeometry{hmargin=3.5cm,vmargin=3.5cm}
\thispagestyle{lscape}
\pagestyle{lscape}

\begin{landscape}

\begin{ThreePartTable}
\begin{TableNotes}
\item Notes: These are some long notes to show that on the first table the text runs all the way across the bottom of the page. See? Isn't it lovely how it just lays down at the bottom of the page.

\end{TableNotes}
\end{ThreePartTable}

\begin{longtable}{C{4.4cm}C{1.2cm}C{1.4cm}C{1.7cm}C{3.6cm}P{8.0cm}}
\caption{\large{Previous studies}} \label{table1} \\

\toprule
& & \multicolumn{3}{l}{\hspace{1.0cm}\head{Energy security focus}} & \\
\midrule

\toprule
\ & & \multicolumn{3}{l}{\hspace{1.0cm}\head{Energy security focus}} & \\
\midrule

\multicolumn{6}{r}{{\emph{continues on next page}}} \\
\endfoot

\bottomrule
\insertTableNotes\\
\endlastfoot

XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\

\end{longtable}

\end{landscape}
\restoregeometry
\pagestyle{plain}

\blindtext

\begin{table*}
\begin{threeparttable}
\caption{GDP and emissions of major economies} \label{meconomies}
\begin{tabular}{lcccccc}
\toprule
&& XX & XX && XX & XX \\
\midrule
\head{XXXXX} && XX & XX && XX) & XX \\
\head{XXXXX} && XX & XX && XX) & XX \\
\head{XXXXX} && XX & XX && XX) & XX \\
\bottomrule
\end{tabular}
\begin{tablenotes}
\item Notes: This is meaningless not explaining the meaningless table.
\end{tablenotes}
\end{threeparttable}
\end{table*}

\newgeometry{hmargin=3.5cm,vmargin=3.5cm}
\thispagestyle{lscape}
\pagestyle{lscape}

\begin{landscape}

\begin{ThreePartTable}
\begin{TableNotes}
\item Notes: These are some long notes. See how the margin of these notes is wrong? They match the text width of the preceding threeparttable.
\end{TableNotes}

\begin{longtable}{C{4.4cm}C{1.2cm}C{1.4cm}C{1.7cm}C{3.6cm}P{8.0cm}}
\caption{\large{Previous studies}} \label{table2} \\

\toprule
\ & & \multicolumn{3}{l}{\hspace{1.0cm}\head{Energy security focus}} & \\
\midrule

\toprule
\ & & \multicolumn{3}{l}{\hspace{1.0cm}\head{Energy security focus}} & \\
\midrule

\multicolumn{6}{r}{{\emph{continues on next page}}} \\
\endfoot

\bottomrule
\insertTableNotes\\
\endlastfoot

XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\
XXX & 2010 & XXXXl && This is an example of a working table \\

\end{longtable}

\end{ThreePartTable}
\end{landscape}
\restoregeometry
\pagestyle{plain}

\blindtext

\end{document}

-