TransWikia.com

Change the centering in align environment

TeX - LaTeX Asked on August 3, 2021

I recently was trying to figure out a way to get better spacing in an align environment.

Say for example i was trying to type

documentclass[11pt,a4paper]{article}
usepackage[top=3cm,bottom=3cm,left=3cm,right=3cm]{geometry} %pour les dimensions
usepackage{amssymb,stmaryrd,amsmath,mathrsfs,nccmath,mathtools,amsthm,esint,aligned-overset}
%usepackage{calc,xargs,ifthen} %pour les opérations
usepackage{graphicx,pdfpages} %pour inclure des images ou des pdf
usepackage[french]{babel}  %rajouter éventuellemmeent english, greek, etc.
usepackage[T1]{fontenc}    %gestion des accents (pour les pdf)
usepackage[utf8]{inputenc} %encodage du fichier source
usepackage{fancyhdr} %Used for headers and footers
usepackage{xcolor} %pour gérer les couleurs
defnorme#1{leftlVert,#1,rightrVert}
defscal#1#2{leftlangle#1,,,#2rightrangle}

begin{document}
begin{align*}
            norme{x+y}^2 = norme{x}^2 + norme{y}^2 &iff scal{x+y}{x+y} = norme{x}^2+norme{y}^2 
            &iff scal{x}{x} + 2scal{x}{y} + scal{y}{y} = scal{x}{x} + scal{y}{y} 
            &iff2scal{x}{y} = 0 
            &iffscal{x}{y} = 0 
            &iff xtext{ et }ytext{ orthogonaux}
end{align*}
end{document}

The code works, and the display is okay, but the problem is that it looks like this:

Display from the code

Technically, the equation is centered well, but i was wondering if i could change it so that the iff symbols are in the center of the page, instead of slighty to the left as shown in the picture, and so the result would be

Correct display

One Answer

You can't really, because the r.h.s. of the second row is too long. However, you can have an approximation with eqparbox:

documentclass[11pt,a4paper]{article}
usepackage[top=3cm,bottom=3cm,left=3cm,right=3cm, showframe]{geometry} %pour les dimensions
usepackage{amssymb, stmaryrd, mathrsfs, nccmath, mathtools, amsthm, esint, aligned-overset}
usepackage{graphicx,pdfpages} %pour inclure des images ou des pdf
usepackage[french]{babel} %rajouter éventuellemmeent english, greek, etc.
usepackage[T1]{fontenc} %gestion des accents (pour les pdf)
usepackage{fancyhdr} %Used for headers and footers
usepackage{xcolor} %pour gérer les couleurs
usepackage{eqparbox}
newcommand{eqmathbox}[2][M]{eqmakebox[#1][r]{$displaystyle#2$}}
DeclarePairedDelimiter{norme}lVertrVert
defscal#1#2{leftlangle#1,,,#2rightrangle}

begin{document}

begin{align*}
            eqmathbox{norme{x+y}^2 = norme{x}^2 + norme{y}^2} &iff eqmathbox{scal{x+y}{x+y} = norme{x}^2+norme{y}^2hskip 3em} 
            &iff scal{x}{x} + 2scal{x}{y} + scal{y}{y} = scal{x}{x} + scal{y}{y} 
            &iff 2scal{x}{y} = 0 
            &iff scal{x}{y} = 0 
            &iff xtext{ et }ytext{ orthogonaux}
end{align*}

end{document} 

enter image description here

Correct answer by Bernard on August 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP