我讀了很多關於 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
答案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}