将 longtables 移到左侧(以匹配 tabularx 输出)

将 longtables 移到左侧(以匹配 tabularx 输出)

在下面的 MWE 中,我希望 longtable 看起来与表格相同。如何将其移动到左侧以适应表格的格式?我可以简单地使用 longtables,但它需要与页面的左侧进一步对齐。

\documentclass[a4paper]{tufte-handout}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{longtable}
\usepackage{tabularx} % better tables
\setlength{\extrarowheight}{3pt} % increase table row height
\newcommand{\tableheadline}[1]{\multicolumn{1}{l}{\spacedlowsmallcaps{#1}}}
\newcommand{\myfloatalign}{\centering} % to be used with each float for alignment
\newcolumntype{L}{>{\raggedleft}p{0.18\textwidth}}
\newcolumntype{R}{p{.78\textwidth}}
\newcommand\VRule{\vrule width 0.5pt}

\begin{document}
    

\section{Small List}
\begin{table}[h]
    \myfloatalign
    \begin{tabularx}{\textwidth}{l|X}
        2017 & Something Happened that year\\   
        2016 & That year too \\
    \end{tabularx}
\end{table} 
\bigskip

\section{Long List}
\begingroup
\begin{longtable}{L!{\VRule}R}
    2017 & Something Happened that year\\   
    2016 & That year too \\
\end{longtable}
\endgroup   
\end{document}

LaTeX 渲染的屏幕截图

答案1

从您自己的答案来看,您想要的是全宽表格。但是,如果您在表格中添加了 hline,那么您自己的答案就是错误的。以下是具有多个长表或短表环境的更好的答案。

\documentclass[a4paper]{tufte-handout}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{tabularx}
\usepackage{xltabular}
\usepackage{tabularray}

\setlength{\extrarowheight}{3pt}
\newcommand\VRule{\vrule width 2pt}

\begin{document}

\section{Tabularx (short)}

\begin{table}[!htbp]
  \begin{tabularx}{\textwidth}{l!{\VRule}X}
  \hline
    2017 & Something Happened that year\\   
    2016 & That year too \\
  \hline
  \end{tabularx}
\end{table} 
\bigskip

\section{Xltabular (long)}

\begin{xltabular}{\textwidth}{l!{\VRule}X}
  \hline
    2017 & Something Happened that year\\   
    2016 & That year too \\
  \hline
\end{xltabular}

\section{Tabularray (short)}

\begin{table}[!htbp]
  \begin{tblr}{l|[2pt]X}
  \hline
    2017 & Something Happened that year\\   
    2016 & That year too \\
  \hline
  \end{tblr}
\end{table}

\section{Tabularray (long)}

\SetTblrTemplate{head}{empty}
\begin{longtblr}{l|[2pt]X}
  \hline
    2017 & Something Happened that year\\   
    2016 & That year too \\
  \hline
\end{longtblr}

\end{document}

在此处输入图片描述

答案2

我已经扩展了 MWE,以包括现代表格数组包裹

\documentclass[a4paper]{tufte-handout}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{longtable}
\usepackage{tabularx} % better tables
\setlength{\extrarowheight}{3pt} % increase table row height
\setlength\LTleft{-35pt}
\newcommand{\tableheadline}[1]{\multicolumn{1}{l}{\spacedlowsmallcaps{#1}}}
\newcommand{\myfloatalign}{\centering} % to be used with each float for alignment
\newcolumntype{L}{>{\raggedleft}p{0.18\textwidth}}
\newcolumntype{R}{p{.78\textwidth}}
\newcommand\VRule{\vrule width 0.5pt}

\usepackage{tabularray}


\begin{document}
    

\section{Tabularx}
\begin{table}[h]
    \myfloatalign
    \begin{tabularx}{\textwidth}{l|X}
        2017 & Something Happened that year\\   
        2016 & That year too \\
    \end{tabularx}
\end{table} 
\bigskip

\section{Longtable}
\begingroup
\begin{longtable}{L!{\VRule}R}

    2017 & Something Happened that year\\   
    2016 & That year too \\
\end{longtable}
\endgroup   
\bigskip

\section{Tabularray}
\begin{table}[!htpb]
    \begin{tblr}{r|X}
    2017 & Something Happened that year\\   
    2016 & That year too \\
    \end{tblr}
\end{table}

\end{document}

渲染输出

相关内容