9

I have the following code:

\begin{align*}
c_s &\equiv b_s^2\\
&\equiv (c_{s-1}^{(2^{k_{s-1}-k_s-1})})^2 \\
&\equiv c_{s-1}^{(2^{k_{s-1}-k_s})} \\
&\equiv c_{s-2}^{(2^{k_{s-2}-k_{s-1}} \cdot 2^{k_{s-1}-k_s})}\\
&\mathrel{\makebox[\widthof{=}]{\vdots}}\\
&\equiv c_0^{(2^{k_{0}-k_{1}} \cdot \cdots \cdot 2^{k_{s-1}-k_s})} \pmod p
\end{align*}

On the third last line, I want to change the argument to \widthof to be \equiv, but doing this gives me compile error. What do I need to do to achieve the desired result?

b_pcakes
  • 237
  • 1
    as it happens, the width of equiv is exactly the same as that of =. (this should be true in all fonts designed for use with math.) however, the general question is a reasonable one, and the mathtools answer is a good one. – barbara beeton Oct 24 '16 at 00:15

2 Answers2

9

You could use

\widthof{$\equiv$}

but there's a slicker way with mathtools:

\documentclass{article}
\usepackage{amsmath,mathtools}

\begin{document}

\begin{align*}
c_s &\equiv b_s^2\\
&\equiv (c_{s-1}^{(2^{k_{s-1}-k_s-1})})^2 \\
&\equiv c_{s-1}^{(2^{k_{s-1}-k_s})} \\
&\equiv c_{s-2}^{(2^{k_{s-2}-k_{s-1}} \cdot 2^{k_{s-1}-k_s})}\\
&\vdotswithin{\equiv}\\
&\equiv c_0^{(2^{k_{0}-k_{1}} \cdot \cdots \cdot 2^{k_{s-1}-k_s})} \pmod{p}  
\end{align*}

\end{document}

enter image description here

The space might seem too big, so \mathtools also provides \shortvdotswithin:

\documentclass{article}
\usepackage{amsmath,mathtools}
\mathtoolsset{shortvdotsadjustabove=3pt} % I don't like the default

\begin{document}

\begin{align*}
c_s &\equiv b_s^2\\
&\equiv (c_{s-1}^{(2^{k_{s-1}-k_s-1})})^2 \\
&\equiv c_{s-1}^{(2^{k_{s-1}-k_s})} \\
&\equiv c_{s-2}^{(2^{k_{s-2}-k_{s-1}} \cdot 2^{k_{s-1}-k_s})}\\
&\shortvdotswithin{\equiv}
&\equiv c_0^{(2^{k_{0}-k_{1}} \cdot \cdots \cdot 2^{k_{s-1}-k_s})} \pmod{p}
\end{align*}

\end{document}

enter image description here

Note that there is no \\ after \shortvdotswithin{\equiv}.

Be careful that it's \pmod{p} and not \pmod p. The latter seems to work, but try \pmod 11 and you'll see.

egreg
  • 1,121,712
7

The argument of \widthof (package calc) is set in text mode. Mathematical symbols need math mode:

\widthof{$\equiv$}

Full example:

\documentclass{article}
\usepackage{calc}
\usepackage{amsmath}
\begin{document}
\begin{align*}
c_s &\equiv b_s^2\\
&\equiv (c_{s-1}^{(2^{k_{s-1}-k_s-1})})^2 \\
&\equiv c_{s-1}^{(2^{k_{s-1}-k_s})} \\
&\equiv c_{s-2}^{(2^{k_{s-2}-k_{s-1}} \cdot 2^{k_{s-1}-k_s})}\\
&\mathrel{\makebox[\widthof{$\equiv$}]{\vdots}}\\
&\equiv c_0^{(2^{k_{0}-k_{1}} \cdot \cdots \cdot 2^{k_{s-1}-k_s})} \pmod p
\end{align*}
\end{document}

Result

Heiko Oberdiek
  • 271,626
  • shouldn't it be with \m@th ? –  Oct 24 '16 at 06:09
  • hmm no, examining \mathsurround I see that align sets \mathsurround to 0pt immediately after &. Still it is strange, try \mathssurround200pt \begin{align}\the\mathssurround&\the\mathsurround,\the\mathsurround\end{align}. The last one prints 0pt! And if I put a \relax after &, then we get 0pt, 0pt after it. –  Oct 24 '16 at 06:23
  • ah, I see that it is a feature of amsmath that \m@th is issued for each cell. Coming from an \halign template the \m@th at each cell becomes effective only after TeX's usual scan at start of cell has been stopped by some non-expandable token. So \relax\the\mathssurround is needed to reveal the setting. For all purposes \mathsurround is 0pt inside (each cell of an) align. I was not aware of that. –  Oct 24 '16 at 07:23
  • @jfbu A generic macro would have to consider \m@th/\mathsurround and the math style (\mathpalette/\mathchoice). But I do not think, that it is necessary in ad hoc code to take precautions for all the quite unlikely cases. – Heiko Oberdiek Oct 24 '16 at 17:14