我遇到了 longtables 的问题,它从下一页开始,而当前页面上有很多空间可以使用。我尝试了多种解决方案,但都无济于事。我不知道现在该怎么办。谢谢。
\documentclass[a4paper,12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{longtable}
\usepackage{enumitem}
\usepackage[left=3.81cm, right=2.54cm, top=3.175cm]{geometry}
\usepackage{adjustbox}
\usepackage[table,xcdraw]{xcolor}
\hbadness=99999
\begin{document}
\section{Proposed storage solutions}
Based on the current packaging and storage issues the following solutions were proposed after brainstorming:
\begin{longtable}[!h]
\centering
\hspace*{-4cm}%
\begin{tabular}[t]{|p{0.2\linewidth}|p{0.3\linewidth}|p{0.3\linewidth}|p{0.3\linewidth}|p{0.1\linewidth}|}
\hline
% HEADER ROW
\textbf{Solution} & \textbf{Specifications} & \textbf{Pros} & \textbf{Cons} & \textbf{Total cost} \\ \hline
% FIRST ROW
\raisebox{-\totalheight}{\includegraphics[width=0.2\textwidth, height=60mm]{images/myLboro.png}}
&
\begin{itemize}[nosep, leftmargin=0pt]
\item[] Configuration: Vertical
\item[] Stability: Tension clamp with pressure plate
\item[] Dimensions: 48’’x 40 x 65’’
\item[] Capacity: 661 pounds
\end{itemize}
&
\begin{itemize}[nosep, leftmargin=0pt]
\item[] Easy to assemble/ dismantle the rack.
\item[] Space-saving compared to storing doors in crates.
\item[] Cheaper than other A-frame racks
\end{itemize}
&
\begin{itemize}[nosep, leftmargin=0pt]
\item[] Not stackable
\item[] Space-saving compared to storing doors in crates.
\item[] Cheaper than other A-frame racks
\end{itemize}
& \\ \hline
% SECOND ROW
\raisebox{-\totalheight}{\includegraphics[width=0.2\textwidth, height=60mm]{images/myLboro.png}}
&
\begin{itemize}[nosep, leftmargin=0pt]
\item[] configuration: Vertical
\item[] Dimensions: At least one-third of the product height should rest against the divider. The V-Divider depth dimension= 4 ft
\end{itemize}
&
\begin{itemize}[nosep, leftmargin=0pt]
\item[] Bulk doors stored vertically within a bay.
\item[] Facilitates one part picking.
\item[] Cheaper than buying new racks.
\end{itemize}
&
\begin{itemize}[nosep, leftmargin=0pt]
\item[] Add door fixtures to secure doors at the bottom to timber decking or rack mesh.
\item[] Dividers to divide 8 different P/N.
\item[] Labeling locations per dividers.
\end{itemize}
& \\ \hline
% THIRD ROW
\raisebox{-\totalheight}{\includegraphics[width=0.2\textwidth, height=60mm]{images/myLboro.png}}
&
\begin{itemize}[nosep, leftmargin=0pt]
\item[] Configuration: Horizontally on the bars
\item[] Dimensions:16"W x 26"L x 24"H
\end{itemize}
&
\begin{itemize}[nosep, leftmargin=0pt]
\item[] Capacity: 7,500 LBS
\item[] Stackable up to five units high
\item[] Unit cost: 115.96 \$
\item[] Space needed per unit: 4.3 sq,ft
\end{itemize}
&
\begin{itemize}[nosep, leftmargin=0pt]
\item[] NO CONS
\end{itemize}
& \\ \hline
\end{tabular}
\hspace*{-3cm}%
\end{longtable}
\end{document}
答案1
- 正如@Ulrike Fisher 的评论中所提到的,
longtable
并不是 的替代品table
而是 的替代品tabular
。 - 您的表格比规定的宽度更宽
\texwidth
,因此,它超出了右页面边框。 - 简单的解决方案是
longtable
使用tabularray
包及其longtblr
环境来表示长表,并使用其X
列类型来表示第二、第三和第四列。
编辑:
- 删除了表格标题,
- 表格中的字体大小缩小为
\small
, - 表格中添加了第四行,用于显示如何
longtnblr
分页。
\documentclass[a4paper,12pt, demo]{report} % in real document remove "demo"
\usepackage[hmargin={3.81cm, 2.54cm}, top=3.175cm]{geometry}
\usepackage[xcdraw]{xcolor}
\usepackage{tabularray}
\usepackage[export,
demo]{adjustbox}
\usepackage{siunitx}
\begin{document}
\section{Proposed storage solutions}
Based on the current packaging and storage issues, the following solutions were proposed after brainstorming:
\begingroup
\DefTblrTemplate{firsthead, middlehead,lasthead}{default}{} % <---
\DefTblrTemplate{contfoot-text}{normal}{\scriptsize\textit{Continued on the next page}}
\SetTblrTemplate{contfoot-text}{normal}
%
\setkeys{Gin}{width=20mm, height=60mm}
\begin{longtblr}{hlines, vlines,
colspec = {c *{3}{X[h, l]} c},
colsep = {4pt},
column{1} = {colsep=3pt},
row{1} = {font=\small\bfseries, c, m},
row{2-Z} = {belowsep+=-4pt},
rowhead = 1,
}
Solution
& Specifications
& Pros
& Cons
& {Total\\ cost} \\
% table body
% FIRST ROW
\includegraphics{images/myLboro.png}
& {Configuration: Vertical\\
Stability: Tension clamp with pressure plate\\
Dimensions: \qtyproduct{48 x 40 x 65}{''}
Capacity: \qty{661}{pounds}}
& {Easy to assemble/ dismantle the rack.\\
Space-saving compared to storing doors in crates.\\
Cheaper than other A-frame racks}
& {Not stackable\\
Space-saving compared to storing doors in crates.\\
Cheaper than other A-frame racks}
& \\
% SECOND ROW
\includegraphics{images/myLboro.png}
& {configuration: Vertical\\
Dimensions: At least one-third of the product height should rest against the divider.\\
The V-Divider depth dimension: \qty{4}{ft}}
& {Bulk doors stored vertically within a bay.\\
Facilitates one part picking.\\
Cheaper than buying new racks.}
& {Add door fixtures to secure doors at the bottom to timber decking or rack mesh.\\
Dividers to divide 8 different P/N.\\
Labeling locations per dividers.}
& \\
% THIRD ROW
\includegraphics{images/myLboro.png}
& {Configuration: Horizontally on the bars\\
Dimensions: \qtyproduct{16 x 26 x 24}{''} }
& {Capacity: \qty{7,500}{LBS}
Stackable up to five units high
Unit cost: \qty{115.96}{\$}
Space needed per unit: \qty{4.3}{sq,ft}}
& NO CONS
& \\
% FOURTH ROW (repeated third), IF EXIST
\includegraphics{images/myLboro.png}
& {Configuration: Horizontally on the bars\\
Dimensions: \qtyproduct{16 x 26 x 24}{''} }
& {Capacity: \qty{7,500}{LBS}
Stackable up to five units high
Unit cost: \qty{115.96}{\$}
Space needed per unit: \qty{4.3}{sq,ft}}
& NO CONS
& \\
\end{longtblr}
\end{document}
附录: 如果您喜欢在表格中添加标题,那么在上述解决方案中,您需要删除选项,这些选项会从表格中删除标题并添加您想要的标题。请参阅下面的 MWE:
\documentclass[a4paper,12pt, demo]{report} % in real document remove "demo"
\usepackage[hmargin={3.81cm, 2.54cm}, top=3.175cm]{geometry}
\usepackage[xcdraw]{xcolor}
\usepackage{tabularray}
\usepackage[export,
demo]{adjustbox}
\usepackage{siunitx}
\begin{document}
\section{Proposed storage solutions}
Based on the current packaging and storage issues, the following solutions were proposed after brainstorming:
\begingroup
\setkeys{Gin}{width=20mm, height=60mm}
\begin{longtblr}[
caption = {Caption}, % <---
label = {tab:long?} % <---
]{hlines, vlines,
colspec = {c *{3}{X[h, l]} c},
colsep = {4pt},
column{1} = {colsep=3pt},
row{1} = {font=\small\bfseries, c, m},
row{2-Z} = {belowsep+=-4pt},
rowhead = 1,
}
Solution
& Specifications
& Pros
& Cons
& {Total\\ cost} \\
% table body
% FIRST ROW
\includegraphics{images/myLboro.png}
& {Configuration: Vertical\\
Stability: Tension clamp with pressure plate\\
Dimensions: \qtyproduct{48 x 40 x 65}{''}
Capacity: \qty{661}{pounds}}
& {Easy to assemble/ dismantle the rack.\\
Space-saving compared to storing doors in crates.\\
Cheaper than other A-frame racks}
& {Not stackable\\
Space-saving compared to storing doors in crates.\\
Cheaper than other A-frame racks}
& \\
% SECOND ROW
\includegraphics{images/myLboro.png}
& {configuration: Vertical\\
Dimensions: At least one-third of the product height should rest against the divider.\\
The V-Divider depth dimension: \qty{4}{ft}}
& {Bulk doors stored vertically within a bay.\\
Facilitates one part picking.\\
Cheaper than buying new racks.}
& {Add door fixtures to secure doors at the bottom to timber decking or rack mesh.\\
Dividers to divide 8 different P/N.\\
Labeling locations per dividers.}
& \\
% THIRD ROW
\includegraphics{images/myLboro.png}
& {Configuration: Horizontally on the bars\\
Dimensions: \qtyproduct{16 x 26 x 24}{''} }
& {Capacity: \qty{7,500}{LBS}
Stackable up to five units high
Unit cost: \qty{115.96}{\$}
Space needed per unit: \qty{4.3}{sq,ft}}
& NO CONS
& \\
% FOURTH ROW (repeated third), IF EXIST
\includegraphics{images/myLboro.png}
& {Configuration: Horizontally on the bars\\
Dimensions: \qtyproduct{16 x 26 x 24}{''} }
& {Capacity: \qty{7,500}{LBS}
Stackable up to five units high
Unit cost: \qty{115.96}{\$}
Space needed per unit: \qty{4.3}{sq,ft}}
& NO CONS
& \\
\end{longtblr}
\endgroup
\end{document}
笔记:我想知道您是否真的需要这么高的图像。例如,将其高度降低 10% 可使第一页上的表格更合适。对于此\setkeys{Gin}{width=20mm, height=60mm}
更改\setkeys{Gin}{width=20mm, height=55mm}
答案2
不需要 itemize 环境,我只得到一页:
\PassOptionsToPackage{table,xcdraw}{xcolor}
\PassOptionsToPackage{demo}{graphicx}
\documentclass[a4paper,12pt]{report}
\usepackage{xltabular}
\usepackage{enumitem}
\usepackage[left=3.81cm, right=2.54cm, top=3.175cm]{geometry}
\usepackage{adjustbox}
\usepackage{xcolor,array}
\hbadness=99999
\begin{document}
\section{Proposed storage solutions}
Based on the current packaging and storage issues the following solutions were proposed after brainstorming:
\noindent\small
\begin{xltabular}{\linewidth}{|c|X|X|X|p{0.1\linewidth}|}\hline
% HEADER ROW
\textbf{Solution} & \textbf{Specifications} & \textbf{Pros} & \textbf{Cons} & \textbf{Total cost} \\ \hline
% FIRST ROW
\raisebox{\dimexpr-\totalheight+\normalbaselineskip}{\includegraphics[width=0.2\textwidth, height=60mm]{images/myLboro.png}}
& Configuration: Vertical\newline
Stability: Tension clamp with pressure plate\newline
Dimensions: 48’’x 40 x 65’’\newline
Capacity: 661 pounds
& Easy to assemble/ dismantle the rack.\newline
Space-saving compared to storing doors in crates.\newline
Cheaper than other A-frame racks
& Not stackable\newline
Space-saving compared to storing doors in crates.\newline
Cheaper than other A-frame racks
& \\ \hline
% SECOND ROW
\raisebox{-\totalheight}{\includegraphics[width=0.2\textwidth, height=60mm]{images/myLboro.png}}
&
\begin{itemize}[nosep, leftmargin=0pt]
\item[] configuration: Vertical
\item[] Dimensions: At least one-third of the product height should rest against the divider. The V-Divider depth dimension= 4 ft
\end{itemize}
&
\begin{itemize}[nosep, leftmargin=0pt]
\item[] Bulk doors stored vertically within a bay.
\item[] Facilitates one part picking.
\item[] Cheaper than buying new racks.
\end{itemize}
&
\begin{itemize}[nosep, leftmargin=0pt]
\item[] Add door fixtures to secure doors at the bottom to timber decking or rack mesh.
\item[] Dividers to divide 8 different P/N.
\item[] Labeling locations per dividers.
\end{itemize}
& \\ \hline
% THIRD ROW
\raisebox{-\totalheight}{\includegraphics[width=0.2\textwidth, height=60mm]{images/myLboro.png}}
&
\begin{itemize}[nosep, leftmargin=0pt]
\item[] Configuration: Horizontally on the bars
\item[] Dimensions:16"W x 26"L x 24"H
\end{itemize}
&
\begin{itemize}[nosep, leftmargin=0pt]
\item[] Capacity: 7,500 LBS
\item[] Stackable up to five units high
\item[] Unit cost: 115.96 \$
\item[] Space needed per unit: 4.3 sq,ft
\end{itemize}
&
\begin{itemize}[nosep, leftmargin=0pt]
\item[] NO CONS
\end{itemize}
& \\ \hline
\end{xltabular}
\normalsize
\end{document}
答案3
longtable
不能替代table
。
您的表格太宽了,所以我把它设置得超出了两个边距。请阅读手册以了解我添加的其他部分。
相反,\raisebox
您可以使用valign
提供的密钥adjustbox
。
对于itemize
列表,我认为最好使用项目分隔,否则表格会很难阅读。另外,为了减少宽度,我使用了\footnotesize
。
为了确保表格在各个页面上的分割正确,我重复了第三行。
\documentclass[a4paper,12pt,draft]{report}
\usepackage[left=3.81cm, right=2.54cm, top=3.175cm]{geometry}
\usepackage{longtable}
\usepackage{enumitem}
\usepackage[export]{adjustbox}
\usepackage[table,xcdraw]{xcolor}
\begin{document}
\section{Proposed storage solutions}
Based on the current packaging and storage issues the following solutions
were proposed after brainstorming:
\begingroup
\setlength{\LTleft}{0pt minus 300pt}
\setlength{\LTright}{0pt minus 300pt}
\footnotesize
\begin{longtable}{
|>{\raggedright}p{0.2\textwidth}|
>{\raggedright}p{0.22\textwidth}|
>{\raggedright}p{0.22\textwidth}|
>{\raggedright}p{0.22\textwidth}|
>{\raggedright\arraybackslash}p{0.14\textwidth}|
}
\hline
% HEADER ROW
\textbf{Solution} &
\textbf{Specifications} &
\textbf{Pros} &
\textbf{Cons} &
\textbf{Total cost} \\
\hline
\endhead
\hline
\endfoot
% FIRST ROW
\includegraphics[width=0.2\textwidth, height=60mm,valign=T]{images/myLboro.png} &
\begin{itemize}[topsep=0pt,label={},leftmargin=0pt]
\item Configuration: Vertical
\item Stability: Tension clamp with pressure plate
\item Dimensions: 48’’x 40 x 65’’
\item Capacity: 661 pounds
\end{itemize} &
\begin{itemize}[topsep=0pt,label={},leftmargin=0pt]
\item Easy to assemble/ dismantle the rack.
\item Space-saving compared to storing doors in crates.
\item Cheaper than other A-frame racks
\end{itemize} &
\begin{itemize}[topsep=0pt,label={},leftmargin=0pt]
\item Not stackable
\item Space-saving compared to storing doors in crates.
\item Cheaper than other A-frame racks
\end{itemize} &
\\ \hline
% SECOND ROW
\includegraphics[width=0.2\textwidth, height=60mm,valign=T]{images/myLboro.png} &
\begin{itemize}[topsep=0pt,label={},leftmargin=0pt]
\item configuration: Vertical
\item Dimensions: At least one-third of the product height should rest against the divider. The V-Divider depth dimension= 4 ft
\end{itemize} &
\begin{itemize}[topsep=0pt,label={},leftmargin=0pt]
\item Bulk doors stored vertically within a bay.
\item Facilitates one part picking.
\item Cheaper than buying new racks.
\end{itemize} &
\begin{itemize}[topsep=0pt,label={},leftmargin=0pt]
\item Add door fixtures to secure doors at the bottom to timber decking or rack mesh.
\item Dividers to divide 8 different P/N.
\item Labeling locations per dividers.
\end{itemize} &
\\ \hline
% THIRD ROW
\includegraphics[width=0.2\textwidth, height=60mm,valign=T]{images/myLboro.png} &
\begin{itemize}[topsep=0pt,label={},leftmargin=0pt]
\item Configuration: Horizontally on the bars
\item Dimensions:16"W x 26"L x 24"H
\end{itemize} &
\begin{itemize}[topsep=0pt,label={},leftmargin=0pt]
\item Capacity: 7,500 LBS
\item Stackable up to five units high
\item Unit cost: 115.96 \$
\item Space needed per unit: 4.3 sq,ft
\end{itemize} &
\begin{itemize}[topsep=0pt,label={},leftmargin=0pt]
\item NO CONS
\end{itemize} &
\\ \hline
% THIRD ROW (repeated)
\includegraphics[width=0.2\textwidth, height=60mm,valign=T]{images/myLboro.png} &
\begin{itemize}[topsep=0pt,label={},leftmargin=0pt]
\item Configuration: Horizontally on the bars
\item Dimensions:16"W x 26"L x 24"H
\end{itemize} &
\begin{itemize}[topsep=0pt,label={},leftmargin=0pt]
\item Capacity: 7,500 LBS
\item Stackable up to five units high
\item Unit cost: 115.96 \$
\item Space needed per unit: 4.3 sq,ft
\end{itemize} &
\begin{itemize}[topsep=0pt,label={},leftmargin=0pt]
\item NO CONS
\end{itemize} &
\end{longtable}
\endgroup
\end{document}