4

I would like to use characters as variable names and adjust their width to all be the maximum width of a character. This way, brackets around them would align nicely as shown in the example below. Instead of stretching the characters, I would like them to match width by adding whitespace to the left and right of the character. I'm aware of \hphantom{} but what I need here is to "fill up" the width of one character to that of another.

Example:

\begin{aligned}
&\operatorname{I}[a; c] \\
&\operatorname{I}[w; a] \\
&\operatorname{I}[c; w]
\end{aligned}

Output:

unaligned variable names

1
  • For such an approach, one needs to know the width to set things to. Here, that would be w, which does not show up in the first line. Do you propose the user provide the letter (w) for which all widths will be matched, or should the user just always take it to be a w, since that is the widest lowercase letter? May 12, 2020 at 16:27

3 Answers 3

4

You could use eqparbox. In the first example, the objects are centered in the allotted space, in the second one the alignment is right and left.

The tags are arbitrary, you need to use different ones for each application.

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

\newcommand{\q}[3][c]{%
  % #1 (optional) = alignment, default c
  % #2 = tag
  % #3 = object
  \eqmakebox[#2][#1]{$#3$}%
}

\begin{document}

\[
\begin{aligned}
&\operatorname{I}[\q{1}{a}; \q{2}{c}] \\
&\operatorname{I}[\q{1}{w}; \q{2}{a}] \\
&\operatorname{I}[\q{1}{c}; \q{2}{w}]
\end{aligned}
\]

\[
\begin{aligned}
&\operatorname{I}[\q[r]{1}{a}; \q[l]{2}{c}] \\
&\operatorname{I}[\q[r]{1}{w}; \q[l]{2}{a}] \\
&\operatorname{I}[\q[r]{1}{c}; \q[l]{2}{w}]
\end{aligned}
\]

\end{document}

enter image description here

2

As long as you don't need separate equation numbers on various lines, you could use TABstack alignment

\documentclass{article}
\usepackage{amsmath,tabstackengine}
\TABstackMath
\setstacktabulargap{0pt}
\setstackgap{L}{1.2\baselineskip}
\begin{document}
\[
\tabularCenterstack{rcccl}{
\operatorname{I}[&a&;& c&] \\
\operatorname{I}[&w&;& a&] \\
\operatorname{I}[&c&;& w&]
}
\]
\end{document}

enter image description here

1

This soulution is based on \hbox to and on the guess of "a good constant" for this application of type "Op[a;b]"

\def\operatorname#1[#2;#3]{#1\hbox to2.5em{$[\hss#2;\hss#3\hss]$}}

Test: $\operatorname{I}[a; c]$\par
Test: $\operatorname{I}[w; a]$\par
Test: $\operatorname{I}[i; j]$\par
Test: $\operatorname{I}[m; w]$\par

\bye

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .