3
\[
  \begin{split}\int_{0}^{2\pi} &f(x)\cos(nx)dx =\frac{a_0}{2}\int_{0}^{2\pi}\cos(nx)dx\\
  &+a_1\boxed{\int_{0}^{2\pi}cos(x)\cos(nx)dx}+a_2 \boxed{\int_{0}^{2\pi}\cos(2x)\cos(nx)dx}+...\\
  &+a_n\boxed{\int_{0}^{2\pi}\cos^2(nx)dx} \\
  &+ b_1\boxed{\int_{0}^{2\pi}\sin(x)\cos(nx)dx} +b_2\boxed {\int_{0}^{2\pi}\sin(2x)\cos(nx)dx} + ...\\ &+b_n\boxed{\int_{0}^{2\pi}\sin(nx)\cos(nx)dx} 
  \end{split}
\]

Hi, I am still new in Latex and want some help.

If you run this code, you see a_n and b_n go to the second line. I want to keep a_1,a_2+...+a_n in one line so do b_1 and b_2,b_n.

I want to arrange them properly. I am still confused how to use & \ and split and other functions to arrange any equations.

your help is greatly appreciated

3
  • Please write a minimal working example. See link for more details what it means. // Please format your code. See How do I format code blocks?
    – user202729
    Commented Jan 23, 2022 at 4:57
  • You inserted a line break \\ and an alignment marker & before both the a_n and b_n terms. Just remove those. (Of course, potentially what you wrote will not fit on one line.) Commented Jan 23, 2022 at 5:32
  • See also the explanation here: tex.stackexchange.com/a/424625/119 Commented Jan 23, 2022 at 5:35

2 Answers 2

3

You need some more generous text width, here obtained with geometry.

I'd emphasize the symmetries, using an alignedat enviroment to align the coefficients.

\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage{amsmath}

\newcommand{\diff}{\mathop{}\!d}

\begin{document}

\[
\newcommand{\rboxed}[1]{\,\boxed{\!#1\!}}% local command
\begin{split}
&\int_{0}^{2\pi}f(x)\cos(nx)\diff x =\frac{a_0}{2}\int_{0}^{2\pi}\cos(nx)\diff x \\
&\quad\begin{alignedat}[t]{7}
   &+a_1&&\rboxed{\int_{0}^{2\pi}\cos(x)\cos(nx)\diff x}
  &&+a_2&&\rboxed{\int_{0}^{2\pi}\cos(2x)\cos(nx)\diff x}
  &&+\dotsb
  &&+a_n&&\rboxed{\int_{0}^{2\pi}\cos(nx)\cos(nx)\diff x} \\
   &+b_1&&\rboxed{\int_{0}^{2\pi}\sin(x)\cos(nx)\diff x}
  &&+b_2&&\rboxed{\int_{0}^{2\pi}\sin(2x)\cos(nx)\diff x}
  &&+\dotsb
  &&+b_n&&\rboxed{\int_{0}^{2\pi}\sin(nx)\cos(nx)\diff x}
  \end{alignedat}
\end{split}
\]

\end{document}

enter image description here

We can improve by making the boxes into equal width by adding the difference in width between “sin” and “cos”:

\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage{amsmath}

\newcommand{\diff}{\mathop{}\!d}

\begin{document}

\[
\newcommand{\rboxed}[1]{\,\boxed{\!#1\!}}% local command
\settowidth{\dimen8}{$\cos$}%
\settowidth{\dimen2}{$\sin$}%
\addtolength{\dimen8}{-\dimen2}%
\begin{split}
&\int_{0}^{2\pi}f(x)\cos(nx)\diff x =\frac{a_0}{2}\int_{0}^{2\pi}\cos(nx)\diff x \\
&\quad\begin{alignedat}[t]{7}
   &+a_1&&\rboxed{\int_{0}^{2\pi}\cos(x)\cos(nx)\diff x}
  &&+a_2&&\rboxed{\int_{0}^{2\pi}\cos(2x)\cos(nx)\diff x}
  &&+\dotsb
  &&+a_n&&\rboxed{\int_{0}^{2\pi}\cos(nx)\cos(nx)\diff x} \\
   &+b_1&&\rboxed{\int_{0}^{2\pi}\sin(x)\cos(nx)\diff x \kern\dimen8}
  &&+b_2&&\rboxed{\int_{0}^{2\pi}\sin(2x)\cos(nx)\diff x \kern\dimen8}
  &&+\dotsb
  &&+b_n&&\rboxed{\int_{0}^{2\pi}\sin(nx)\cos(nx)\diff x \kern\dimen8}
  \end{alignedat}
\end{split}
\]

\end{document}

enter image description here

4

I'd like to suggest that you not use a split environment (or its close sibling, the aligned environment). Instead, I'd recommend you employ a multline* environment, especially since the integral expressions vary considerable in width, making it unappealing to employ an align* env.

The following screenshots shows solutions that employ a multline* and an align* environment. Note that I've tried to save some (horizontal) whitespace by a triple negative whitespace after all \int terms and changing \boxed{...} to `\boxed{!...!}.

enter image description here

\documentclass{article}
\usepackage[a4paper,margin=2.5cm]{geometry} % set page margins as needed
\usepackage{amsmath}

\begin{document}
    
\begin{multline*}
\int_{0}^{2\pi}\! f(x)\cos(nx)\,dx 
   = \frac{1}{2}a_0\!\int_{0}^{2\pi}\!\!\!\cos(nx)\,dx\\
   + a_1\boxed{\!\int_{0}^{2\pi}\!\!\!\cos(x)\cos(nx)\,dx\!}
   + a_2 \boxed{\!\int_{0}^{2\pi}\!\!\!\cos(2x)\cos(nx)\,dx\!}
   + \dots
   + a_n\boxed{\!\int_{0}^{2\pi}\!\!\!\cos^2(nx)\,dx\!}  \\
   + b_1\boxed{\!\int_{0}^{2\pi}\!\!\!\sin(x)\cos(nx)\,dx\!} 
   + b_2\boxed {\!\int_{0}^{2\pi}\!\!\!\sin(2x)\cos(nx)\,dx\!} 
   + \dots
   + b_n\boxed{\!\int_{0}^{2\pi}\!\!\!\sin(nx)\cos(nx)\,dx\!} 
\end{multline*}

\begin{align*}
\int_{0}^{2\pi}\! f(x)&\cos(nx)\,dx 
  = \frac{1}{2}a_0\!\int_{0}^{2\pi}\!\!\!\cos(nx)\,dx\\
 &+ a_1\boxed{\!\int_{0}^{2\pi}\!\!\!\cos(x)\cos(nx)\,dx\!}
  + a_2 \boxed{\!\int_{0}^{2\pi}\!\!\!\cos(2x)\cos(nx)\,dx\!}
  + \dots
  + a_n\boxed{\!\int_{0}^{2\pi}\!\!\!\cos^2(nx)\,dx\!}  \\
 &+ b_1\boxed{\!\int_{0}^{2\pi}\!\!\!\sin(x)\cos(nx)\,dx\!} 
  + b_2\boxed {\!\int_{0}^{2\pi}\!\!\!\sin(2x)\cos(nx)\,dx\!} 
  + \dots
  + b_n\boxed{\!\int_{0}^{2\pi}\!\!\!\sin(nx)\cos(nx)\,dx\!} 
\end{align*}

\end{document}

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