2

How do I go about drawing a line vertically down aligned equations like this:

enter image description here

I attempted using a tabular environment but some of the spacing is too much.

This is what I have so far:

CODE

\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}

4 Answers 4

2

You can put a bunch of [b]ottom-aligned constructions next to one another, separated by a \vrule:

enter image description here

\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}

The \vrules are grouped with an aligned that has a blank top row (using \mathstrut). The \vrule will stretch the vertical length of the construction by default.

4

The blkarray package provides a convenient means to produce aligned (and non-aligned) material with separators spanning different rows, inside a maths environment (such as align). This is done by adding 'blocks' with different column specifications to a 'blockarray' environment defined by the package. In the below code, I use one block per row, simply adding an extra column line for each successive row (note that each block must still have the same number of total columns, albeit empty ones):

\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}

Output:

output

4

Here is a proposition, with tabularreplaced by array, a smaller value for arraycolsep and some improvements:

\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} 

enter image description here

Unrelated: needless to load masfonts when you load amssymb: the latter package already loads it.

1
2

Some spacing is too much? Reduce it.

\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}

enter image description here

1
  • 1
    Please watch out X1 and X2 vertical alignment.
    – user31034
    Feb 13, 2019 at 16:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .