![Tabularx 中的垂直居中](https://linux22.com/image/477508/Tabularx%20%E4%B8%AD%E7%9A%84%E5%9E%82%E7%9B%B4%E5%B1%85%E4%B8%AD.png)
我知道这个问题之前已经问过很多次了,但是在 tabularx 环境中是否有另一种有效的方法可以真正垂直居中文本?
\documentclass[a4paper,9pt]{extarticle}
\usepackage[a4paper,left=1.8cm,right=1.8cm,top=2.5cm,bottom=1.4cm,footskip=0cm,headheight=0cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[table]{xcolor}
\usepackage{xcolor}
\definecolor{table_lines}{cmyk}{0, 0, 0, 0.24} % define color
\usepackage{fancyhdr} % page numbering
\renewcommand{\headrulewidth}{0pt} % remove top line
\usepackage{colortbl} % column lines color
\usepackage{tabularx} % different column width
\newcolumntype{L}[1]{>{\hsize=#1\hsize\raggedright\arraybackslash}X}
\newcolumntype{C}[1]{>{\hsize=#1\hsize\centering\arraybackslash}X}
\makeatletter
\newcommand{\thickhline}{\noalign {\hrule height 2pt}}
\newcolumntype{'}{!{\color{table_lines}\vrule}}
\makeatother
\usepackage{tcolorbox} % fancy section
\renewcommand*\footnoterule{} % remove footnote line
\usepackage{array}
\makeatletter
\def\@seccntformat#1{\llap{\csname the#1\endcsname\quad}}
\def\tabularxcolumn#1{m{#1}} % vertical center in tabualrx
\makeatother
\begin{document}
\renewcommand{\tabularxcolumn}[1]{>{\arraybackslash}m{#1}}
\begin{center}
\begin{tabularx}{\textwidth}{' L{0.20} '@{}L{0.53} ' C{0.27} '}
\arrayrulecolor{table_lines}\hline
0 & 11/02/2011 & \raisebox{-0.05cm}{1} \\[0.0775cm]\hline
Hallelujah & 04/17/2012 & \raisebox{-0.05cm}{1} \\[0.0775cm]\hline
1 & 07/05/2013 & \raisebox{-0.05cm}{0} \\[0.0775cm]\arrayrulecolor{table_lines}\hline
\end{tabularx}
\end{center}
\vspace*{0.7cm}
\end{document}
答案1
\raisebox
大多数情况下,由于指定的额外长度导致对齐不准确\\[.]
,但是您还想在每行上方添加一点额外的空间,以补偿降序字符的视觉效果,/
使数字在其行中显得过高。
就像是
\documentclass[a4paper,9pt]{extarticle}
\usepackage[a4paper,left=1.8cm,right=1.8cm,top=2.5cm,bottom=1.4cm,footskip=0cm,headheight=0cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[table]{xcolor}
\usepackage{xcolor}
\definecolor{table_lines}{cmyk}{0, 0, 0, 0.24} % define color
\usepackage{colortbl} % column lines color
\usepackage{tabularx} % different column width
\newcolumntype{L}[1]{>{\hsize=#1\hsize\raggedright\arraybackslash}X}
\newcolumntype{C}[1]{>{\hsize=#1\hsize\centering\arraybackslash}X}
\makeatletter
\newcommand{\thickhline}{\noalign {\hrule height 2pt}}
\newcolumntype{'}{!{\color{table_lines}\vrule}}
\makeatother
\begin{document}
\begin{center}
\renewcommand\arraystretch{1.2}
\addtolength\extrarowheight{1.5pt}
\begin{tabularx}{\textwidth}{' L{0.20} '@{}L{0.53} ' C{0.27} '}
\arrayrulecolor{table_lines}\hline
0 & 11/02/2011 & 1 \\\hline
Hallelujah & 04/17/2012 & 1 \\\hline
1 & 07/05/2013 & 0 \\\arrayrulecolor{table_lines}\hline
\end{tabularx}
\end{center}
\vspace*{0.7cm}
\end{document}
顺便说一句,由于行内没有换行符,tabularx
这里没有太多有用的工作,我只会使用tabular
(虽然垂直间距是相同的)