我正在使用这个包长桌我想要实现的是垂直居中单元格, 和等行高。
我曾尝试使用米{}列类型,以实现垂直居中,但是当我尝试使用增加行高时阵列拉伸,垂直对齐失败。所以我需要两方面的帮助
- 为什么 arraystretch 会干扰垂直对齐? 否则如何实现 arraystretch 的功能并保持对齐?
- 阵列拉伸不会提供相等的行高,只会增加填充。如何才能获得相等的行高?
这是输出,您可以看到箭头长度的差异:
梅威瑟:
\documentclass{article}
\usepackage[table,dvipsnames]{xcolor}%table colors
\usepackage{array}
\usepackage{makecell}
\usepackage{longtable}
\setlength{\doublerulesep}{0pt}
\newcommand{\myhline}{\hline\hline\hline}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}m{#1}}
\begin{document}
\begin{footnotesize}
\renewcommand{\arraystretch}{3}
\rowcolors{2}{MidnightBlue!10}{white}
\begin{longtable}{ | C{1.7in} | C{1.5in} | C{0.65in} | C{0.6in} | C{0.6in} | }
\hline
\rowcolor{MidnightBlue!30}
\textbf{test1} & \textbf{test2} & \textbf{test3} & \textbf{test4} & \textbf{test5} \\
\myhline
\textbf{qwerty} & testing simple & - & + & + \\
\textbf{qwerty2} & testing simple long test & - & + & -\\
\textbf{qwerty} & testing simple long test & - & + & + \\
\textbf{qwerty} & testing simple long test & - & + & + \\
\textbf{qwerty} & testing simple long test & - &+ & + \\
\textbf{qwerty} & testing reaaaaaaaaaaaally simple loooooooooooooong test & - & + & + \\
\textbf{qwerty} & testing simple long test & - & + & + \\
\textbf{qwerty} & testing simple long test (pixels) & - & + & + \\
\textbf{qwerty} & testing simple long test & - & + & + \\
\hline
\rowcolor{white}
\caption{Table testing}
\label{my_label}
\end{longtable}
\end{footnotesize}
\end{document}
答案1
(红线表示页面布局)
使用cellspace
(而不是使用arraystretch
)和xltabular
(而不是longtable
):
\documentclass{article}
\usepackage[skip=1ex]{caption}
\usepackage[table,dvipsnames]{xcolor}%table colors
\usepackage{array, makecell, tabularx, xltabular}
\newcolumntype{C}[1]{>{\centering\arraybackslash\hsize=#1\hsize}X}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash\hsize=#1\hsize}X}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash\hsize=#1\hsize}X}
\usepackage[column=O]{cellspace}
\setlength\cellspacetoplimit{5pt}
\setlength\cellspacebottomlimit{5pt}
\addparagraphcolumntypes{C}
%
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document
\begin{document}
{\footnotesize
\centering
\setlength\columnsep{4pt}
\renewcommand\tabularxcolumn[1]{m{#1}}
\rowcolors{2}{MidnightBlue!10}{white}
\begin{tabularx}{\linewidth}{ |>{\bfseries}O{C{1.75}}|O{C{1.75}}|
O{C{0.50}}|O{C{0.50}}|O{C{0.50}}| }
\Xhline{1pt}
test 1 & \textbf{test 2}
& \textbf{test 3} & \textbf{test 4} & \textbf{test 5} \\
\Xhline{0.5pt}
qwerty & testing simple & - & + & + \\
qwerty & testing simple long test & - & + & -\\
qwerty & testing simple long test & - & + & + \\
qwerty & testing simple long test & - & + & + \\
qwerty & testing simple long test & - & + & + \\
qwerty & testing reaaaaaaaaaaaally simple loooooooooooooong test
& - & + & + \\
qwerty & testing simple long test & - & + & + \\
qwerty & testing simple long test (pixels)
& - & + & + \\
qwerty & testing simple long test & - & + & + \\
\Xhline{1pt}
\end{tabularx}
\captionof{table}{Table testing}
\label{my_label}
}
\end{document}