我想要一张看起来像的桌子
然而,当使用
\begin{tabular}{|p{2cm}|p{3cm}|p{3cm}|p{3cm}|}
\hline Time-Scale & Mechanical Machine State Variables & Electrical Machine State Variables & Power Electronics State Variables \\
\hline Mechanical Machine (Slowest)
& Dynamic & Instantaneous & Instantaneous \\
\hline Electrical Machine (Middle)
& Frozen & Dynamic & Instantaneous \\
\hline Power Electronics (Fastest)
& Frozen & Frozen & Dynamic \\
\hline
\end{tabular}
我得到一张难看的表格:
我怎样才能使每个框中的文本居中以及如何将一个框中的文本分成多行?(当我尝试在单词之间使用 \ 时,它将其视为一个新的表格条目。)
从之前的帖子中,我看到使用 tabularx 代替 tabular 是一种可行的解决方案。这是推荐的解决方案吗?
有没有一种方法可以固定列宽并防止单词部分出现在一行的末尾而部分出现在下一行的开头,而不是手动输入新行?
谢谢你,
凯文
答案1
% arara: pdflatex
\documentclass{article}
\usepackage{array}
\newcommand{\specialcell}[1]{\begin{tabular}{@{}c@{}}#1\end{tabular}}
\begin{document}
\begin{table}
\centering
\begin{tabular}{|c|c|c|c|}
\hline
\bfseries Time-Scale & \bfseries\specialcell{Mechanical\\Machine State\\Variables} & \bfseries\specialcell{Electrical\\Machine State\\Variables} & \bfseries\specialcell{Power\\Electronics State\\Variables} \\
\hline
\specialcell{Mechanical\\Machine\\(Slowest)} & Dynamic & Instantaneous & Instantaneous \\
\hline
\specialcell{Electrical\\Machine\\(Middle)} & Frozen & Dynamic & Instantaneous \\
\hline
\specialcell{Power\\Electronics\\(Fastest)} & Frozen & Frozen & Dynamic \\
\hline
\end{tabular}
\end{table}
\end{document}
更好读的是:
\documentclass{article}
\newcommand{\specialcell}[1]{\begin{tabular}{@{}l@{}}#1\end{tabular}}
\usepackage{booktabs}
\begin{document}
\begin{table}
\centering
\begin{tabular}{*{4}{l}}
\toprule
Time-Scale & \specialcell{Mechanical\\Machine State\\Variables} & \specialcell{Electrical\\Machine State\\Variables} & \specialcell{Power\\Electronics State\\Variables} \\
\midrule
\specialcell{Mechanical\\Machine\\(Slowest)} & Dynamic & Instantaneous & Instantaneous \\\addlinespace
\specialcell{Electrical\\Machine\\(Middle)} & Frozen & Dynamic & Instantaneous \\\addlinespace
\specialcell{Power\\Electronics\\(Fastest)} & Frozen & Frozen & Dynamic \\
\bottomrule
\end{tabular}
\end{table}
\end{document}