我想知道为什么 \color 命令会改变固定宽度表格中的垂直对齐方式。
\documentclass{article}
\usepackage[table]{xcolor}
\begin{document}
\begin{tabular}{l | l}
\hline
\color{red} why is this & aligned with this? \\
\hline
\end{tabular}
\vspace{1cm}
\begin{tabular}{p{0.3\textwidth} | p{0.3\textwidth}}
\hline
\color{red} but this & not aligned with this? \\
\hline
\end{tabular}
\end{document}
编辑:当然还有后续问题:有没有简单的方法可以解决这个问题?
答案1
我的建议是使用正确的语法\textcolor{red}{but this}
而不是\color{red} but this
。
\documentclass{article}
\usepackage[table]{xcolor}
\begin{document}
\begin{tabular}{l | l}
\hline
why is this & aligned with this? \\
\hline
\end{tabular}
\vspace{1cm}
\begin{tabular}{p{0.3\textwidth} | p{0.3\textwidth}}
\hline
\textcolor{red}{but this} & not aligned with this? \\
\hline
\end{tabular}
\end{document}