多行 tabularx-cells 垂直居中时边距不均匀

多行 tabularx-cells 垂直居中时边距不均匀

我阅读了很多关于 tabularx-tables 中垂直居中的资料,并找到了一个通用的解决方案。但是,当单元格中有多个行时,边距似乎不对齐。

您可以看到,在顶行最右侧的单元格中,底部没有边距。此外,在第二行中,圆圈似乎没有在中间完美对齐,而在第三行中看起来不错。

我将非常感激任何关于如何解决此问题的想法!

在此处输入图片描述

\documentclass[a4paper,10pt,BCOR10mm,oneside,headsepline]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{wasysym}
\usepackage{enumitem}
\usepackage{color}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{typearea}
\usepackage[T1]{fontenc}
\usepackage[table]{xcolor}    % loads also »colortbl«
\areaset{17cm}{26cm}
\setlength{\topmargin}{-1cm}

\begin{document}

\newcolumntype{P}[1]{>{\centering\arraybackslash}m{#1}}
\renewcommand{\tabularxcolumn}[1]{m{#1}}

\setlength{\extrarowheight}{0.35cm}

\newcommand{\QO}{\huge{\textbf{$\Circle$}}\small}

\rowcolors{2}{gray!5}{gray!25}
\begin{tabularx}{\linewidth}{cX*{4}{P{1.5cm}}}%
   \rowcolor{gray!50}
   \textbf{1.} & \textbf{A very very very super long question, that is going to be split for sure\dots \newline (Something else)}
   & short & longer & little longer & super-duper mega very very very long \\[1em]%
   & short & \QO & \QO & \QO & \QO\\[1em]
   & Very long, will most propably span multiple lines. Might even mess up the formatting a little bit\dots & \QO & \QO & \QO & \QO\\[1em]
\end{tabularx}

\end{document}

答案1

这是使用cellspace包的解决方案,它使用以字母 为前缀的说明符来定义列中单元格顶部和底部的最小垂直填充S。我借此机会简化了 的定义\QO

\documentclass[a4paper,10pt,BCOR10mm,oneside,headsepline]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{wasysym, amssymb, amsfonts, bm}
\usepackage{enumitem}
\usepackage{color}
\usepackage{tabularx}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\usepackage{booktabs}
\usepackage{typearea}
\usepackage[T1]{fontenc}
\usepackage[table]{xcolor} % loads also »colortbl«
\areaset{17cm}{26cm}
\setlength{\topmargin}{-1cm}
\newcolumntype{P}[1]{>{\centering\arraybackslash}S{m{#1}}}
\renewcommand{\tabularxcolumn}[1]{m{#1}}

\newcommand{\QO}{\textbf{\huge\Circle}}

\usepackage{cellspace}
\setlength{\cellspacetoplimit}{2ex}
\setlength{\cellspacebottomlimit}{2ex}
\addparagraphcolumntypes{X}

\begin{document}

\rowcolors{2}{gray!5}{gray!25}
\begin{tabularx}{\linewidth}{cS{X}*{4}{P{1.5cm}}}%
   \rowcolor{gray!50}
   \textbf{1.} & \textbf{A very very very super long question, that is going to be split for sure\dots \newline (Something else)}
   & short & longer & little longer & super-duper mega very very very long \\
   & short & \QO & \QO & \QO & \QO \\
   & Very long, will most probably span multiple lines. Might even mess up the formatting a little bit\dots & \QO & \QO & \QO & \QO\\
\end{tabularx}

\end{document} 

在此处输入图片描述

答案2

圆圈定义影响周围的文字

\newcommand{\QO}{\textbf{\huge$\Circle$}}

会是一个更好的定义,但如果你这样做会更清楚

\newcommand{\QO}{!\dotfill\textbf{\huge$\Circle$}\dotfill!}

在此处输入图片描述

在这里您可以看到....基线与的基线对齐Short,但由于圆的大部分位于基线之上,因此它在单元格中显得更高。

答案3

正如大卫·卡莱尔指出的那样他的回答,您的定义\QO将圆圈放在(印刷)基线上。由于它的尺寸很大(字面意思\huge:),它最终看起来像是向上移动了不少。补救措施是将中心垂直置于数学轴上。(为了形象化数学轴的高度:数学符号-+放置在此轴上。)

在此处输入图片描述

上述图片由

ABC\dots$\bm\Circle$\dots\QOa\dots$-$\QOb$-$\dots XYZ

在哪里

\newcommand{\QOa}{\textbf{\huge$\Circle$}} % OP's definition, improved
\newcommand{\QOb}{$\vcenter{\hbox{\huge$\bm\Circle$}}$} % proposed new def.

无论如何,如果将圆圈放在数学线上,表格看起来不错(至少在我看来)。

在此处输入图片描述

\documentclass[paper=a4,  fontsize=10pt,
               BCOR=10mm, twoside=false, 
               headsepline]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{wasysym} % for "\Circle" macro
\usepackage{enumitem}
%%\usepackage{color} % don't load both 'color' and 'xcolor'
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{typearea}
\usepackage[T1]{fontenc}
\usepackage[table]{xcolor}    % loads also »colortbl«
\areaset{17cm}{26cm}
\setlength{\topmargin}{-1cm}

\usepackage{bm} % for "\bm" macro
%% center the circle (vertically) on the math axis:
\newcommand{\QO}{$\vcenter{\hbox{\huge$\bm\Circle$}}$}

\newcolumntype{P}[1]{>{\centering\arraybackslash}m{#1}}
\renewcommand{\tabularxcolumn}[1]{m{#1}}

\setlength{\extrarowheight}{0.35cm}

\begin{document}

\noindent % <-- don't forget this instruction
\rowcolors{2}{gray!5}{gray!25}
\begin{tabularx}{\linewidth}{cX*{4}{P{1.5cm}}}%
   \rowcolor{gray!50}
   \textbf{1.} 
   & \textbf{A very very very super long question, that is 
     going to be split for sure\dots   
   \newline (Something else)}
   & short & longer & little longer 
   & super-duper mega very very very long \\[1em]%
   & short & \QO & \QO & \QO & \QO\\[1em]
   & Very long, will most propably span multiple lines. 
     Might even mess up the formatting a little bit\dots 
           & \QO & \QO & \QO & \QO\\[1em]
\end{tabularx}

\end{document}

相关内容