2

I have a very long set of equations that I put in an array. They must be aligned as

\begin{array}{lclc}
 A     & Long expression              &  \text{\hspace{.5cm}}   & Long expression \\
.
.
.
Z  & Long expression              &  \text{\hspace{.5cm}}   & Long expression \\
\end{array}

This is for give you an idea of how long the expression can be. Moreover the second and fourth component must be centered. I would like to use align because it allows for page breaks of the equations in case they are too long, but if I use them, then the second and fourth components of the align are not centered anymore. How can I have a structure as follows:

\begin{align}
 A     & Long centered expression              &  \text{\hspace{.5cm}}   & Long centered expression \\
.
.
.
Z  & Long centered expression              &  \text{\hspace{.5cm}}   & Long centered expression \\
\end{align}

I need the equations to be numbered, centered and with the possibility of breaking in multiple pages if they are too long.

EDIT

I add an example:

\[
\begin{array}{lclc}
 A     & This is a very long expression              &  \text{\hspace{.5cm}}   & Also this is a long expression \\
 B     & Normal             &  \text{\hspace{.5cm}}   & Something \\
Z  & Short              &  \text{\hspace{.5cm}}   & This is even longer expression of before \\
\end{array}
\]

If you try it on a TeX file the second and the fourth columns are centered with respect to their content. If I have a very long expression, then if I use array, it is possible that the equations do not fit well in the page because it cannot be broken in multiple pages. So I was thinking of using align with \allowpagebreaks[1]. But if I use

\[
\begin{align}
 A     & This is a very long expression              &  \text{\hspace{.5cm}}   & Also this is a long expression \\
 B     & Normal             &  \text{\hspace{.5cm}}   & Something \\
Z  & Short              &  \text{\hspace{.5cm}}   & This is even longer expression of before \\
\end{align}
\]

You see that the alignments of the second and fourth columns are with respect to the & symbol, and not centered with respect to their content.

I hope that the example clarifies my question

  • it will be much easier for people to understand the issue and test answers if you supplied a small but complete test document. alignments are right and left aligned to the alignment point so a&=b so effectively they are centred if you can structure it that way – David Carlisle Oct 04 '21 at 09:10
  • I added something one can copy and past in a TeX document and see what I mean. – Alessandro Mininno Oct 04 '21 at 09:31
  • well a complete document would be easier especially if it had more representative example, also align should not be in \[ if I cut and paste your fragment into a document I get ! Package amsmath Error: Erroneous nesting of equation structures; – David Carlisle Oct 04 '21 at 09:57
  • I found this answer https://tex.stackexchange.com/a/102845/167169 that actually does what I'm asking with alignat. It's lenghty because I need to put the command at each line, but this is exactly what I was looking for. – Alessandro Mininno Oct 05 '21 at 08:37
  • glad you found something that does what you need. I marked the question as duplicate – David Carlisle Oct 05 '21 at 10:45

2 Answers2

1

Note that you can not have align inside \[ The simplest and most common way is to add alignment points within the expression so they alig towards the alignment point rather tahn appear to be flush left or right. I added | here to make the alignment visible in teh output but that is not needed. Note that the example text is already too wide to fit in a standard text block even if I remove the .5cm spacing (there is no need for \hspace to be inside \text) If you have a much wider text block or your real expressions are smaller you could of course re-add spacing, although align already adds space between each expression (that is between each pair of columns)

enter image description here

\documentclass[a4paper]{article}

\usepackage{amsmath}

\begin{document}

\begin{align} A && This isa very&|long expression & Also this &|is a long expression \ B && Normal&| & Some&|thing \ Z && Short&| & This is even &|longer expression of before \end{align}

\end{document}

David Carlisle
  • 757,742
1

You can do it with alignat and eqparbox. The label for the boxes is automatically generated for each align-lcc display.

Dont' add a trailing \\, as is mandatory for align and friends.

\documentclass{article}
\usepackage{amsmath,eqparbox}

\ExplSyntaxOn

\NewDocumentEnvironment{align-lcc}{b} { \mininno_align_lcc:n { #1 } } {}

\seq_new:N \l__mininno_align_body_seq \seq_new:N \l__mininno_align_row_seq \tl_new:N \l__mininno_align_body_tl \int_new:N \g__mininno_align_rows_int

\cs_new_protected:Nn \mininno_align_lcc:n { \int_gincr:N \g__mininno_align_rows_int \tl_clear:N \l__mininno_align_body_tl \seq_set_split:Nnn \l__mininno_align_body_seq { \ } { #1 } \seq_map_indexed_function:NN \l__mininno_align_body_seq __mininno_align_row:nn \begin{alignat}{3} \tl_use:N \l__mininno_align_body_tl \end{alignat} }

\cs_new_protected:Nn __mininno_align_row:nn { \seq_set_split:Nnn \l__mininno_align_row_seq { & } { #2 } \tl_put_right:Nx \l__mininno_align_body_tl { \seq_item:Nn \l__mininno_align_row_seq { 1 } } \tl_put_right:Nx \l__mininno_align_body_tl { __mininno_align_cell:nn {A}{\seq_item:Nn \l__mininno_align_row_seq { 2 }} } \tl_put_right:Nx \l__mininno_align_body_tl { __mininno_align_cell:nn {B}{\seq_item:Nn \l__mininno_align_row_seq { 3 }} } \int_compare:nF { #1 == \seq_count:N \l__mininno_align_body_seq } { \tl_put_right:Nn \l__mininno_align_body_tl { \ } } }

\cs_new_protected:Nn __mininno_align_cell:nn { &\quad& \eqmakebox[#1-\int_to_arabic:n {\g__mininno_align_rows_int}][c]{$\displaystyle#2$} }

\ExplSyntaxOff

\begin{document}

\begin{align-lcc} A & This is a very long expression & Also this is a long expression \ B & Normal & Something \ Z & Short & This is even longer expression of before \end{align-lcc}

\end{document}

The idea is to split the input at \\, then each row at & and fill in using \eqmakebox.

enter image description here

egreg
  • 1,121,712
  • Thanks, but I copied your tex but it does not work. Something that I'm missing? – Alessandro Mininno Oct 05 '21 at 08:20
  • @AlessandroMininno Try adding \usepackage{xparse} (but you should also update your TeX system). – egreg Oct 05 '21 at 08:20
  • I was using Overleaf, so it should be update. In any case, I found this answer https://tex.stackexchange.com/a/102845/167169 that does what I'm asking but on every line I need to add the command. Is there a way to make it automatic? – Alessandro Mininno Oct 05 '21 at 09:23