Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have the following MWE:

\documentclass{report}
\usepackage{amsmath}
\begin{document}
\begin{align}
    L_W&=\frac{L}{W}    & \text{words per line}&=\frac{\text{bytes per line}}{\text{bytes per word}} \\
    s&=\frac{l}{s}      & \text{number of sets}&=\frac{\text{number of lines}}{\text{associativity}} \\
    a_{off}&=ld_2(w)    & \text{address offset bits}&=ld_2(\text{words per line}) \\
    a_{s}&=ld_2(s)      & \text{address set bits}&=ld_2(\text{number of sets}) \\
    t&=a_b-a_s-a_{off}  & \text{address tag bit}&=\begin{aligned}
     &\text{address bits} \\
        -&\text{address set bits}\\
        -&\text{address offset bits}
    \end{aligned}
\end{align}
\end{document}

The output, with what I would like to change highlighted is this:

mwe plus highlight

  1. I would like to move the RHS of the second equation in row (5), so that address bits aligns with = and the equation number. http://tex.stackexchange.com/a/44451/19326 comes close but the equation number is centered. (http://tex.stackexchange.com/a/105639/19326 comes close as well but here I can't see how to handle the equation number and alignment of the formulas in the first column). Note that I want to align by the variable name and not by the sign. especially note the gap left between the equals sign and the first variable, so that the signs of the rows below wont vertically overlap with the equals sign)
  2. I would like to add equal spacing, I tried: http://tex.stackexchange.com/a/9151/19326 (by adding \savebox\strutbox{$\vphantom{\frac{\text{bytes per line}}{\text{bytes per wordi}}\frac{L}{W}}$}) but this still seams to give different spacing. (see between 3/4 with the addition) (currently not included since I am afraid that this will extend the entire enviornment downwards.
share|improve this question
    
Why not use alignat and specify all the alignment points? For (2), add [.xcm] to the end of (3). Play around with x until you are satisfied. –  dustin Aug 3 '13 at 19:35
add comment

1 Answer

up vote 6 down vote accepted

The spacing between rows can be adjusted with \vphantom; the aligned can be treated with [t] so the first line is level with =. However, centering the equation number is not something I would even try.

\documentclass{report}
\usepackage{amsmath}
\newcommand{\vphtextfr}{\vphantom{\frac{\text{by}}{\text{ty}}}}
\begin{document}
\begin{align}
L_W&=\frac{L}{W} & 
  \text{words per line}&=\frac{\text{bytes per line}}{\text{bytes per word}} \\
s&=\frac{l}{s} &
  \text{number of sets}&=\frac{\text{number of lines}}{\text{associativity}} \\
a_\textup{off}&=\mathit{ld}_2(w) &
  \text{address offset bits}&=\mathit{ld}_2(\text{words per line})\vphtextfr \\
a_{s}&=\mathit{ld}_2(s) &
  \text{address set bits}&=\mathit{ld}_2(\text{number of sets})\vphtextfr \\
t&=a_b-a_s-a_\textup{off} &
  \text{address tag bit}\vphtextfr&=
    \begin{aligned}[t]
     &\text{address bits} \\
    -&\text{address set bits}\\
    -&\text{address offset bits}
    \end{aligned}
\end{align}
\end{document}

Note the usage of \textup{off}: it's not the product of three quantities, but a word. Also use \mathit{ld} for a multiletter identifier.

enter image description here

share|improve this answer
    
In your example adding vphantom works nicely, however I was amazed by the simplicity of setting up a savebox strutbox. The biggest issue with it was that It did not work correctly when I tried. Do you have any idea why? (I have more equations and would love the automation achieved by the linked awnser) –  ted Aug 3 '13 at 19:53
1  
@ted You should have used \dfrac, not \frac. –  egreg Aug 3 '13 at 19:55
    
Also where do you get textup from (I cant find it in the amsmath doc, find returns no results), and what is the difference to text. For those who do not know about displaystyle: tex.stackexchange.com/a/71033/19326. It basically fixes the fact that in inline math mode the fraction is set in a smaller size than in the align enviornment. Therefore it suffices to use \dfrac in the \savebox\strutbox –  ted Aug 3 '13 at 20:06
    
One last thing, i think it should be \operatorname for ld_2 since ld_2 refers to ld to logaritmus dualis (log to base 2) after researching typesetting math a bit more. While you as a prof will now somebody else like me might come across this. –  ted Aug 3 '13 at 20:13
1  
@ted If it's an operator like \log, then it should be upright and \operatorname{ld} is good. You can also do \DeclareMathOperator{\ld}{ld} in the preamble and use \ld_2 in the document. –  egreg Aug 3 '13 at 21:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.