我有一张tabularx
表格,标题有两行。如何才能将其余单行标题垂直对齐到中间?
\documentclass[12pt,a4paper]{article}
\usepackage{blindtext}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tabularx}
\usepackage{blindtext}
\usepackage{booktabs}
\begin{document}
\begin{table}[htb]
\footnotesize
\begin{tabularx}{\linewidth}{cX}
\toprule
\textbf{\shortstack{Line 1\\Line 2}} & \textbf{Head}\\
\midrule
Parameter 1 & \blindtext \\
Parameter 2 & \blindtext \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
答案1
那么使用呢makecell
?
\documentclass[12pt,a4paper]{article}
\usepackage{blindtext}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tabularx}
\usepackage{blindtext}
\usepackage{booktabs}
\usepackage{makecell}
\begin{document}
\begin{table}[htb]
\footnotesize
\begin{tabularx}{\linewidth}{cX}
\toprule
\textbf{\makecell{Line 1\\Line 2}} & \textbf{Head}\\
\midrule
Parameter 1 & \blindtext \\
Parameter 2 & \blindtext \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
答案2
使用包\Centerstack
中的stackengine
。它不仅可以实现所需的居中,还可以使行距正确(通过修复基线跳跃,而不是像 那样修复单词间的垂直间隙\shortstack
)。
\documentclass[12pt,a4paper]{article}
\usepackage{blindtext}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tabularx}
\usepackage{blindtext}
\usepackage{booktabs}
\usepackage[usestackEOL]{stackengine}
\begin{document}
\begin{table}[htb]
\footnotesize
\begin{tabularx}{\linewidth}{cX}
\toprule
\textbf{\Centerstack{Line 1\\Line 2}} & \textbf{Head}\\
\midrule
Parameter 1 & \blindtext \\
Parameter 2 & \blindtext \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}