Longtable 不适合页边距

Longtable 不适合页边距

我已经尝试了一段时间将长表放入页边距内。不幸的是没有成功。任何帮助都将不胜感激。谢谢!

\begin{longtable}[c]{|l|llllll|}
\caption{ABC}
\label{tab:my-table}\\
\hline
\multicolumn{1}{|c|}{\multirow{2}{*}{Title and Reference}} &
  \multicolumn{6}{c|}{Match for "Operation Management of Urban Service Robots" with Sub-Topic} \\ \cline{2-7} 
\multicolumn{1}{|c|}{} &
  \multicolumn{1}{l|}{Smart City and Robotics} &
  \multicolumn{1}{l|}{Singular Robots} &
  \multicolumn{1}{l|}{Multiple Robots} &
  \multicolumn{1}{l|}{Assistance Infrastructure} &
  \multicolumn{1}{l|}{Responsible Energy Consumption} &
  Time Management \\ \hline
\endhead
%
ABC &
  \multicolumn{1}{l|}{} &
  \multicolumn{1}{l|}{} &
  \multicolumn{1}{l|}{} &
  \multicolumn{1}{l|}{} &
  \multicolumn{1}{l|}{} &
   \\ \hline
 &
  \multicolumn{1}{l|}{} &
  \multicolumn{1}{l|}{} &
  \multicolumn{1}{l|}{} &
  \multicolumn{1}{l|}{} &
  \multicolumn{1}{l|}{} &
   \\ \hline
\end{longtable}

答案1

\documentclass[12pt,a4,twoside]{article}
\usepackage{longtable}
\usepackage{multirow}
\usepackage{makecell}
\usepackage{float}
\usepackage{blindtext, pdflscape}
\usepackage{tabularx}
\usepackage{geometry}
\usepackage{ltablex}
\usepackage{caption}
\begin{document}
\setlength{\arrayrulewidth}{0.2mm} % To change table line thickness
\setlength{\tabcolsep}{1pt}
\renewcommand{\arraystretch}{1}
\begin{longtable}[c]{|l|llllll|}
\caption{ABC}
\label{tab:my-table}\\
\hline
\multicolumn{1}{|c|}{\multirow{2}{*}{\makecell{Title \\ and \\ Reference}}} &
  \multicolumn{6}{c|}{\makecell{Match for "Operation Management of Urban Service Robots" \\ with Sub-Topic}} \\ \cline{2-7} 
\multicolumn{1}{|c|}{} &
  \multicolumn{1}{l|}{\makecell{Smart City \\ and \\ Robotics}} &
  \multicolumn{1}{l|}{\makecell{Singular \\ Robots}} &
  \multicolumn{1}{l|}{\makecell{Multiple \\ Robots}} &
  \multicolumn{1}{l|}{\makecell{Assistance \\ Infrastructure}} &
  \multicolumn{1}{l|}{\makecell{Responsible \\ Energy \\ Consumption}} &
  \multicolumn{1}{l|}{\makecell{Time\\ Management}} \\ \hline

\endhead
%
ABC &
  \multicolumn{1}{l|}{} &
  \multicolumn{1}{l|}{} &
  \multicolumn{1}{l|}{} &
  \multicolumn{1}{l|}{} &
  \multicolumn{1}{l|}{} &
   \\ \hline
 &
  \multicolumn{1}{l|}{} &
  \multicolumn{1}{l|}{} &
  \multicolumn{1}{l|}{} &
  \multicolumn{1}{l|}{} &
  \multicolumn{1}{l|}{} &
   \\ \hline
\end{longtable}
\end{document}

在此处输入图片描述

答案2

我建议您(a)摆脱所有\multicolumn{1}“包装器”,(b)加载xltabular包并从 a 切换longtablexltabular环境 - 主要优点是您可以设置xltabular环境的目标宽度,以及(c)X在所有 7 列中使用列类型以允许自动换行。

我还将通过 (i) 删除所有垂直线和 (ii) 使用更少但间距适当的水平线,使表格看起来更加开放和吸引人。

在此处输入图片描述

\documentclass{article}
\usepackage[english]{babel}
\usepackage{xltabular,ragged2e,amsmath,booktabs,makecell}
\newcolumntype{L}{>{\RaggedRight\hspace{0pt}}X}
\newcolumntype{C}{>{\Centering\hspace{0pt}}X}
\hyphenation{infra-struc-ture con-sump-tion}

\begin{document}

\setlength\tabcolsep{2pt} % default: 6pt
\begin{xltabular}{\textwidth}{@{} L CCCCCC @{}}
\caption{ABC} \label{tab:my-table}\\
\toprule
Title and Reference &
\multicolumn{6}{c}{\makecell[t]{Match for ``Operation 
  Management of \\Urban Service Robots'' with Sub-Topic}} \\ 
\cmidrule(l){2-7} 
 &
  Smart City and Robotics &
  Singular Robots &
  Multiple Robots &
  Assistance Infrastructure &
  Responsible Energy Consumption &
  Time Management \\ 
\midrule
\endhead

ABC \\ 
\addlinespace
DEF \\ 
\bottomrule
\end{xltabular}
\end{document}

答案3

  • 您没有提供任何有关文档设置的信息。因此,页面布局、所用字体及其大小都未知。这两者都对页面外观有很大影响。
  • 对于您的长桌,我会使用longtblr包裹tabularray
  • 下面的MWE(最小工作示例)提供了两种表设计的情况:
\documentclass{article}
\usepackage{geometry}   
\usepackage[english]{babel}
\hyphenation{infra-struc-ture con-sump-tion}
\usepackage{newtxtext, newtxmath}

\usepackage{ragged2e}
\usepackage{tabularray}
\UseTblrLibrary{amsmath,booktabs}

\begin{document}
With  cells in "jail" of horizontal and "vertical" rules:
    \begin{longtblr}[
caption = {ABC},
  label = {tab:my-table}
                    ]{hlines, vlines,
                      colsep  = 3pt,
                      colspec = { X[l] *{6}{X[cmd=\Centering\hspace{0pt}]} },
                        hspan = minimal,
                      rowhead = 2
                      }
\SetCell[r=2]{c}   Title and Reference
    &   \SetCell[c=6]{c}    Match for ``Operation Management of Urban Service Robots'' with Sub-Topic
        &   &   &   &   &                       \\
    &   Smart City and Robotics
        &   Singular Robots
            &   Multiple Robots
                &   Assistance Infrastructure
                    &   Responsible Energy Consumption
                        &   Time Management     \\
ABC & 1 & 2 & 3 & 4 & 5 & 6                     \\
DEF &   &   &   &   &   &                       \\
    \end{longtblr}

or with use \verb+booktabs+ rules:

    \begin{longtblr}[
caption = {ABC},
  label = {tab:my-table}
                    ]{colsep  = 3pt,
                      colspec = {@{} X[l] *{6}{X[cmd=\Centering\hspace{0pt}]} @{}},
                        hspan = minimal,
                      rowhead = 2
                      }
    \toprule
\SetCell[r=2]{c}   Title and Reference 
    &   \SetCell[c=6]{c}    Match for ``Operation Management of Urban Service Robots'' with Sub-Topic
        &   &   &   &   &                       \\ 
\midrule
    &   Smart City and Robotics 
        &   Singular Robots 
            &   Multiple Robots 
                &   Assistance Infrastructure 
                    &   Responsible Energy Consumption 
                        &   Time Management     \\
    \midrule
ABC & 1 & 2 & 3 & 4 & 5 & 6                     \\
DEF &   &   &   &   &   &                       \\
    \bottomrule
    \end{longtblr}
\end{document}

在此处输入图片描述

相关内容