我想将一些列值居中,因此使用 P{'width'}。但这会弄乱我的表格分隔符。
乳胶:
\begin{table}[H]
\centering
\begin{tabular}{p{3cm}|P{1cm}|P{1cm}|P{1cm}|P{1cm}|P{1cm}|P{1cm}}
\textbf{Sentences} & \textbf{the} & \textbf{red} & \textbf{dog} & \textbf{cat} & \textbf{eats} & \textbf{food} \\
\hline
the red dog & 1 & 1 & 1 & 0 & 0 & 0\\
cat eats dog & 0 & 0 & 1 & 1 & 1 & 0\\
dog eats food & 0 & 0 & 1 & 0 & 1 & 1\\
red cat eats & 0 & 1 & 0 & 1 & 1 & 0\\
\hline
\end{tabular}
\end{table}
输出:
我该如何保留分隔线?
答案1
据我了解您想要什么,可以通过最近定义的列类型来获得wc
:
\documentclass{article}
\usepackage{array}
\usepackage{float}
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{p{3cm}*{6}{|wc{1cm}}}
\textbf{Sentences} & \textbf{the} & \textbf{red} & \textbf{dog} & \textbf{cat} & \textbf{eats} & \textbf{food} \\
\hline
the red dog & 1 & 1 & 1 & 0 & 0 & 0\\
cat eats dog & 0 & 0 & 1 & 1 & 1 & 0\\
dog eats food & 0 & 0 & 1 & 0 & 1 & 1\\
red cat eats & 0 & 1 & 0 & 1 & 1 & 0\\
\hline
\end{tabular}
\end{table}
\end{document}