1

Initially, I had the code

\begin{align*}
|a_d|_p & = 1 \\
|a_i|_p & \leq 1
\end{align*}

which produced the result below:

first image

This is undesirable because the vertical bars | on the left don't line up. Then I discovered the alignat environment, and tried the code

\begin{alignat}{3}
| & a_d & |_p & & & = 1 \\
| & a_i & |_p & & & \leq 1
\end{alignat}

which produced the result below:

second image

This is better, but it's still not great because now the a_d and a_i don't line up. Ideally, I'd want just the column with the a_d and a_i to be centered. Then, I looked at the answer to this question, and tried the code

\begin{alignat*}{3}
| & \omit\hfill $a_d$ \hfill & |_p & & & = 1 \\
| & \omit\hfill $a_i$ \hfill & |_p & & & \leq 1
\end{alignat*}

which produced the result below:

third image

This is better in some respects because each of the vertical bars line up, as do the a_d and a_i, but now the right-hand vertical bars |_p are spaced too far to the right. Any suggestions?


UPDATE: After reading the code in Bernard's suggestions, along with some information about \makemathbox (from mathtools), \newlength, and \settowidth, I came up with the following code, which seems to do what I want. However, am I doing anything that is deprecated?

\newlength{\myl}
\settowidth{\myl}{$a_d$}

\begin{align*}
|a_d|_p & = 1 \\
| \mathmakebox[\myl]{a_i} |_p & \leq 1
\end{align*}
1
  • 2
    an experienced math copyeditor wouldn't find the original presentation inappropriate. i think this is a case of "trying too hard". Jul 2, 2015 at 18:09

1 Answer 1

2

Here are two solutions, using mathtools, and makebox for one of them. For the second one , with eqparbox , more automated. I define a \varpabs command which uses a tag: all \varpabs which share the same tag will have the same width – that of the widest argument:

\documentclass{article}

\usepackage{mathtools}
\usepackage{etoolbox}
\usepackage{makebox, eqparbox}
\DeclarePairedDelimiterXPP{\pabs}[1]{}\lvert \rvert{_p}{\ifblank{#1}{\:\cdot\:}{#1}}
\DeclarePairedDelimiterXPP{\varpabs}[2]{}\lvert\rvert{_p}{\eqmakebox[#1]{$\displaystyle#2$}}

\begin{document}

\begin{align*}
  \pabs{a_d} & = 1 \\
  \pabs{\makebox*{$ a_d $}{$ a_i $}} & \leq 1
\end{align*}

\begin{align*}
  \varpabs{A}{a_d + c} & = 1 \\
  \varpabs*{A}{ \frac{a_i }{b_i}} & \leq 1
\end{align*}

\end{document} 

enter image description here

3
  • Also, how does the code I just added to the bottom of my question look?
    – justin
    Jul 3, 2015 at 3:08
  • @justin You should read barbara's comment on your question: she knows whereof she speaks. (At least, if anybody here knows, she does. Conversely, if she doesn't know, we're all whistling in the dark.)
    – cfr
    Jul 3, 2015 at 3:16
  • @cfr I appreciate it... I saw her comment, and while it's reassuring to know I could have left everything as is, I'm also curious about how I can manipulate LaTeX spacing in general, so that's why I'm spending energy on this. Working on this particular task is kind of an instructive example for me.
    – justin
    Jul 3, 2015 at 3:24

You must log in to answer this question.

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