1

Problem:

Trying to align multiple rows and columns where the number of values differ for each row.

Minimal Working Example (MWE):

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{flalign*}
\text{err:} & \qquad\text{...}              && \text{\# Too far away}\\
            & \qquad\text{beq t0,  t1, err} && \text{\# Jump to err if t0 equal to t1}\\
\text{\# To manage a long jump...} && \\
\end{flalign*}

\end{document}

Desired outcome:

err:   ...                # Too far away
       beq t0,  t1, er    # Jump to err if t0 equal to t1
# To manage a long jump...
2
  • do you really need a math alignment here? It's all text so tabbing or tabular or simply verbatim might be more suitable? Oct 12, 2021 at 15:57
  • @DavidCarlisle Good point, I might consider other alternatives. However, if I choose to pursue the path of flalign*, how would a solution look like (for my own learning)?
    – kexxcream
    Oct 12, 2021 at 15:59

1 Answer 1

2

enter image description here

The AMS alignments are not helping at all here almost all the markup added is there to explicitly undo the amsmath setting. Alignments are math but you want text so \text, they alternate right and left aligned columns but you just want left so need && to skip every other column, the last line contains a long unaligned entry so I used \rlap to hide its width. However:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{alignat*}{3}
&\text{err:} && \qquad\text{...}              && \text{\# Too far away}\\
&            && \qquad\text{beq t0,  t1, err}\qquad && \text{\# Jump to err if t0 equal to t1}\\
&\rlap{\# To manage a long jump...}
\end{alignat*}

\end{document}

Or...

enter image description here

\documentclass{article}

\begin{document}

\begin{verbatim}
err:   ...                # Too far away
       beq t0,  t1, er    # Jump to err if t0 equal to t1
# To manage a long jump...
\end{verbatim}
\end{document}
6
  • How would a solution look to tab the content without alignat* or align*? I am also having trouble to compile the sign ^ with align*.
    – kexxcream
    Oct 16, 2021 at 12:42
  • @kexxcream ^ is math superscript, it isn't clear what you want, as a start I think I'd just use \begin{verbatim}...\end{verbatim} then you can use spaces at the start of lines and characters like ^ (and #) are taken as literal characters. I added an example Oct 16, 2021 at 12:48
  • I think I am only missing two things: 1) how can I include the sign ^ in verbatim and will there be a problem if I se \ttfamily? 2) is there a way in verbatim to adopt tab / align instead of spaces?
    – kexxcream
    Oct 16, 2021 at 13:34
  • @kexxcream you can use ^ in verbatim to get ^ using tabs is evil but some packages have extensions to allow that eg fancyvrb obeytabs option verbatim will use whatever font you have set \ttfamily to use. Oct 16, 2021 at 13:36
  • If using tabs is evil, what alternatives do you have to align content in verbatim?
    – kexxcream
    Oct 16, 2021 at 13:43

You must log in to answer this question.

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