tabularx 中 p 单元格的行间距不均匀

tabularx 中 p 单元格的行间距不均匀

看一下下面的图片:

在此处输入图片描述

Namespace 列使用p单元格排版。页面布局为横向模式。我已将行间距明确设置为20pt。但是,由于p第一行的单元格比其相邻单元格多一行文本,因此 R1 和 R2 之间的行间距小于 R2 和 R3 之间的行间距。

我该如何解决这个问题,以便行距考虑到p单元格的高度?

以下是 MWE:

\documentclass[10pt]{article}
\usepackage[landscape,margin=0.5in]{geometry}
\usepackage{tabularx}
\usepackage{booktabs}
\newcommand*{\nkeywfont}{\fontfamily{pcr}\selectfont}
\newcommand{\nkeyw}[1]{\begingroup \nkeywfont #1\endgroup}
\newcommand{\keyw}[1]{\begingroup \fontfamily{qcr}\selectfont \textbf{#1}\endgroup}

\newcommand{\lbtcell}[1]{%
  \begin{tabular}[t]{@{}p{4cm}@{}}#1\end{tabular}}
\newcommand{\libtype}[3]{\nkeyw{#1} & \lbtcell{#2} & #3 \\[20pt]}

\begin{document}
{\centering
\begin{tabularx}{\linewidth}{rp{4cm}X}
\toprule
Type & Namespace & Description \\
\cmidrule(l{1cm}r){1-1} \cmidrule(lr){2-2} \cmidrule(lr{1cm}){3-3}

\libtype{size\_type}{\nkeyw{string} \\ \nkeyw{vector<T>} (and all other containers)}{Unsigned type big enough to hold the number of characters in a \nkeyw{string}, or the number of elements in a \nkeyw{vector}. Returned by the \nkeyw{size} function}

\libtype{iterator}{\nkeyw{string}, \nkeyw{vector<T>} (and all other containers)}{Denotes the type of an iterator. Can be used to read and write the element it denotes. May be used only with non\keyw{const} \nkeyw{string}s and containers}

\libtype{const\_iterator}{\nkeyw{string}, \nkeyw{vector<T>} (and all other containers)}{Denotes the type of an iterator. Can be used only to read the element it denotes. If the \nkeyw{string} or container is \keyw{const}, only its \nkeyw{const\_iterator} can be used. However, \nkeyw{const\_iterator} may also be used for non\keyw{const} \nkeyw{string}s and containers}
\bottomrule
\end{tabularx}
\\}  
  \end{document}

答案1

正如您所发现的,通常的\\[20pt]做法不起作用。但booktabs可以解决问题:

\documentclass[10pt]{article}
\usepackage[landscape,margin=0.5in]{geometry}
\usepackage{tabularx}
\usepackage{booktabs}
\newcommand*{\nkeywfont}{\fontfamily{pcr}\selectfont}
\newcommand{\nkeyw}[1]{\begingroup \nkeywfont #1\endgroup}
\newcommand{\keyw}[1]{\begingroup \fontfamily{qcr}\selectfont \textbf{#1}\endgroup}

\newcommand{\lbtcell}[1]{%
  \begin{tabular}[t]{@{}p{4cm}@{}}#1\end{tabular}}

\newcommand{\libtype}[3]{\nkeyw{#1} & \lbtcell{#2} & #3 \\
  \addlinespace[20pt]
}

\begin{document}

\noindent
\begin{tabularx}{\linewidth}{rp{4cm}X}
\toprule
Type & Namespace & Description \\
\cmidrule(l{1cm}r){1-1} \cmidrule(lr){2-2} \cmidrule(lr{1cm}){3-3}

\libtype{size\_type}{\nkeyw{string} \\ \nkeyw{vector<T>} (and all other 
containers)}{Unsigned type big enough to hold the number of characters in a \nkeyw{string}, 
or the number of elements in a \nkeyw{vector}. Returned by the \nkeyw{size} function}

\libtype{iterator}{\nkeyw{string}, \nkeyw{vector<T>} (and all other containers)}{Denotes the 
type of an iterator. Can be used to read and write the element it denotes. May be used only 
with non\keyw{const} \nkeyw{string}s and containers}

\libtype{const\_iterator}{\nkeyw{string}, \nkeyw{vector<T>} (and all other 
containers)}{Denotes the type of an iterator. Can be used only to read the element it 
denotes. If the \nkeyw{string} or container is \keyw{const}, only its 
\nkeyw{const\_iterator} can be used. However, \nkeyw{const\_iterator} may also be used for 
non\keyw{const} \nkeyw{string}s and containers}
\bottomrule
\end{tabularx}

\end{document}

在此处输入图片描述

相关内容