是否可以不太复杂地使列宽相同?
\begin{table}[h]
\centering
\label{my-label}
\begin{tabular}{@{}c|c@{}}
\toprule
\textbf{Injection Pressure {[}bar{]}} & \textbf{Time {[}s{]}} \\ \hline
1.0 & 120 \\
1.5 & 120 \\
2.0 & 90 \\
2.5 & 90 \\
3.0 & 90 \\
4.0 & 60 \\
5.0 & 60 \\
6.0 & 60 \\ \bottomrule
\end{tabular}
\caption{Various injection pressures and time setting}
\end{table}
答案1
取决于你对“太复杂”的定义。你可以简单地用 指定列的宽度p{5cm}
。或者如果你想让它们居中:
\documentclass{article}
\usepackage{booktabs}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{@{}P{5cm}P{5cm}@{}}
\toprule
\textbf{Injection Pressure [bar]} & \textbf{Time {[}s{]}} \\ \hline
1.0 & 120 \\
1.5 & 120 \\
2.0 & 90 \\
2.5 & 90 \\
3.0 & 90 \\
4.0 & 60 \\
5.0 & 60 \\
6.0 & 60 \\ \bottomrule
\end{tabular}
\caption{Various injection pressures and time setting}
\label{my-label}
\end{table}
\end{document}
(基于如何使表格中的列值居中?)
答案2
使用 ,siunitx
您只需设置S
列宽。我还加载了makecell
列标题的常见格式。\thead
(和\makecell
,此处未使用)命令允许在其内容中进行换行:
\documentclass{article}
\usepackage{makecell}
\renewcommand\theadfont{\normalsize\bfseries}
\usepackage{siunitx}
\begin{document}
\begin{table}[!htb]
\centering\sisetup{table-number-alignment=center, table-column-width=3cm}
\setlength\extrarowheight{2pt}
\label{my-label}
\begin{tabular}{S[table-format=1.1] | S[table-format=3.0] }
\Xhline{1pt}
{\thead{Injection \\ Pressure [bar]}} & {\thead{Time [s]}} \\
\hline
1.0 & 120 \\
1.5 & 120 \\
2.0 & 90 \\
2.5 & 90 \\
3.0 & 90 \\
4.0 & 60 \\
5.0 & 60 \\
6.0 & 60 \\
\Xhline{1pt}
\end{tabular}
\caption{Various injection pressures and time setting}
\end{table}
\end{document}
答案3
或者使用tabularx
“非常复杂/精致”的方式:
\documentclass{article}
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcommand\mcxl[1]{\multicolumn{1}{C|}{\bfseries #1}}
\newcommand\mcx[1]{\multicolumn{1}{C }{\bfseries #1}}
\usepackage{siunitx}
\begin{document}
\begin{table}[h]
\centering
\renewcommand\arraystretch{1.2}
\begin{tabularx}{0.5\linewidth}{S[table-format=1.1] | S[table-format=3.0] }
\hline
\mcxl{Injection\par Pressure [bar]}
& \mcx{Time\par [s]} \\ \hline
1.0 & 120 \\
1.5 & 120 \\
2.0 & 90 \\
2.5 & 90 \\
3.0 & 90 \\
4.0 & 60 \\
5.0 & 60 \\
6.0 & 60 \\ \hline
\end{tabularx}
\caption{Various injection pressures and time setting}
\label{my-label}
\end{table}
\end{document}