Longtable 使用 \linewidth 设置表格宽度,覆盖横向页面的页眉

Longtable 使用 \linewidth 设置表格宽度,覆盖横向页面的页眉

我正在尝试longtable在横向模式下制作页面宽度为 的表格。为了更容易设置列宽,我定义了一种新的列类型,即 [p] 列,但大小是 的一小部分\linewidth。但是当我编译时,表格会超出文档标题。

\documentclass[a4paper,twoside,12pt,notitlepage,openright]{article}

\usepackage{amsmath}
\usepackage[english]{babel}
\usepackage[hmargin=3.0cm,vmargin=3.6cm]{geometry} % setting marginals
\usepackage{fancyhdr,extramarks}  % header ja footer manipulation
\usepackage{times}  % to change font to times
\usepackage{setspace} % for linespacing

% Table
\usepackage{booktabs}
\usepackage{lscape}
\usepackage{afterpage}
\usepackage{longtable}
\usepackage{threeparttablex}
\newcommand{\mtnote}[1]{\textsuperscript{\TPTtagStyle{#1}}}
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash}p{#1\linewidth}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash}p{#1\linewidth}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash}p{#1\linewidth}}
\usepackage{caption}
\captionsetup{width=\textwidth}

\singlespacing

\pagestyle{fancy}
\fancyhf{}% clearing the header and footer
\fancyhead[LE,RO]{\bfseries\thepage}    % page number to header
\fancyhead[LO]{\nouppercase{\bfseries\rightmark}}     %
\fancyhead[RE]{\nouppercase{\bfseries\leftmark}}%

\renewcommand\sectionmark[1]
 {\markboth{\thesection\ #1}{}}         % section name to header
\renewcommand\subsectionmark[1]
 {\markright{\thesubsection\ #1}}       % subsection name to header
\renewcommand{\headrulewidth}{0.5pt}    % ruler thickness between head and body
\renewcommand{\footrulewidth}{0pt}      % no ruler between body and footer

\numberwithin{table}{section}       % table numbers with section numbers

\usepackage{lipsum}

\begin{document}

\section{Section 1}
\lipsum[1-2]
\the\textheight is the text height portrait mode

\afterpage{ 
\begin{landscape}
\singlespacing
\footnotesize
\setlength\LTcapwidth{\linewidth}  % default: 4in
%\setlength{\tabcolsep}{2pt}       % default: 6pt
\setlength\LTleft{0pt}            % default: \parindent
\setlength\LTright{3.6cm}           % default: \fill
    \begin{ThreePartTable}
        \begin{TableNotes} \footnotesize
            \item [a] Something 
        \end{TableNotes}
        \renewcommand*{\arraystretch}{1.4} 
        \begin{longtable}{L{.1} L{.14} L{.14} L{.1} L{.12} L{.14} L{.12} L{.14}}
        %@{\extracolsep{\fill}}L{.1} L{.14} L{.14} L{.1} L{.12} L{.14} L{.12} L{.14}@{}
            \caption{Table caption is also not very small and it seems to be places wrongly as well, like it is centered with the table that goes over the header here it is the linewidth which seems to be correct \the\linewidth} \label{table:articles} \\\toprule
            Column 1 & Column 2 & Column 3 & Column 4 & Column 5 & Column 6 & Column 7 & Column 8  \\\midrule
            \endfirsthead
            \multicolumn{8}{@{}l}{Table \ref{table:articles} continued.}\\\toprule
            Column 1 & Column 2 & Column 3 & Column 4 & Column 5 & Column 6 & Column 7 & Column 8  \\\midrule
            \endhead

            \bottomrule
            \endfoot
            \bottomrule
            \insertTableNotes 
            \endlastfoot

            Some author name here 1 & Something goes here and it is quite big, it fills several lines in the table describing boring stuff  & The sizes vary for each column, sometimes there is more boring stuff and others & Some are usually short & So the column width is set to more or less fit these differences  & I describe some aspects of scientific articles & I dont understand why this doesnt work for me & It goes on for a few pages but here I added just two lines  \\

            Some author name here 1 & Something goes here and it is quite big, it fills several lines in the table describing boring stuff  & The sizes vary for each column, sometimes there is more boring stuff and others & Some are usually short & So the column width is set to more or less fit these differences  & I describe some aspects of scientific articles & I dont understand why this doesnt work for me & It goes on for a few pages but here I added just two lines  \\            
        \end{longtable}
    \end{ThreePartTable}
\end{landscape}      
}   


\end{document}

表格结果

答案1

\tabcolsep在新的列类型定义中考虑值:使用此代码

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash}p{\dimexpr#1\linewidth-2\tabcolsep\relax}}

同样,对于RC,问题也解决了。或者,您可以使用 包,它将的ltablex功能引入。longtabletabularx

在此处输入图片描述

相关内容