TransWikia.com

align a set of mathematical expressions in a matrix form with arbitrary number of columns

TeX - LaTeX Asked on September 2, 2021

I have arranged a set of mathematical expressions using align environment. For example,

begin{flalign*}
u_{(1.1)0}^0 &= 0;          &u_{(2.1)0}^0 &=  - 2;          &u_{(2.2)0}^0 &= 2;      &u_{(3.1)0}^0 &=  - 1;         &u_{(3.2)0}^0 &=  - 1;      &u_{(4.1)0}^0 &= 0
u_{(1.1)xi }^0 &=  - 2;        &u_{(2.1)xi }^0 &= 2;      &u_{(2.2)xi }^0 &= 2;  &u_{(3.1)xi }^0 &= 3;      &u_{(3.2)xi }^0 &=  - 3;   &u_{(4.1)xi }^0 &= 4
end{flalign*}

For different page setups, sometimes these equations causes overflow from the print zone.

  • Is there a simple algorithm that can print these equations with arbitrary number of columns?

Edit-1
The example is changed slightly to make the problem elegant.

   begin{alignat*}{3}
      a&=fffffffffffffffffffffffff; &b&=gbbbbbbbbbbbbbbbbbbb; &c&=aaaaaaaaaaaaaaaaaaaaaa; 
      d&=ggggggggggggggggggggggggg; &f&=tttttttttttttttttttt; &t&=ssssssssssssssssssssss;
  end{alignat*}

The output generated with the above code (and also with align) is shown below.

enter image description here
Since the expressions outside the margins cannot be printed, it forces the user to realign the expressions with 2 columns (here 2 is chosen arbitrarily by user based on individual case).

So, given a set of expressions, is there an algorithm or some code that can print the expressions with alignment within the number of columns given by the user without any intervention.

Edit-2
With a slight search in web, using some of the comments, the problem is slightly solved.

newcounter{i}
setcounter{i}{-1}
newcountcol
col=3
foreach ele in {1,2,3,...,15}
 {
  ifnum thei <col
  {
   ele,
   addtocounter{i}{1}
  }
  else
 {
    setcounter{i}{0}
     ele,
 } fi
}

With the above code, the output is an matrix form as shown below.

enter image description here

Edit-3

While searching a topic, I found a few answers How to store a string. The idea is: define a command that takes a string. While running the loop, redefine the string command with the new string. Once the final string is obtained, use the string in the required environment and reset the string command to the first one.

I am not sure whether this is a proper way of doing and this works or not.


P.S.: There are many cases like this and very difficult to arrange these for each page setup!

2 Answers

Add my MWE using alignat enviroment of amsmath without a numbered equation.

documentclass[a4paper,12pt]{article}
usepackage{amsmath,amssymb}
begin{document}
begin{alignat*}{6}
    u_{(1.1)0}^0 &= 0;quad  &u_{(2.1)0}^0 &=  - 2;quad  &u_{(2.2)0}^0 &= 2;quad  &u_{(3.1)0}^0 &=  - 1;quad &u_{(3.2)0}^0 &=  - 1;quad  &u_{(4.1)0}^0 &= 0
     u_{(1.1)xi}^0 &= -2;quad  &u_{(2.1)xi}^0&= 
     2;quad  &u_{(2.2)xi }^0  &= 2;quad  &u_{(3.1)xi}^0&=  3;quad &u_{(3.2)xi}^0  &=  - 3;quad  &u_{(4.1)xi}^0 &= 4
end{alignat*}
end{document}

enter image description here

..and with geometry package, you have the correct numbered equations.

documentclass[a4paper,12pt]{article}
usepackage{amsmath,amssymb}
usepackage[margin=2cm]{geometry}
begin{document}
begin{alignat}{6}
    u_{(1.1)0}^0 &= 0;quad  &u_{(2.1)0}^0 &=  - 2;quad  &u_{(2.2)0}^0 &= 2;quad  &u_{(3.1)0}^0 &=  - 1;quad &u_{(3.2)0}^0 &=  - 1;quad  &u_{(4.1)0}^0 &= 0
     u_{(1.1)xi}^0 &= -2;quad  &u_{(2.1)xi}^0&= 
     2;quad  &u_{(2.2)xi }^0  &= 2;quad  &u_{(3.1)xi}^0&=  3;quad &u_{(3.2)xi}^0  &=  - 3;quad  &u_{(4.1)xi}^0 &= 4
end{alignat}
end{document}

enter image description here

Answered by Sebastiano on September 2, 2021

Accidentally while searching for something else I have come across two solutions which are much simpler than expected.

Solution:1 One can use multicol package. From the documentation of the package. The working model is

documentclass[a4paper,12pt]{article}
usepackage{multicol}
begin{document}
begin{multicols}{3}
noindent $u_{1.1 0}^0=-2;$
$u_{1.2 0}^0= 0;$
$u_{1.3 0}^0=2;$
columnbreak
$u_{2.1 0}^0= 0$
$u_{3.1 0}^0=3;$ 
$u_{3.2 0}^0=-1;$
$u_{3.3 0}^0=-1;$
$u_{3.4 0}^0=3$
$u_{4.1 0}^0=-1;$
$u_{4.2 0}^0=-1;$
end{multicols}
end{document}

The sample output is enter image description here columnbreak can be used to break the column at the desired location. It is observed that sometimes one has to experiment a little based on the behaviour.

Solution :2 In multicol the items are arrange vertically. If one wants to do horizontally, they use the package tasks. The details can be found in align horizontally

Answered by rajendra on September 2, 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