5

I'm trying to align the following "equation":

\begin{equation*}
\begin{split} 
A_G &= [ \text{E.id, E.name, E.rank,} \\ 
& \quad \quad \text{P.rank, P.title, P.code,} \\
& \quad \quad \text{S.code, S.amount} ] \\
&= [ 1\ 1\ 1\ 1\ 1\ 1\ 1\ 1 ]
\end{split} 
\end{equation*}

which looks like this:

enter image description here

As one can see, the broken lines don't align well -- I'd like to have "P.rank" and "S.code" both left-align to "E.id". How can one achieve this?

3

In this case you could use align to align.

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
A_G = [& \text{E.id, E.name, E.rank,} \\ 
&  \text{P.rank, P.title, P.code,} \\
&  \text{S.code, S.amount} ] \\
= [& 1\ 1\ 1\ 1\ 1\ 1\ 1\ 1 ]
\end{align*}
\end{document}

enter image description here

  • Thanks! I was trying some stuff with multiple alignment points -- all attempts failed. In general how would multiple alignments work? – Covi Jul 30 '18 at 5:27
5

Here's a solution that uses (a) a \parbox directive to typeset the text material -- no need to insert line breaks by hand and hence to worry about alignment points -- and (b) a bmatrix environment to typeset the row vector.

I chose the width of the \textbox -- 4cm -- so that it reproduces the number of line breaks (2) that appear in the OP's screenshot. By setting the width of the box to 5.5cm, say, the number of line breaks would be reduced from 2 to just 1.

enter image description here

\documentclass{article}
\usepackage{amsmath}
% handy utility macro (the default width is 4cm):
\newcommand\textbox[2][4cm]{\parbox[t]{#1}{\raggedright #2}}

\begin{document}
\begin{equation*}
\begin{split}
A_G &= [\textbox{E.id, E.name, E.rank, P.rank, P.title, P.code, S.code, S.amount]} \\
    &= \begin{bmatrix}
          1 & 1 & 1 & 1 & 1 & 1 & 1 & 1
       \end{bmatrix}
\end{split} 
\end{equation*}
\end{document}
4

Since the material is textual, I suggest tabular (it would be array if the material were math); this also uses less vertical space.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{align*}
A_G &= [
  \begin{tabular}[t]{@{}l@{}}
    E.id, E.name, E.rank, \\
    P.rank, P.title, P.code, \\
    S.code, S.amount$]$
  \end{tabular}
\\
&= \begin{bmatrix} 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \end{bmatrix}
\end{align*}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.