我正在处理下表:
\documentclass{article}
\usepackage{mathtools}
\usepackage{array}
\usepackage{booktabs}
\begin{document}
\begin{table}[htbp]
\caption{Test Cases} % title of Table
\centering % used for centering table
\addtolength{\leftskip} {-2cm}
\addtolength{\rightskip}{-2cm}
\begin{tabular}{l l c c c | c >{\centering\arraybackslash}p{1.5cm}} % columns type and number
\hline\hline %inserts double horizontal lines
Parameters & &NoCross\#1 & NoCross\#2 & NoCross\#3 & Cross\#1 & Cross\#2 \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
mass &[kg] & 1500 & 1500 &1500 & 1500 &1500\\ % inserting body of the table
thrust &[N] & 5000 & 5000 &10000 & 5000 &10000\\
altitude &[km] & 15 & 10 &15 & 15 &15 \\
n2(k): $x_f-x_0$ & & 24.8671 & 25.0002 &14.0379 & 24.8678 &14.0379 13.9663 13.8099\\
n1(k): $x_f-x_0$ & & 24.8671 & 25.0002 &14.0379 & 24.8678 &/\\
n1(k-2): $x_f-x_0$ - 30& & 26.8671 & 27.0002 &16.0379 & 26.8678 &/\\
n1(k-4): $x_f-x_0$ - 60 & & 28.8671 & 29.0002 & / & 28.8678 &/\\ % [1ex] adds vertical space
n1(k+1.5): $x_f-x_0$ + 22.5 & & / & / &12.5379 & / &/\\
diversion j & & / & / & / & $\pm$1.5 &$\pm$1.5/3/4.5\\
\hline %inserts single line
\end{tabular}
\label{table:testcases} % is used to refer this table in the text
\end{table}
\end{document}
我想水平对齐第一列(第 4 行到第 8 行)上的表达式。具体来说,我想让所有表达式都对齐x_f-x_0
。我该怎么做?
答案1
以下是使用两列的三个不同版本,用于表达式,例如n2(k): $x_f-x_0$
。我还包含一个版本,它适合文本宽度,而不允许表格突出到左右边距,同时还使用booktabs
-style 水平线且无垂直线:
\documentclass{article}
\usepackage{mathtools}
\usepackage{array}
\usepackage{booktabs}
\usepackage{makecell}
\begin{document}
\begin{table}[htbp]
\caption{Test Cases} % title of Table
\centering % used for centering table
\addtolength{\leftskip} {-2cm}
\addtolength{\rightskip}{-2cm}
\begin{tabular}{l@{\;}l l c c c | c >{\centering\arraybackslash}p{1.5cm}} % columns type and number
\hline\hline %inserts double horizontal lines
\multicolumn{2}{l}{Parameters}& &NoCross\#1 & NoCross\#2 & NoCross\#3 & Cross\#1 & Cross\#2 \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
\multicolumn{2}{l}{mass} &[kg] & 1500 & 1500 &1500 & 1500 &1500\\ % inserting body of the table
\multicolumn{2}{l}{thrust} &[N] & 5000 & 5000 &10000 & 5000 &10000\\
\multicolumn{2}{l}{altitude} &[km] & 15 & 10 &15 & 15 &15 \\
n2(k):& $x_f-x_0$ & & 24.8671 & 25.0002 &14.0379 & 24.8678 &14.0379 13.9663 13.8099\\
n1(k):& $x_f-x_0$ & & 24.8671 & 25.0002 &14.0379 & 24.8678 &/\\
n1(k-2):& $x_f-x_0 - 30$& & 26.8671 & 27.0002 &16.0379 & 26.8678 &/\\
n1(k-4):& $x_f-x_0 - 60$ & & 28.8671 & 29.0002 & / & 28.8678 &/\\ % [1ex] adds vertical space
n1(k+1.5):& $x_f-x_0 + 22.5$ & & / & / &12.5379 & / &/\\
\multicolumn{2}{l}{diversion j} & & / & / & / & $\pm$1.5 &$\pm$1.5/3/4.5\\
\hline %inserts single line
\end{tabular}
\label{table:testcases} % is used to refer this table in the text
\end{table}
\begin{table}[htbp]
\caption{Test Cases} % title of Table
\centering % used for centering table
\addtolength{\leftskip} {-2cm}
\addtolength{\rightskip}{-2cm}
\begin{tabular}{r@{\;}l l c c c | c >{\centering\arraybackslash}p{1.5cm}} % columns type and number
\hline\hline %inserts double horizontal lines
\multicolumn{2}{l}{Parameters}& &NoCross\#1 & NoCross\#2 & NoCross\#3 & Cross\#1 & Cross\#2 \\ [0.5ex] % inserts table
%heading
\hline % inserts single horizontal line
\multicolumn{2}{c}{mass} &[kg] & 1500 & 1500 &1500 & 1500 &1500\\ % inserting body of the table
\multicolumn{2}{c}{thrust} &[N] & 5000 & 5000 &10000 & 5000 &10000\\
\multicolumn{2}{c}{altitude} &[km] & 15 & 10 &15 & 15 &15 \\
n2(k):& $x_f-x_0$ & & 24.8671 & 25.0002 &14.0379 & 24.8678 &14.0379 13.9663 13.8099\\
n1(k):& $x_f-x_0$ & & 24.8671 & 25.0002 &14.0379 & 24.8678 &/\\
n1(k-2):& $x_f-x_0 - 30$& & 26.8671 & 27.0002 &16.0379 & 26.8678 &/\\
n1(k-4):& $x_f-x_0 - 60$ & & 28.8671 & 29.0002 & / & 28.8678 &/\\ % [1ex] adds vertical space
n1(k+1.5):& $x_f-x_0 + 22.5$ & & / & / &12.5379 & / &/\\
\multicolumn{2}{c}{diversion j} & & / & / & / & $\pm$1.5 &$\pm$1.5/3/4.5\\
\hline %inserts single line
\end{tabular}
\label{table:testcases} % is used to refer this table in the text
\end{table}
\begin{table}[htbp]
\caption{Test Cases} % title of Table
\centering
\setlength{\tabcolsep}{4pt}
\begin{tabular}{l@{\;}l c c c c c}
\toprule
\multicolumn{2}{l}{Parameters} & \multicolumn{3}{c}{NoCross} & \multicolumn{2}{c}{Cross} \\
\cmidrule(r){3-5} \cmidrule(l){6-7}
& & \#1 & \#2 & \#3 & \#1 & \#2 \\
\midrule
\multicolumn{2}{l}{mass [kg]} & 1500 & 1500 & 1500 & 1500 & 1500 \\
\multicolumn{2}{l}{thrust [N]} & 5000 & 5000 & 10000 & 5000 & 10000 \\
\multicolumn{2}{l}{altitude [km]} & 15 & 10 & 15 & 15 & 15 \\
n2(k):& $x_f-x_0$ & 24.8671 & 25.0002 & 14.0379 & 24.8678 & \makecell[t]{14.0379\\ 13.9663\\ 13.8099}\\
n1(k):& $x_f-x_0$ & 24.8671 & 25.0002 & 14.0379 & 24.8678 & \\
n1(k-2):& $x_f-x_0 - 30$ & 26.8671 & 27.0002 & 16.0379 & 26.8678 & \\
n1(k-4):& $x_f-x_0 - 60$ & 28.8671 & 29.0002 & & 28.8678 & \\
n1(k+1.5):& $x_f-x_0 + 22.5$ & & & 12.5379 & & \\
\multicolumn{2}{l}{diversion j} & & & & $\pm$1.5 & $\pm$1.5/3/4.5\\
\bottomrule
\end{tabular}
\label{table:testcases}
\end{table}
\end{document}