我在表格中使用“m”列类型时遇到了一些问题。由于某种原因,当使用m
列类型时,内容会稍微向顶部偏移,导致顶部填充减少,底部填充增加,从而导致表格看起来很难看。
我发现了几个关于这个主题的问题,但这些问题似乎都没有使用禁忌\tabulinesep
和\cellcolor
。所以我将这个问题添加到列表中:
如何使tabu
表格正确垂直居中?
例子
\documentclass[a4paper]{article}
\usepackage{colortbl}
\usepackage{lipsum}
\usepackage{tabu}
\usepackage{xcolor}
\definecolor{white}{HTML}{FFFFFF}
\definecolor{darkBlue}{HTML}{015093}
\definecolor{lightBlue}{HTML}{EBF0F5}
\tabulinesep1em
\begin{document}
\section{Correct padding}
\begin{tabu}{X[1,c] |[0.5em,white] X[5,c]}
\cellcolor{darkBlue}\textcolor{white}{Lorem ipsum} &
\cellcolor{lightBlue}\lipsum[5] \\
\end{tabu}
\section{Wrong padding when using 'm' column}
\begin{tabu}{X[1,c,m] |[0.5em,white] X[5,c,m]}
\cellcolor{darkBlue}\textcolor{white}{Lorem ipsum} &
\cellcolor{lightBlue}\lipsum[5] \\
\end{tabu}
\end{document}
答案1
使用\lipsum*
不添加尾随的\par
:
\documentclass[a4paper]{article}
\usepackage{colortbl}
\usepackage{lipsum}
\usepackage{tabu}
\usepackage{xcolor}
\definecolor{white}{HTML}{FFFFFF}
\definecolor{darkBlue}{HTML}{015093}
\definecolor{lightBlue}{HTML}{EBF0F5}
\tabulinesep1em
\begin{document}
\section{Correct padding}
\begin{tabu}{X[1,c] |[0.5em,white] X[5,c]}
\cellcolor{darkBlue}\textcolor{white}{Lorem ipsum} &
\cellcolor{lightBlue}\lipsum*[5] \\
\end{tabu}
\section{Correct padding also when using 'm' column}
\begin{tabu}{X[1,c,m] |[0.5em,white] X[5,c,m]}
\cellcolor{darkBlue}\textcolor{white}{Lorem ipsum} &
\cellcolor{lightBlue}\lipsum*[5] \\
\end{tabu}
\end{document}
答案2
谢谢扎尔科和乌尔丽克·菲舍尔指出这是由\lipsum
而不是\tabu
列m
类型引起的。
例子
\documentclass[a4paper]{article}
\usepackage{colortbl}
\usepackage{lipsum}
\usepackage{tabu}
\usepackage{xcolor}
\definecolor{white}{HTML}{FFFFFF}
\definecolor{darkBlue}{HTML}{015093}
\definecolor{lightBlue}{HTML}{EBF0F5}
\tabulinesep1em
\newcommand\mytext[0]{
Fusce mauris. Vestibulum luctus nibh at lectus. Sed
bibendum, nulla a faucibus semper, leo velit ultricies tellus,
ac venenatis arcu wisi vel nisl. Vestibulum diam. Aliquam
pellentesque, augue quis sagittis posuere, turpis lacus
congue quam, in hendrerit risus eros eget felis. Maecenas
eget erat in sapien mattis porttitor. Vestibulum porttitor.
Nulla facilisi. Sed a turpis eu lacus commodo facilisis.
Morbi fringilla, wisi in dignissim interdum, justo lectus
sagittis dui, et vehicula libero dui cursus dui. Mauris
tempor ligula sed lacus. Duis cursus enim ut augue. Cras
ac magna. Cras nulla. Nulla egestas. Curabitur a leo.
Quisque egestas wisi eget nunc. Nam feugiat lacus vel est.
Curabitur consectetuer.
}
\begin{document}
\begin{tabu}{X[1,c,m] |[0.5em,white] X[5,c,m]}
\cellcolor{darkBlue}\textcolor{white}{Lorem ipsum} &
\cellcolor{lightBlue}\mytext \\
\end{tabu}
\end{document}