将定义大小的元素垂直居中放在表格内

将定义大小的元素垂直居中放在表格内

我想将两列表格中的元素垂直居中在左列,其宽度为线宽的 30%,第二列元素左对齐,其宽度为线宽的 70%。我已成功分别完成这两项操作,但无法在同一张表中同时完成。

我的代码如下:

\setlength{\arrayrulewidth}{1mm}
\setlength{\tabcolsep}{18pt}
\usepackage{array}
\usepackage{tabularx}

{\rowcolors{1}{blue!50!white!60}{blue!30!white!70}
\begin{tabularx}{\linewidth}{ |>{\arraybackslash}m{0.3\linewidth}|>{\arraybackslash}m{0.7\linewidth}|}
\hline
ID & GUIDEME-FR-FUNC-001 \\
TITLE & Functions Start Over \\
AUTHOR & IBM CIO\\
CREATION DATE & 25-09-2018 \\
SOURCE & GUIDEME-FR-FUNC-001 \\
SUBSYSTEM & Functions \\
TYPE & Functional \\
PRIORITY & High \\
STATUS & Approved \\
DESCRIPTION & The system shall permit users to start over and look for another room \\
TEST PLAN & Check if it is possible to go back to the main page once instructions have been displayed \\
\hline
\end{tabularx}
}

结果如下:

在此处输入图片描述

答案1

像这样?

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx}
\usepackage[table]{xcolor}

\begin{document}

{
\rowcolors{1}{blue!50!white!60}{blue!30!white!70}
\setlength{\arrayrulewidth}{1mm}
\setlength{\tabcolsep}{18pt}
\renewcommand\tabularxcolumn[1]{m{#1}}              % <---
\begin{tabularx}{\linewidth}{|m{0.3\linewidth}|X|}  % <---
\hline
ID              & GUIDEME-FR-FUNC-001 \\
TITLE           & Functions Start Over \\
AUTHOR          & IBM CIO\\
CREATION DATE   & 25-09-2018 \\
SOURCE          & GUIDEME-FR-FUNC-001 \\
SUBSYSTEM       & Functions \\
TYPE            & Functional \\
PRIORITY        & High \\
STATUS          & Approved \\
DESCRIPTION     & The system shall permit users to start over and look for another room \\
TEST PLAN       & Check if it is possible to go back to the main page once instructions have been displayed \\
\hline
\end{tabularx}
}
\end{document}

或者在单元格内容的上方和下方留出更多空间:

在此处输入图片描述

\documentclass{article}
\usepackage{cellspace,               % <--- for additional space above/below cells' content
            tabularx}                % <---
\setlength\cellspacetoplimit{4pt}    % <---
\setlength\cellspacebottomlimit{4pt} % <--- 
\addparagraphcolumntypes{X}          % <---
\usepackage[table]{xcolor}

\begin{document}

{
\rowcolors{1}{blue!50!white!60}{blue!30!white!70}
\setlength{\arrayrulewidth}{1mm}
\setlength{\tabcolsep}{18pt}
\renewcommand\tabularxcolumn[1]{m{#1}}
\begin{tabularx}{\linewidth}{|m{0.3\linewidth}|S{X}|} % <---
\hline
ID              & GUIDEME-FR-FUNC-001 \\
TITLE           & Functions Start Over \\
AUTHOR          & IBM CIO\\
CREATION DATE   & 25-09-2018 \\
SOURCE          & GUIDEME-FR-FUNC-001 \\
SUBSYSTEM       & Functions \\
TYPE            & Functional \\
PRIORITY        & High \\
STATUS          & Approved \\
DESCRIPTION     & The system shall permit users to start over and look for another room \\
TEST PLAN       & Check if it is possible to go back to the main page once instructions have been displayed \\
\hline
\end{tabularx}
}
\end{document}

注意:在tabularx表格环境中必须至少有一列X类型为 (或其派生类型)。要使文本垂直居中,最后一列单元格的内容必须垂直居中。这是在上面的例子中得到的\renewcommand\tabularxcolumn[1]{m{#1}}

相关内容