1

How can you extend arrow to match the width of text in the above line?

I want to get a result like this.

X -> Y -> Z
 ------->

And the best way I could think of was:

X
\begin{array}{c}
    \stackrel{f}{\longrightarrow} Y \stackrel{g}{\longrightarrow} \\
    \xrightarrow{\hfill h \hfill}
\end{array}
Z

But the arrow is short. I want to extend the width of the

\xrightarrow{\hfill h \hfill}

to match the width of

\stackrel{f}{\longrightarrow} Y \stackrel{g}{\longrightarrow}

Please give me some advice.

1
  • 1
    Welcome to TeX.SX! Please post a small complete document that shows your setting and what you already have.
    – gernot
    Commented Jan 27, 2021 at 10:29

1 Answer 1

1

Like this?

\documentclass{article}

\usepackage{mathtools, amssymb}
\usepackage{eqparbox} 
\newcommand{\eqmathbox}[2][M]{\eqmakebox[#1]{$#2$}}

\begin{document}

\begin{align*}
  X
\begin{array}{c}
    \eqmathbox{\stackrel{f}{\longrightarrow} Y \stackrel{g}{\longrightarrow}} \\[-1ex]
    \xrightarrow[\hskip-0.7ex\eqmathbox{\scriptstyle h}\hskip-0.8ex]{}
\end{array}
Z
\end{align*}

\end{document} 

enter image description here

5
  • Thank you! The result is exactly what I wanted. Box and glue are things I haven't yet understood. Trying to figure out how your document is working.
    – Saigo Ueno
    Commented Jan 27, 2021 at 17:37
  • Actually, it was fothund by trial and error: \xrightarrow measures what is above or below it, and adds small lengths on both sides. I don't know how these lengths are chosen, but I removed small lengths at both ends of the \eqmathbox with \hskip -… until it seemed correct. I measured these lengths in ex units, so that if you use another font size, it should (hopefully) still work
    – Bernard
    Commented Jan 27, 2021 at 17:46
  • Is \hskip needed? I was testing the script to understand the behavior and it seems to me that I am getting the same result by changing \xrightarrow[\hskip-0.7ex\eqmathbox{\scriptstyle h}\hskip-0.8ex]{} to \xrightarrow[\eqmathbox{\scriptstyle h}]{} Is there some reason to add /hskip?
    – Saigo Ueno
    Commented Feb 1, 2021 at 16:26
  • I added it because the arrow ends were not exactly aligned with the other arrows above – the \xrightarrow itself is lightly larger than what's above or below it, and I don't know exactly by how much.
    – Bernard
    Commented Feb 1, 2021 at 16:35
  • I see. Thank you.
    – Saigo Ueno
    Commented Feb 2, 2021 at 2:12

You must log in to answer this question.

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