1

Please have a look at the following MWE:

\documentclass{scrartcl}
\usepackage{amsmath,amstext,amssymb}
\begin{document}

\begin{align}
\cdots\text{ABB}&\bigg|\text{BAABB}&\bigg|\text{AAABB}&\bigg|\text{BB}&\bigg|\text{BB}&\bigg|\text{ABABAABABB}&\bigg|\text{AA}\cdots \\
n_0 &  n_1 & n_2 & n_3 & n_4 & n_5
\end{align}
\end{document}

This produces the following output:

enter image description here

I want to align the vertical lines $\bigg|$ and the corresponding labels $n_i$ below each other. I do not want to have the additional white space after the $\bigg|$ in equation (1) either. How can I achieve that?

2
  • A simple solution is to insert a negative thin space: \bigg|\! Jun 23, 2016 at 19:51
  • @Marco Daniel Negative thin space only removes the white space after every second $\bigg|$ somehow ..
    – klopps
    Jun 23, 2016 at 20:10

2 Answers 2

3

Here is a solution, if I've well understood what you want. It's based on the code for the \vdotswithin command from mathtools. So I define a \vertwithin{label} command, which puts the \vert command centred in a box of width the labelwidth, and uses this box as alignment point.

B.t.w., for n alignment points, you need 2n-1 ampersands. Also, you don't have to load mathtext if you load amsmath (nor if you load mathtools, which loads amsmath)

I'm not sure whether you want white space at the end of text segments, so I provided both solutions:

\documentclass{scrartcl}
\usepackage{mathtools,amssymb}

\newcommand\vertwithin[1]{%
{\mathmakebox[\widthof{\ensuremath{{}#1{}}}][c]{{\biggm\vert}}}}%

\begin{document}

\begin{align}
 ⋯ \text{ABB} & \vertwithin{n₀} \text{BAABB} & & \vertwithin{n₁} \text{AAABB}& &\vertwithin{n₂} \text{BB} & & \vertwithin{n₃} \text{BB} & & \vertwithin{n₄} \text{ABABAABABB} & & \vertwithin{n₅} \text{AA} ⋯ \\
 & n₀ & & n₁ & & n₂ & & n₃ & & n₄ & & n₅
\end{align}

\begin{alignat}{6}
 ⋯ \text{ABB} & \vertwithin{n₀} \text{BAABB} & & \vertwithin{n₁} \text{AAABB}& & \vertwithin{n₂} \text{BB} & & \vertwithin{n₃} \text{BB} & & \vertwithin{n₄} \text{ABABAABABB} & & \vertwithin{n₅} \text{AA} ⋯ \\
 & n₀ & & n₁ & & n₂ & & n₃ & & n₄ & & n₅
\end{alignat}

\end{document} 

enter image description here

3

You can use alignat to remove the gaps between the alignment marks &:

enter image description here

\documentclass{article}

\usepackage{mathtools,eqparbox}

\begin{document}

% Original alignment
\begin{align}
  \cdots\text{ABB}&\bigg|\text{BAABB}&\bigg|\text{AAABB}&\bigg|\text{BB}&\bigg|\text{BB}&\bigg|\text{ABABAABABB}&\bigg|\text{AA}\cdots \\
  n_0 &  n_1 & n_2 & n_3 & n_4 & n_5
\end{align}

% Updated alignment
\newcommand{\setvert}{\eqmakebox[eqmb]{$\bigg|$}}
\newcommand{\setsub}[1]{\eqmakebox[eqmb]{$\mathclap{#1}$}}
\begin{alignat}{6}
  \cdots\text{ABB}
    &\setvert\text{BAABB}
    &&\setvert\text{AAABB}
    &&\setvert\text{BB}
    &&\setvert\text{BB}
    &&\setvert\text{ABABAABABB}
    &&\setvert\text{AA}
  \cdots \\
    &\setsub{n_0}
    &&\setsub{n_1}
    &&\setsub{n_2}
    &&\setsub{n_3}
    &&\setsub{n_4}
    &&\setsub{n_5}
\end{alignat}

\end{document}

eqparbox's \eqmakebox[<tag>]{<stuff>} figures out the width of <stuff> across all similar <tag>s (so needs at least two compilations on the first go). I placed the enumerations in the second equation inside a \mathclap to avoid it influencing the alignat alignment.

3
  • Initially I also had thought of a solution like this. Note it works only because all labels have more or less the same width
    – Bernard
    Jun 23, 2016 at 22:19
  • @Bernard: I've removed the width of the labels with \mathclap, using only the width of \bigg|.
    – Werner
    Jun 23, 2016 at 22:21
  • I hadn't noticed. That's a nice idea!
    – Bernard
    Jun 23, 2016 at 22:33

You must log in to answer this question.

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