我该如何绘制一条垂直向下对齐方程的线,如下所示:
我尝试使用表格环境,但有些间距太大。
这是我目前所拥有的:
代码
\documentclass[10pt]{book}
\usepackage{amsmath,amssymb,amsfonts}
\begin{document}
% Table generated by Excel2LaTeX from sheet 'Sheet1'
\begin{table}[htbp]
\centering
\caption{Add caption}
\begin{tabular}{ccc|ll|ll|l|ll|l}
U1 & = & \multicolumn{1}{c}{X1} & & \multicolumn{1}{c}{} & & \multicolumn{1}{r}{} & \multicolumn{1}{r}{} & & \multicolumn{1}{r}{} & \\
U2 & = & X2 & & \multicolumn{1}{c}{} & & \multicolumn{1}{r}{} & \multicolumn{1}{r}{} & & \multicolumn{1}{r}{} & \\
U3 & = & X3 & + & X1 & & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} & & \multicolumn{1}{l}{} & \\
& = & & & & + & X2 & \multicolumn{1}{l}{} & & \multicolumn{1}{l}{} & \\
Un & = & Xn & & & & & … & + & Xn-1 & \\
Sn & = & & & & & & & & & Xn \\
\end{tabular}%
\label{tab:addlabel}%
\end{table}%
\end{document}
答案1
您可以将一堆[b]
ottom-aligned
结构并排放置,并用\vrule
:分隔。
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\begin{aligned}[b]
U_1 &= X_1 \\
U_2 &= X_2 \\
U_3 &= X_3 \\
\\ \\
U_n &= X_n \\
S &= \mathstrut
\end{aligned}
{\vrule\begin{aligned}[b]
\mathstrut \\ {}+ X'_1 \\ \mathstrut \\ \mathstrut \\ \mathstrut \\ \mathstrut
\end{aligned}}
{\vrule\begin{aligned}[b]
\mathstrut \\ {}+ X'_2 \\ \mathstrut \\ \mathstrut \\ \mathstrut
\end{aligned}}
{\vrule\begin{aligned}[b]
\mathstrut \\ {}+ X'_3 \\ \mathstrut \\ \mathstrut
\end{aligned}}
{\vrule\begin{aligned}[b]
\mathstrut \\ \quad\cdots\quad \\ \mathstrut
\end{aligned}}
{\vrule\begin{aligned}[b]
\mathstrut \\ {}+ X'_{n-1}
\end{aligned}}
\]
\end{document}
s\vrule
与 组合在一起,aligned
其顶部有一空白行(使用\mathstrut
)。\vrule
默认情况下,将拉伸构造的垂直长度。
答案2
该blkarray
包提供了一种方便的方法来在数学环境(如 align)中生成对齐(和非对齐)材料,其中分隔符跨越不同的行。这是通过将具有不同列规范的“块”添加到包定义的“blockarray”环境中来实现的。在下面的代码中,我每行使用一个块,只需为每个连续行添加一个额外的列线(请注意,每个块仍然必须具有相同的总列数,尽管是空的):
\documentclass[10pt]{book}
\usepackage{amsmath}
\usepackage{blkarray}
\begin{document}
\begin{align*}
\begin{blockarray}{cccccc}
\begin{block}{cccccc}
U_1=X_1&&&&&\\ % Row 1
\end{block}
\begin{block}{c|ccccc}
U_2=X_1&&&&&\\ % Row 2
\end{block}
\begin{block}{c|c|cccc}
U_3=X_3&+X_1'&&&&\\ % Row 3
\end{block}
\begin{block}{c|c|c|ccc}
&&+X_2'&&&\\ % Row 4
\end{block}
\begin{block}{c|c|c|c|cc}
&&&&&\\ % Row 5
\end{block}
\begin{block}{c|c|c|c|c|c}
U_n=X_n &&&\ldots&+X_{n-1}'&\\ % Row 6
\end{block}
\begin{block}{c|c|c|c|c|c}
s=\phantom{x}&&&&&+X_n'\\ % Row 7
\end{block}
\end{blockarray}
\end{align*}
\end{document}
输出:
答案3
这是一个建议,用tabular
代替array
,取较小的值arraycolsep
并进行一些改进:
\documentclass[10pt]{book}
\usepackage{amsmath,amssymb}
\usepackage{makebox}
\begin{document}
% Table generated by Excel2LaTeX from sheet 'Sheet1'
\begin{table}[htbp]
\centering \setlength{\arraycolsep}{3pt}
\caption{Add caption}\[
\begin{array}{c@{{}={}}c|ll|ll|l|ll|l}
U_1 & X_1 \\
U_2 & X_2 & \\
U_3 & X_3 & + & X_1 \\
\multicolumn{1}{c}{\makebox*{$U_3$}{ $ \smash[t]{\vdots} $\hspace{1.5em}}} & \smash[t]{\vdots} & & & + & X_2 \\
U_n & X_n & & & & & \cdots & + & X_{n-1} \\
S_n & & & & & & & & & X_n \\
\end{array} \]%
\label{tab:addlabel}%
\end{table}%
\end{document}
无关masfonts
:加载时无需加载amssymb
:后者包已经加载它了。
答案4
有些间距太大?减少它。
\documentclass[10pt]{book}
\usepackage{amsmath,amssymb,amsfonts}
\begin{document}
\begin{table}[htbp]
\centering
\caption{Add caption}
\begin{tabular}{c@{\ }c@{}c|l@{\ }l|l@{\ }l|l|l@{\ }l|l}
U1 & = & \multicolumn{1}{c}{X1} & & \multicolumn{1}{c}{} & & \multicolumn{1}{r}{} & \multicolumn{1}{r}{} & & \multicolumn{1}{r}{} & \\
U2 & = & X2 & & \multicolumn{1}{c}{} & & \multicolumn{1}{r}{} & \multicolumn{1}{r}{} & & \multicolumn{1}{r}{} & \\
U3 & = & X3 & + & X1 & & \multicolumn{1}{l}{} & \multicolumn{1}{l}{} & & \multicolumn{1}{l}{} & \\
& = & & & & + & X2 & \multicolumn{1}{l}{} & & \multicolumn{1}{l}{} & \\
Un & = & Xn & & & & & … & + & Xn-1 & \\
Sn & = & & & & & & & & & Xn \\
\end{tabular}%
\label{tab:addlabel}%
\end{table}%
\end{document}