我发现tabularht
,允许为表格提供固定垂直尺寸的包并没有考虑表格标题占用的垂直空间。
按理说,标题实际上并不是表格的一部分,而是周围的表格。
然而,这实际上阻止了我指定\textheight
的大小tabularht
。
现在,我想通过一种变通方法从 中减去标题的高度\textheight
。但是,我不知道如何获得该特定测量值(字体高度加上上方间距加上下方间距)?
\documentclass{scrbook} % because that is what I use
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tabularht}
\usepackage{tabularx}
\newlength{\CaptionHeight}
\settoheight{...} % this is where I am stuck
\newlength(\TabularhtHeight}
\setlength{\TabularhtHeight}{\textheight - \CaptionHeight}
\usepackage{showframe}
\usepackage{lipsum}
\begin{document}
\begin{table*}
\caption{Test}
\begin{tabularhtx}{\TabularhtHeight}{\linewidth}{|X|X|}
\hline
\textbf{Column A} & \textbf{Column B}\\
\hline
\lipsum[2] & \lipsum[2] \\
\interrowfill
\lipsum[2] & \lipsum[2] \\
\hline
\end{tabularhtx}
\end{table*}
\end{document}
答案1
您必须在本地设置长度,因为标题的高度取决于标题文本。这里有一种方法:我们排版标题并测量它。计数器必须上下移动,因为标签宽度会影响一行或多行的排版。
\documentclass{scrbook}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tabularht}
\usepackage{tabularx,calc}
\newlength{\TabularhtHeight}
\makeatletter
\newcommand{\captionht}[2][]{%
\stepcounter{table}%
\setbox\z@=\vbox{\@makecaption\fnum@table{#2}}%
\addtocounter{table}{-1}%
\setlength{\TabularhtHeight}{\textheight-\ht\z@-\lineskip}%
\if\relax\detokenize{#1}\relax
\caption{#2}%
\else
\caption[#1]{#2}%
\fi
}
\makeatother
\usepackage{showframe}
\usepackage{lipsum}
\begin{document}
\pagestyle{empty}
\begin{table*}
\captionht{Test}
\begin{tabularhtx}{\TabularhtHeight}{\linewidth}{|X|X|}
\hline
\textbf{Column A} & \textbf{Column B}\\
\hline
\lipsum[2] & \lipsum[2] \\
\interrowfill
\lipsum[2] & \lipsum[2] \\
\hline
\end{tabularhtx}
\end{table*}
\end{document}