我尝试使用 tabularx 环境将我的长论文标题对齐到冒号处,如下图所示。我希望每个条目之间的垂直间距为一个 parskip,就像在普通文本中使用的一样(例如:大学和部门之间的间距)。不知何故,如果仔细观察,间距看起来通常非常不一致。我知道 parskip 是可拉伸的长度,但我如何才能实现均匀的垂直间距,尤其是在 tabluarx 环境中。谢谢!
注意:文本将被放入框架环境中,但我不认为这是这里的问题。
MWE(带有编译的xelatex的scrbook类):
\documentclass[
a4paper,
10pt,
parskip=half,
]{scrbook}
\usepackage[showframe]{geometry}
\usepackage{setspace}
\usepackage{tabularx}
\onehalfspacing
\newlength{\defaulttabcolsep}
\setlength{\defaulttabcolsep}{\tabcolsep}
\begin{document}
Author:~Author \hfill Type of the work: Thesis\\[\parskip]
\setlength\tabcolsep{0pt}
\begin{tabularx}{\linewidth}{l X}
Title:~ & Tabularx environment is used to align long titles at the colon Tabularx environment is used to align long titles at the colon\\[\parskip]
Test & Test\\[\parskip]
\end{tabularx}
\setlength\tabcolsep{\defaulttabcolsep}
Date:~\today\\[\parskip]
University:~University
Department:~Department
\end{document}
编辑:
我现在将linegoal
代码放入环境中framed
。不幸的是,有时它需要在我的主文档中进行 6 次或更多次迭代才能终止编译,并且parbox
不再完全对齐,这可能表明剩余线宽计算不正确。
有人有什么想法吗,是否采用表格方法或其他方法?
\documentclass[
a4paper,
10pt,
parskip=half,
]{scrbook}
\usepackage{setspace}
\usepackage{tabularx}
\usepackage{linegoal}
\usepackage{framed}
\onehalfspacing
\newlength{\defaulttabcolsep}
\setlength{\defaulttabcolsep}{\tabcolsep}
\begin{document}
Author:~Author \hfill Type of the work: Thesis\\[\parskip]
\setlength\tabcolsep{0pt}
\begin{tabularx}{\linewidth}{l X}
Title:~ & Tabularx environment is used to align long titles at the colon Tabularx environment is used to align long titles at the colon%\\[\parskip]
\end{tabularx}\setlength\tabcolsep{\defaulttabcolsep}
Date:~\today%\\[\parskip]
University:~University
Department:~Department
\vspace{2cm}
\begin{oframed}
Author:~Author \hfill Type of the work: Thesis\\[\parskip]
Title:~\parbox[t][2\baselineskip]{\linegoal}{Tabularx environment is used to align long titles at the colon Tabularx environment is used to align long titles at the colon}\\[\parskip]
Date:~\today\\[\parskip]
University:~University of \LaTeX\\[\parskip]
Department:~Department of Typesetting
\end{oframed}
\end{document}
答案1
哦,天哪! 的常见问题是parskip=half
,将\parfillskip
设置为非零自然宽度以试图隐藏问题parskip
造成的问题。
嗯,我认为没有必要\linegoal
使用 ,因为\linewidth
在另一种情况下,您可以简单地使用 。由于\parfillskip
,您会得到一个 10pt 的溢出框,但是没有 也很容易处理tabularx
。
\documentclass[
a4paper,
10pt,
parskip=half,
]{scrbook}
\usepackage{setspace}
\usepackage{tabularx}
\usepackage{framed}
\newcommand{\longhang}[2]{%
\par
\settowidth{\dimen0}{#1: }%
\hangindent=\dimen0 \hangafter=1
\mbox{#1: }\ignorespaces #2\par
}
\onehalfspacing
\begin{document}
Author:~Author \hfill Type of the work: Thesis{\parfillskip=0pt\par}
\longhang{Title}{
Tabularx environment is not used to align long titles at the colon
Tabularx environment is not used to align long titles at the colon
}
Date:~\today
University:~University
Department:~Department
\vspace{2cm}
\begin{oframed}
Author:~Author \hfill Type of the work: Thesis{\parfillskip=0pt\par}
\longhang{Title}{
Tabularx environment is not used to align long titles at the colon
Tabularx environment is not used to align long titles at the colon
}
Date:~\today
University:~University of \LaTeX
Department:~Department of Typesetting
\end{oframed}
\end{document}
答案2
以下是另一个建议\@hangfrom
:
\documentclass[
%a4paper,% default
10pt,
parskip=half,
]{scrbook}
\usepackage[showframe]{geometry}
\usepackage{setspace}
\usepackage{framed}
\onehalfspacing
\begin{document}
\begin{oframed}
\setlength{\parfillskip}{0pt plus 1fil}
Author:~Author \hfill Type of the work: Thesis
\makeatletter
\@hangfrom{Title:~}{Tabularx environment is used to align long titles at the colon Tabularx environment is used to align long titles at the colon}
\makeatother
Date:~\today
University:~University
Department:~Department
\end{oframed}
\end{document}
补充说明:选项parskip=half
设置\parfillskip
为1em plus 1fil
。如果段落的最后一行应该跨越整个宽度,但使用当前的缩进和段落间距离设置,则必须在本地更改\parfillskip
为0pt plus 1fil
。或者您可能想使用选项parskip=half-
。
答案3
由于我最近的评论,我不完全确定这是否能满足您的需求,但我的建议是使用包装\parbox
的宽度。\linegoal
linegoal
\documentclass[
a4paper,
10pt,
parskip=half,
]{scrbook}
\usepackage[showframe]{geometry}
\usepackage{setspace}
\usepackage{linegoal}
\onehalfspacing
\begin{document}
Author: Author \hfill Type of the work: Thesis\\[\parskip]
Title: \parbox[t][2\baselineskip]{\linegoal}{This is a parbox used with the width \texttt{\textbackslash linegoal} which I am making extra long so you can see how it breaks}\\[\parskip]
Date: \today\\[\parskip]
University: University of \LaTeX\\[\parskip]
Department: Department of Typesetting\\[\parskip]
\end{document}
然后您可以\\[\parskip]
在任何地方使用(或者只是在除第一行之外的所有地方使用段落分隔符,因为出于\hfill
我无法弄清楚的原因,它会出现错误)。
您需要至少编译两次才能\linegoal
正常工作。
输出: