![将定义大小的元素垂直居中放在表格内](https://linux22.com/image/393687/%E5%B0%86%E5%AE%9A%E4%B9%89%E5%A4%A7%E5%B0%8F%E7%9A%84%E5%85%83%E7%B4%A0%E5%9E%82%E7%9B%B4%E5%B1%85%E4%B8%AD%E6%94%BE%E5%9C%A8%E8%A1%A8%E6%A0%BC%E5%86%85.png)
我想将两列表格中的元素垂直居中在左列,其宽度为线宽的 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}}
。