3

I am currently trying to get this kind of alignement :

enter image description here

By using the aligned-overset package, i have managed to come up with :

This is tedious and not very good :

%%%%%%%%%%% préambule %%%%%%%%%%%
% chercher les packages https://www.ctan.org/search?phrase=%
%
%% pour le document %%
\documentclass[11pt,a4paper]{article}%
\usepackage[margin=3cm]{geometry}% pour gérer les dimensions
\usepackage[french]{babel}% rajouter éventuellement english, greek, etc.
\usepackage[T1]{fontenc}% gestion des accents (pour les pdf)
\usepackage[utf8]{inputenc}% encodage du fichier source
\usepackage{xcolor}% pour gérer les couleurs
\usepackage{fancyhdr}% pour gérer les entêtes et bas de pages
%
%% pour les maths %%
\usepackage{amssymb} \usepackage{amsmath}%
\usepackage{stmaryrd} \usepackage{mathrsfs}%
\usepackage{nccmath} \usepackage{mathtools}%
\usepackage{amsthm}% pour théorèmes, preuves...
\usepackage{esint}% pour les intégrales
\usepackage{aligned-overset}% pour les alignements
%
%% pour améliorer les rapports
\usepackage{graphicx,pdfpages}% pour inclure des images ou des pdf
\usepackage{array,enumitem}% pour optimiser des modes
%
%
%
\begin{document}
  \begin{enumerate}
    \color{red}
    \item {\sl Calculons} \(\displaystyle\sum_{k=1}^{n-1}\binom{n}{k}(-1)^k\).
      \begin{align*}
        \sum_{k=1}^{n-1}\binom{n}{k}(-1)^k
        \underset{\phantom{\substack{\text{Binôme de} \\ \text{Newton}}}}&
          =\sum_{k=\boxed{0}}^{\boxed{n}}\binom{n}{k}(-1)^k - \binom{n}{0}(-1)^0 - \binom{n}{n}(-1)^n,\\
        \underset{\phantom{\substack{\text{Binôme de} \\ \text{Newton}}}}&=
          \sum_{k=0}^{n}\binom{n}{k}(-1)^k -1 - (-1)^n,\\
        \underset{\phantom{\substack{\text{Binôme de} \\ \text{Newton}}}}&=
          \sum_{k=0}^{n}\binom{n}{k}(-1)^k1^{n-k} -1 + (-1)^{n+1},\\
        \underset{\substack{\text{binôme de} \\ \text{Newton}}}&=
          (-1+1)^{n} - 1 + (-1)^{n+1},\\
        \underset{\phantom{\substack{\text{Binôme de} \\ \text{Newton}}}}&=
          \boxed{-1+(-1)^{n+1}}.
      \end{align*}
  \end{enumerate}
\end{document}

Which gives, enter image description here

I can't figure out how to make the text inside the boxes smaller, and also my way of aligning using phantom is very tedious and error prone...

2

I am like a snail but I add my idea anyway I have:

  1. deleted amsmath that is a subset of mathtools;

  2. deleted \usepackage{aligned-overset} using an array with the option rcll;

  3. used the font and mathfont of the 1st image \usepackage{newtxtext} \usepackage{mathptmx};

  4. increased the vertical spaces with [1.5em] and [2em];

  5. used a \mkern-5mu (for the first line) to have the perfect alignment and \displaystyle always because I had a \sum always inline mode;

  6. used \scriptstyle command to have a tiny 0 and n into the boxes (same size of the others limits of the sum);

  7. used \textsl{Calculons} instead of the old command \sl.

    \documentclass[11pt,a4paper]{article}%
    \usepackage[margin=3cm]{geometry}% pour gérer les dimensions
    \usepackage[french]{babel}% rajouter éventuellement english, greek, etc.
    \usepackage[T1]{fontenc}% gestion des accents (pour les pdf)
    \usepackage[utf8]{inputenc}% encodage du fichier source
    \usepackage{xcolor}% pour gérer les couleurs
    \usepackage{fancyhdr}% pour gérer les entêtes et bas de pages
    %
    %% pour les maths %%
    \usepackage{amssymb}%
    \usepackage{stmaryrd} \usepackage{mathrsfs}%
    \usepackage{nccmath} \usepackage{mathtools}%
    \usepackage{amsthm}% pour théorèmes, preuves...
    \usepackage{esint}% pour les intégrales
    \usepackage{newtxtext}
    \usepackage{mathptmx}
    
    %
    %% pour améliorer les rapports
    \usepackage{graphicx,pdfpages}% pour inclure des images ou des pdf
    \usepackage{array,enumitem}% pour optimiser des modes
    \begin{document}
      \begin{enumerate}
        \color{red}
        \item \textsl{Calculons} $\displaystyle\sum_{k=1}^{n-1}\binom{n}{k}(-1)^k$.
          \[\begin{array}{rcll}
            \displaystyle\sum_{k=1}^{n-1}\binom{n}{k}(-1)^k
            & = &\mkern-5mu\displaystyle \sum_{k=\boxed{\scriptstyle 0}}^{\boxed{\scriptstyle n}}\binom{n}{k}(-1)^k-\binom{n}{0}(-1)^0 - \binom{n}{n}(-1)^n,\\[1.5em]
            & = &\displaystyle\sum_{k=0}^{n}\binom{n}{k}(-1)^k-1-(-1)^n,\\[1.5em]
            & = &\displaystyle\sum_{k=0}^{n}\binom{n}{k}(-1)^k 1^{n-k} -1 + (-1)^{n+1},\\[1.5em]
            & \underset{\substack{\text{Binôme de} \\ \text{Newton}}}{=} &(-1+1)^{n} - 1 + (-1)^{n+1},\\[2em]
            & = &\boxed{-1+(-1)^{n+1}}.
          \end{array}
          \]
      \end{enumerate}
    \end{document}
    

enter image description here

4

Your usage of \underset is wrong: it should be \underset{...}{=} with the & preceding it.

I also provide a redefinition of \boxed which, in the original definition, always use \displaystyle.

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\renewcommand{\boxed}[1]{\mathpalette\boxed@{#1}}
\newcommand{\boxed@}[2]{%
  \fbox{$\m@th#1#2\mathstrut$}%
}
\makeatother

\begin{document}

\begin{align*}
  \sum_{k=1}^{n-1}\binom{n}{k}(-1)^k
  &\underset{\phantom{\substack{\text{binôme de} \\ \text{Newton}}}}{=}
   \sum_{k=\boxed{0}}^{\boxed{n}}\binom{n}{k}(-1)^k - \binom{n}{0}(-1)^0 - \binom{n}{n}(-1)^n,
\\
  &\underset{\phantom{\substack{\text{binôme de} \\ \text{Newton}}}}{=}
   \sum_{k=0}^{n}\binom{n}{k}(-1)^k -1 - (-1)^n,
\\
  &\underset{\phantom{\substack{\text{binôme de} \\ \text{Newton}}}}{=}
   \sum_{k=0}^{n}\binom{n}{k}(-1)^k1^{n-k} -1 + (-1)^{n+1},
\\
  &\underset{\substack{\text{binôme de} \\ \text{Newton}}}{=}
  (-1+1)^{n} - 1 + (-1)^{n+1},
\\
  &\underset{\phantom{\substack{\text{binôme de} \\ \text{Newton}}}}{=}
   \boxed{-1+(-1)^{n+1}}.
\end{align*}

\end{document}

enter image description here

I'd omit the punctuation at the end of lines, except the last. And I'd also avoid the spaced equals signs.

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand{\sboxed}[1]{{\mathpalette\sboxed@{#1}}}
\newcommand{\sboxed@}[2]{%
  \setlength{\fboxsep}{1pt}%
  \fbox{$\m@th#1#2\mathstrut$}%
}
\makeatother

\begin{document}

\begin{align*}
  \sum_{k=1}^{n-1}\binom{n}{k}(-1)^k
  &=\sum_{k=\sboxed{0}}^{\sboxed{n}}\binom{n}{k}(-1)^k - \binom{n}{0}(-1)^0 - \binom{n}{n}(-1)^n
\\
  &=\sum_{k=0}^{n}\binom{n}{k}(-1)^k -1 - (-1)^n
\\
  &=\sum_{k=0}^{n}\binom{n}{k}(-1)^k1^{n-k} -1 + (-1)^{n+1}
\\
  &=(-1+1)^{n} - 1 + (-1)^{n+1} \qquad\text{(binôme de Newton)}
\\
  &=\sboxed{-1+(-1)^{n+1}}\,.
\end{align*}

\end{document}

Here, rather than redefining \boxed, I used a different command, which maybe is better also for the preceding solution.

enter image description here

2

A solution witheqparbox and stackengine.

Some remarks: nowadays, you don't have to load inputenc with option [utf8] since it is what LaTeX expects by default. Also, needless to load amsmath if you load mathtools, which does it for you.

I took the liberty to replace the vivid red with another red.

\documentclass[11pt,a4paper]{article}%
\usepackage[margin=3cm]{geometry}% pour gérer les dimensions
\usepackage[french]{babel}% rajouter éventuellement english, greek, etc.
\usepackage[T1]{fontenc}% gestion des accents (pour les pdf)
\usepackage[svgnames]{xcolor}% pour gérer les couleurs
\usepackage{fancyhdr}% pour gérer les entêtes et bas de pages
%
%% pour les maths %%
\usepackage{amssymb} %
\usepackage{stmaryrd} \usepackage{mathrsfs}%
\usepackage{nccmath} \usepackage{mathtools}%
\usepackage{amsthm}% pour théorèmes, preuves...
\usepackage{esint}% pour les intégrales
\usepackage{aligned-overset}% pour les alignements
\usepackage[usestackEOL]{stackengine} %
%% pour améliorer les rapports
\usepackage{graphicx,pdfpages}% pour inclure des images ou des pdf
\usepackage{array,enumitem}% pour optimiser des modes
\usepackage{eqparbox}
\newcommand{\eqmathbox}[2][E]{\eqmakebox[#1]{$\displaystyle #2$}}

%
\begin{document}

  \begin{enumerate}
    \color{IndianRed}
    \item {\sl Calculons} \(\displaystyle\sum_{k=1}^{n-1}\binom{n}{k}(-1)^k\).
      \begin{align*}
        \sum_{k=1}^{n-1}\binom{n}{k}(-1)^k
        & \eqmathbox{=}\sum_{k=\boxed{\scriptstyle 0}}^{\boxed{\scriptstyle n}}\binom{n}{k}(-1)^k - \binom{n}{0}(-1)^0 - \binom{n}{n}(-1)^n,\\
        &\eqmathbox{=} \sum_{k=0}^{n}\binom{n}{k}(-1)^k -1 - (-1)^n,\\
        &\eqmathbox{=} \sum_{k=0}^{n}\binom{n}{k}(-1)^k1^{n-k} -1 + (-1)^{n+1},\\
         & \eqmathbox{\underset{\;\scriptsize\Centerstack{binôme de\\ Newton }\;}{=}} (-1+1)^{n} - 1 + (-1)^{n+1},\\
        &\eqmathbox{=} \boxed{-1+(-1)^{n+1}}.
      \end{align*}
  \end{enumerate}

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