以下是我正在处理mwe
的标题中多余空白的问题。如果我没记错的话,longtable
这主要是由于。@{\extracolsep{\fill}}
\documentclass[letterpaper]{article}
\usepackage[letterpaper,tmargin=2cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm]{geometry}
\usepackage{booktabs,array,longtable}
\usepackage[dvipsnames,table]{xcolor}
\usepackage{enumitem}
\begin{document}
\renewcommand{\labelenumi}{\bfseries Unit\ \arabic{enumi}.}
\renewcommand{\arraystretch}{1.5}
\setlength\LTleft{0pt}%
\setlength\LTright{0pt}%
\begin{longtable}{@{\extracolsep{\fill}}|c|>{\centering\arraybackslash}p{8.5em}|>{\raggedright\arraybackslash}p{.5\textwidth}|p{6.5em}|@{}}
\hline
\rowcolor{gray!10}\textbf{text} & \textbf{text} & \textbf{text} & \textbf{text}\tabularnewline%
\hline
\endfirsthead
\hline
\rowcolor{gray!10}\textbf{text} & \textbf{text} & \textbf{text} & \textbf{text}\tabularnewline%
\hline
\endhead
%\hline
%--------------------------------------------- Week 1-3 ---------------------------------------------
text
&
text
&
text
&
text\tabularnewline
\hline%
\end{longtable}
\end{document}
关于如何删除空白处或至少是什么导致空白处的任何建议?
答案1
看看以下解决方案是否适合您:
\documentclass[letterpaper]{article}
\usepackage[showframe, % only for see if table width fit text width
letterpaper,
tmargin=2cm,bmargin=2.5cm,lmargin=2.5cm,rmargin=2.5cm]{geometry}
\usepackage{array, booktabs, longtable}
\usepackage[dvipsnames,table]{xcolor}
\usepackage{enumitem}
\begin{document}
\renewcommand{\labelenumi}{\bfseries Unit\ \arabic{enumi}.}
\renewcommand{\arraystretch}{1.5}
\begin{longtable}{|>{\centering}p{\dimexpr0.1\linewidth-2\tabcolsep-1.25\arrayrulewidth\relax}
|>{\centering}p{\dimexpr0.2\linewidth-2\tabcolsep-1.25\arrayrulewidth\relax}
|>{\raggedright}p{\dimexpr.5\textwidth-2\tabcolsep-1.25\arrayrulewidth\relax}
| p{\dimexpr0.2\linewidth-2\tabcolsep-1.25\arrayrulewidth\relax}|}
\hline
\rowcolor{gray!10}\textbf{text} & \textbf{text} & \textbf{text} & \textbf{text}\tabularnewline%
\hline
\endfirsthead
\hline
\rowcolor{gray!10}\textbf{text} & \textbf{text} & \textbf{text} & \textbf{text}\tabularnewline%
\hline
\endhead
text
&
text
&
text
&
text\tabularnewline
\hline%
\end{longtable}
\end{document}
我没有费心重新计算列的宽度,但这不应该是什么大问题:)
答案2
为了实现一个\textwidth
宽度恰好为 的 longtable,我建议您加载,这样就可以将ltablex
的功能带给。我冒昧地简化了您的序言,特别是您不必加载,因为它也不会为您做任何事情:longtable
tabularx
array
longtable
tabularx
ltablex
\documentclass[letterpaper]{article}
\usepackage[tmargin=2cm,bmargin=2.5cm, hmargin=2.5cm, showframe]{geometry}
\usepackage{booktabs,ltablex}
\usepackage[dvipsnames,table]{xcolor}
\usepackage{enumitem}
\begin{document}
\renewcommand{\labelenumi}{\bfseries Unit\ \arabic{enumi}.}
\renewcommand{\arraystretch}{1.5}
\keepXColumns
\begin{tabularx}{\linewidth}{|c|>{\centering\arraybackslash}p{8.5em}|>{\raggedright\arraybackslash}X|p{6.5em}|@{}}
\hline
\rowcolor{gray!10}\textbf{text} & \textbf{text} & \textbf{text} & \textbf{text}\tabularnewline%
\hline
\endfirsthead
\hline
\rowcolor{gray!10}\textbf{text} & \textbf{text} & \textbf{text} & \textbf{text}\tabularnewline%
\hline
\endhead
%\hline
%--------------------------------------------- Week 1-3 ---------------------------------------------
text
&
text
&
text
&
text \\
\hline%
\end{tabularx}
\end{document}