3

I wanted to align two enumerated item lists horizontally like in the post shown here, however, my alignment is skewed from one item to the other. Bascially, I wanted help to get both items aligned at the "=" sign. Can you help me fix this issue?

Here is my code:

\documentclass{book}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{mathptmx}
\usepackage{enumitem} % Customize lists

\begin{document}

\begin{enumerate}[align=left,style=nextline,leftmargin=*,labelsep=\parindent,label=\textbf{(\alph*)}]
\item\hfill$\begin{aligned}[t]
P(1) & = 3.1479 \\
K(1) & = 0.786986\\
\hat{x}(1) & = 0 + 0.786986(1.5-0)\\
& = 1.1805
\end{aligned}$\hfill\null\\
\item \hfill$\begin{aligned}[t]
P(2) & = 3.1431\\
K(2) & = 0.7870\\
\hat{x}(2) & = 1.1805 + 0.786986(3.0-1.1805)\\
& = 2.6124
\end{aligned}$\hfill\null
\end{enumerate}

\end{document}
3

This with list is not possible (at least simple) to achieve. I sugest to use flalign math environment:

\documentclass{book}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{mathptmx}

    \begin{document}
\begin{flalign*}
\textbf{(a)}    &&  P(1)        & = 3.1479              &&  \\
                &&  K(1)        & = 0.786986            &&  \\
                &&  \hat{x}(1)  & = 0 + 0.786986(1.5-0) &&  \\
                &&              & = 1.1805              &&  \\[1ex]
\textbf{(b)}    &&  P(2)        & = 3.1431              &&  \\
                &&  K(2)        & = 0.7870              &&  \\
                &&  \hat{x}(2)  & = 1.1805 + 0.786986(3.0-1.1805)
                                                        &&  \\
                &&              & = 2.6124              &&
\end{flalign*}
    \end{document}

enter image description here

  • Is this so different from my answer? – egreg Nov 21 '15 at 18:37
  • @cfr, when I load up my answer my browser doesn't show yours (again, I'm time to time faced with this problem) , so I wasn't aware on it. Result are the same, only your approach is more sophisticated than mine. I learned something new. Congratulations! – Zarko Nov 21 '15 at 19:08
4

Not very nice input, but not worse than your attempt:

\documentclass{book}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{mathptmx}
\usepackage{enumitem} % Customize lists

\newenvironment{enumeratealign}
 {\setcounter{enumi}{0}\renewcommand{\theenumi}{\alph{enumi}}\csname flalign*\endcsname}
 {\endalign}
\makeatletter
\newcommand{\alignitem}{%
  \refstepcounter{enumi}%
  \textbf{(\theenumi)}%
  \let\label\ltx@label
}
\makeatletter

\begin{document}

\begin{enumeratealign}
&\alignitem\label{first} &
    P(1)       &= 3.1479 &&\\
&&  K(1)       &= 0.786986 &&\\
&&  \hat{x}(1) &= 0 + 0.786986(1.5-0) &&\\
&&             &= 1.1805 &&\\
\\
&\alignitem &
    P(2)       &= 3.1431 &&\\
&&  K(2)       &= 0.7870 &&\\
&&  \hat{x}(2) &= 1.1805 + 0.786986(3.0-1.1805) &&\\
&&             &= 2.6124 &&
\end{enumeratealign}

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