How to do \widthof with a symbol

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.


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

Tags:

Width