我正在制作简历,决定使用 来longtable
设置所有内容,以便轻松跨越多页。总体而言,我喜欢我所得到的外观,但有几个填充问题我想修复:
- 我的伪副标题行(使用嵌套的 制作
tabular*
)没有完全延伸到列的最右侧longtable
,尽管它们似乎从左侧的正确位置开始。我相信这对应于我收到的有关 未满 的两个警告中的第一个\hbox
。(您可以看到文本没有像下一行的文本那样向右延伸。) itemize
尽管我使用了nosep
中的选项enumitem
,但嵌套周围仍有前导和尾随垂直空格。- 环境结束后会有一点额外的垂直空间
longtable
。 \hbox
发出了有关整体对齐不足的警告longtable
。我认为我以前没有见过这种对齐问题,所以我不确定如何修复它,甚至不知道具体是什么原因造成的。
这是我的 MWE 的输出(红色是我添加的注释,不是输出的一部分):
我的 MWE 是:
\documentclass{article}
\usepackage{array}
\usepackage{enumitem}
\usepackage[T1]{fontenc}
\usepackage[margin=0.5in]{geometry}
\usepackage{longtable}
\usepackage{microtype}
\usepackage{ragged2e}
% No indentation.
\setlength{\parindent}{0pt}
% Adjust longtable padding.
\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\setlength\LTpre{2pt} % A little pre-padding to look like a regular line.
\setlength\LTpost{0pt}
% Adjust itemize environments.
\setlist[itemize]{nosep,left=0pt,label=\raisebox{0.5ex}{\tiny$\bullet$}}
\begin{document}
Some text before the table.
% Without the minipage, there's extra space at the bottom of the table.
\begin{longtable}
{ @{} >{\RaggedLeft\arraybackslash}p{1in} @{\extracolsep{0.25in}} p{6.25in} @{} }% LINE 29
& \begin{tabular*}{\hsize}{@{} l @{\extracolsep{\fill}} r @{}}% LINE 30
Pseudo-Subheading & Other content
\end{tabular*} \\
Left text 1 & Very lengthy text content goes here, which (with enough words
written) ought to span past the end of the line sufficiently to
do some things. \\
Left text 2 & %
\begin{itemize}[after=\strut]
\item Bullet point 1.
\item Bullet point 2.
\end{itemize} \\
Left text 3 & Some regular text, just for effect.
\end{longtable} % LINE 42
Some text after the table.
\end{document}
给出了两个警告:
Underfull \hbox (badness 4713) in paragraph at lines 30--30
[]||
Underfull \hbox (badness 10000) in alignment at lines 29--42
[] []
也许还有一种方法可以简化我的代码,但我绝不是 LaTeX 专家。在解决了各种问题之后,我终于找到了这个解决方案。目标是有两个固定的列,它们之间有四分之一英寸的间隙,左列右对齐,右列左对齐,有时可以将右侧列拆分为子列以显示子标题,还可以嵌入itemize
没有前导或尾随空格和缩进的环境。
答案1
对代码进行一些简化,如(a)longtable
、(b)所示tabular
(c)tabularx
可以消除多余的空格和错位(以及坏框)。
tabularx
第二列的宽度是自动计算的。
\documentclass{article}
\usepackage{array}
\usepackage{enumitem}% Not used here
\usepackage{fontspec}
\usepackage[margin=0.5in]{geometry}
\usepackage{longtable}
\usepackage{microtype}
\usepackage{ragged2e} % Not used here
\usepackage{tabularx}% added <<<<<<<
\usepackage{showframe} % show the margins <<<<<<<<<<<<<<<<<<
\renewcommand*\ShowFrameColor{\color{red}}
% No indentation.
\setlength{\parindent}{0pt}
\newcommand{\markitem}{\raisebox{0.4ex}{\footnotesize\textbullet}~} % added <<<<<<<<<<<<<<
% Adjust longtable padding.
\setlength\LTleft{0pt}
%\setlength\LTright{0pt} % <<<<<<<<<
\setlength\LTpre{2pt} % A little pre-padding to look like a regular line.
\setlength\LTpost{-2pt} % changed <<<<<<<<<<<<<<<<<<<<
\setlength{\tabcolsep}{0pt} % added <<<<<<<<<<<<<<<<<
\begin{document}
Some text before the \textbf{longtable.}
\begin{longtable}{p{1in} @{\extracolsep{0.25in}} p{6.25in}}% LINE 29
& \multicolumn{1}{c}{Pseudo-Subheading \hfill Other content} \\
Left text 1 & Very lengthy text content goes here, which (with enough words
written) ought to span past the end of the line sufficiently to
do some things. \\
Left text 2 & \markitem Bullet point 1. \\
& \markitem Bullet point 2. \\
Left text 3 & Some regular text, just for effect.
\end{longtable} % LINE 42
Some text after the longtable.
\bigskip
Some text before the \textbf{tabular.}
\begin{tabular}{p{1in} @{\extracolsep{0.25in}} p{6.25in}}% LINE 29
& \multicolumn{1}{c}{Pseudo-Subheading \hfill Other content} \\
Left text 1 & Very lengthy text content goes here, which (with enough words written) ought to span past the end of the line sufficiently to do some things. \\
Left text 2 & \markitem Bullet point 1. \\
& \markitem Bullet point 2. \\
Left text 3 & Some regular text, just for effect.
\end{tabular} % LINE 42
Some text after the tabular.
\bigskip
Some text before the \textbf{tabularx}
\begin{tabularx}{\textwidth}{p{1in} @{\extracolsep{0.25in}} X}% LINE 29
& \multicolumn{1}{c}{Pseudo-Subheading \hfill Other content} \\
Left text 1 & Very lengthy text content goes here, which (with enough words
written) ought to span past the end of the line sufficiently to
do some things. \\
Left text 2 & \markitem Bullet point 1. \\
& \markitem Bullet point 2. \\
Left text 3 & Some regular text, just for effect.
\end{tabularx} % LINE 42
Some text after the tabularx.
\end{document}
答案2
编辑:
通过使用enumitem
、etoolbox
和tabularray
包。enumitem
和etoolbox
定义在表itemize
内的列表样式中tblr
,因此您仍然可以使用表体代码itemize
列表。
如果您的表格可以放在一页中,那么您可以用浮动表格插入替换longtblr
MWE 中的所有内容。talltblr
table
\documentclass{article}
\usepackage[margin=0.5in]{geometry}
%\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{tabularray} % version 2021P
\UseTblrLibrary{varwidth} % <===
\NewTblrTheme{fancy}{
\SetTblrStyle{head}{font=\small}
\SetTblrStyle{foot}{\small\itshape}
\SetTblrStyle{caption-tag}{font=\small\bfseries}
}
\usepackage{enumitem}
\usepackage{etoolbox}
\AtBeginEnvironment{longtblr}{%
\setlist[itemize]{nosep,
itemsep=0.5ex,
leftmargin=*,
after=\end{minipage}, % <---
before=\begin{minipage}[t]{\linewidth} % <---
}
}
\setlength{\parindent}{0pt}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begingroup
\begin{longtblr}[
theme = fancy,
caption = {The Long Table Caption},
label = {tab:longtblr},
]{colspec={@{} l X[j] @{}},
row{1} = {font=\bfseries},
rowhead=1,
measure = vbox, % <===
}
& Pseudo-Subheading\hfill Other content \\
Left text 1 & Very lengthy text content goes here, which (with enough words
written) ought to span past the end of the line sufficiently to
do some things. \\
Left text 2 & \begin{itemize}
\item Bullet point 1.
\item Bullet point 2.
\end{itemize} \\
Left text 3 & Some regular text, just for effect.
\end{longtblr}\vspace{-\baselineskip}
\endgroup
\lipsum[2]
\end{document}