我如何左对齐文本并对齐这些等号?至于我使用的等号\,
,它有点用,但我希望更接近。有没有比这更小的间距或任何更好地对齐这些等号的方法?
预期的输出是这样的。
\documentclass{article}
\usepackage[utf8]{inputenc}
\begin{document}
Input data \,\, = 2000\\
Deleted data \,\,\,\,\,\,\,\,= 500\\
Remaining data = 2000 - 500 =1500
\end{document}
抱歉,我可能应该提到我要将文本放在这样的表格中。@Mico 给出的解决方案有效,但在这个表格中无效。所以我认为表格以某种方式改变了格式。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\begin{document}
\begin{table}[]
\centering
\caption{This is a table}
\label{tab: this is a table}
\begin{tabular}{cc} \\ \toprule
\textbf{No} & \textbf{Example} \\ \midrule
1 & 9 \\
2 & 5 \\
3 & 3 \\ \midrule
\multicolumn{2}{l}{\begin{tabular}[c]{@{}l@{}}
\[
\setlength\arraycolsep{0pt}
\begin{array}{ L @{{}={}} l }
\text{Input data} & 2000 \\
\text{Deleted data} & 500 \\
\text{Remaining data} & 2000-500=1500
\end{array}
\]
\end{tabular}} \\ \bottomrule
\end{tabular}
\end{table}
\end{document}
答案1
这是一个array
基于不同的解决方案。
\documentclass{article}
\usepackage{array} % for \newcolumntype macro
\newcolumntype{L}{>{$}l<{$}}
\begin{document}
\[
\setlength\arraycolsep{0pt}
\begin{array}{ L @{{}={}} l }
Input data & 2000 \\
Deleted data & 500 \\
Remaning data & 2000-500=1500
\end{array}
\]
\end{document}
附录:下面是我修改 OP 的附加示例代码以嵌入array
双列tabular
环境的方法:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs,amsmath,array}
\newcolumntype{L}{>{$}l<{$}}
\begin{document}
\begin{table}[h]
\centering
\caption{This is a table\strut}
\label{tab:this is a table}
\begin{tabular}{@{} cc @{}}
\toprule
\textbf{No} & \textbf{Example} \\
\midrule
1 & 9 \\
2 & 5 \\
3 & 3 \\
\midrule
\multicolumn{2}{@{}c@{}}{%
\setlength\arraycolsep{0pt}$
\begin{array}{ L @{{}={}} l }
Input data & 2000 \\
Deleted data & 500 \\
Remaining data & 2000-500=1500
\end{array}$
} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
很少使用但不应忘记:tabbing
环境。然而,在表格中,您需要将其包装在\parbox
或类似内容中。
(我将数字置于数学模式,以便排版更美观。)
\documentclass{article}
\begin{document}
\begin{tabbing}
Remaining data \= \kill % needed to define the position of the tab
Input data \>$= 2000$ \\
Deleted data \>$= 500$ \\
Remaining data \>$= 2000 - 500 = 1500$
\end{tabbing}
\end{document}
编辑
考虑到您想将其放置在已经嵌套的表格单元格内tabular
,为什么不执行以下操作呢:
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}
\centering
\caption{This is a table}
\label{tab: this is a table}
\begin{tabular}{cc} \\ \toprule
\textbf{No} & \textbf{Example} \\ \midrule
1 & 9 \\
2 & 5 \\
3 & 3 \\ \midrule
\multicolumn{2}{l}{
\begin{tabular}[c]{@{}ll@{}}
Input data & $2000$ \\
Deleted data & $500$ \\
Remaining data & $2000-500=1500$
\end{tabular}
} \\ \bottomrule
\end{tabular}
\end{table}
\end{document}
p{}
如果要指定某一列的用途,可以使用列类型:
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}
\centering
\caption{This is a table}
\label{tab: this is a table}
\begin{tabular}{cc} \\ \toprule
\textbf{No} & \textbf{Example} \\ \midrule
1 & 9 \\
2 & 5 \\
3 & 3 \\ \midrule
\multicolumn{2}{l}{
\begin{tabular}[c]{@{}p{4cm}l@{}}
Input data & $2000$ \\
Deleted data & $500$ \\
Remaining data & $2000-500=1500$
\end{tabular}
} \\ \bottomrule
\end{tabular}
\end{table}
\end{document}
答案3
这使用表格并@{$\null =\null$}
在列之间添加正确间距的等号。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\begin{document}
\begin{table}[]
\centering
\caption{This is a table}
\label{tab: this is a table}
\begin{tabular}{cc} \\ \toprule
\textbf{No} & \textbf{Example} \\ \midrule
1 & 9 \\
2 & 5 \\
3 & 3 \\ \midrule
\multicolumn{2}{l}{\begin{tabular}{@{}l@{$\null =\null$}l}
Input data & 2000 \\
Deleted data & 500 \\
Remaining data & $2000-500=1500$
\end{tabular}} \\ \bottomrule
\end{tabular}
\end{table}
\end{document}
答案4
您可以使用array
仅在数学模式下有效的环境。
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\begin{array}{ll}
\text{Input data} &= 2000 \\
\text{Deleted data} &= 500 \\
\text{Remaining data} &= 2000 - 500 = 1500
\end{array}
\]
\end{document}