# fixed columns in math mode

Michael Shell list1 at michaelshell.org
Sun Sep 12 08:21:30 CEST 2021

On Fri, 10 Sep 2021 14:22:14 +0200 (CEST)
karl at aspodata.se wrote:

> Is there any \makebox-like thing that works in math mode so I can set the
> contents width, or rather where the next thing will land?

Karl,

You are asking for a math mode equivalent of Scott Pakin's eqparbox package:

https://www.ctan.org/pkg/eqparbox

i.e., "inter-alignment alignments"

Using Pakin's approach with math mode (which I haven't actually tried
myself) you would have to put everything back into math mode within the
eqparbox's. The big benefit here is that eqparbox would autocalculate the
reserved width (the maximum width) you need for a given column. Be aware
that you will have to rerun LaTeX when changes are made to the columns
that increase the maximum width because eqparbox will only know the maximum
width value after it has finished processing the entire document - if the
maximum width has changed since the start of the run (starting with the
value imported from the previous run via the .aux file), a rerun will be
needed.

Whether or not you use simple manual or Pakin-type automatic setting of the
reserved widths, there is a way to coax IEEEeqnarray to do as you need. The
trick is to insert a phantom/strut row that reserves the needed width in
the given columns without otherwise altering the formatting (i.e., we must
remove any extra vertical spacing caused by this phantom row).

The code below shows an example of use. Do let us know if this does as
you need. In this example, I specified the reserved width as a percentage
of the column width rather than in points. This should help to make the
setting more likely to be acceptable for a variety of content (i.e., it
will work fine as long as the given IEEEeqnarray column(s) does not exceed
30% of the text width.)

Cheers,

Mike Shell

%%%%%
% Test document showing fixed length columns under IEEEeqnarray
% by Michael Shell 9/11/2021
\documentclass{article}

\usepackage{IEEEtrantools}

% length to hold interline spacing used by \IEEEeqnarray
% \MYstdeqnarrylinespacing = \baselineskip + \jot
\newlength{\MYstdeqnarrylinespacing}
\setlength{\MYstdeqnarrylinespacing}{\baselineskip}

% invisible phantom/strut row
% adjust width as needed, must be at least as large as the widest element
% whose width is to become irrelevant in the alignment instances.
% for diagnostic purposes, to make this strut visible, set the height of
% both rules to something nonzero such as 0.2pt
\newcommand{\MYeqnarrayphantomrow}{\hbox{\vrule height 0pt depth 0pt width 0.3\columnwidth}&&\hbox{\vrule height 0pt depth 0pt width 0.3\columnwidth}\\*[-\MYstdeqnarrylinespacing]}

\begin{document}

\title{A Test Example of Fixed Width IEEEeqnarray Columns}
\author{Michael Shell}
\date{\scriptsize (September 11, 2021)}
\maketitle

Test 1 (no phantom row):
\begin{IEEEeqnarray*}{RCL}
a & = & x
\end{IEEEeqnarray*}

Test 2 (with phantom row, the result is the same as above):
\begin{IEEEeqnarray*}{RCL}
\MYeqnarrayphantomrow
a & = & x
\end{IEEEeqnarray*}

Test 3 (wider LHS, with phantom row):
\begin{IEEEeqnarray*}{RCL}
\MYeqnarrayphantomrow
a+b+c & = & y
\end{IEEEeqnarray*}

Test 4 (like test 3, but without phantom row, note alignment failure):
\begin{IEEEeqnarray*}{RCL}
a+b+c & = & y
\end{IEEEeqnarray*}

Test 5 (much wider RHS, with a phantom as well as a second row):
\begin{IEEEeqnarray*}{RCL}
\MYeqnarrayphantomrow
a+b+c & = & y+z+\alpha+\beta+\delta+\gamma\\
b & = & g
\end{IEEEeqnarray*}

Tests 2, 3 and 5 will maintain their alignment of the = in the center
of the page column, as long as the content of the first and third columns
of the IEEEeqnarrays does not exceed the space reserved in \textbackslash
MYeqnarrayphantomrow, which in this test case is
0.3\textbackslash columnwidth.

As a diagnostic, to make the phantom rows visible, set the two rule
heights in the definition of \textbackslash MYeqnarrayphantomrow to
something nonzero, such as 0.2pt. Then you can easily see via
inspection if you have reserved enough space for the given content.

\end{document}
%%%%%