I want to encase a \begin{align}\end{align}
block in a \parbox
of exactly the width it takes up. If I try:
\settowidth{\alignwidth}{\vbox{\begin{align}
\vec a+\vec b&=(\vec a_x+\vec a_y)+(\vec b_x+\vec b_y) \\
&=(\vec a_x+\vec b_x)+(\vec a_y+\vec b_y) \\
\vec a+\vec b&=(\vec a+\vec b)_x+(\vec a+\vec b)_y
\end{align}}}
it just gives a value equal to the full \textwidth
. I've been able to measure all kinds of things, but align blocks have eluded me, short of measuring the longest line, which is a pain and not very generalisable.
The background is that on one line I want diagram 1, set of equations 1, diagram 2, set of equations 2 and I want it laid out to look the best. So far I'm putting them in four \parboxes
with total width \textwidth
.
I use this layout a lot and am trying to automate it as individual tweaking is a pain.
This is just the tip of the iceberg. I am writing a physics book and there are much more complicated figure layouts than this. I have read books where for example, to understand a particular problem, one has to keep in mind a diagram, a table of rules and a derivation which are in three different locations and it just ends up being a painful experience. Combining elements like these into a larger figure which can be read comfortably and presents well is not straightforward at all using standard routines and I have tried many existing packages over the last few years.
Anyway, I now have an answer to my question and have presented it below.
Addendum: Knowing the width of a column of equations is not necessarily an end in itself. Subtract this from \textwidth
and you have calculated the remaining space on the line, so even if the equations don't need to go in a box, something else that's being assembled on the fly can use that value to determine various element widths to end up with something that's either not too wide on the line or doesn't get pushed onto the next line. There are other scenarios, for example ending with a set of equations to the right of various elements, that needs either multiple equation numbers on various lines or an end of theorem bowtie at the end of the last line, that need to be at the right margin. The exact remaining space enables them to line up perfectly.
align
works.varwidth
might help. But it does not eliminate the white space on the left. What exactly are you using this for? There might be better ways.\settowidth{\alignwidth}{\parbox{20pt}{\begin{align}equations\end{align}}
you get the exact width. That is, try to force it into something too small and it fills the actual width. @daleif To measure I have equations set to fleqn with zero indent hence no need to worry about white space on the left.\settowidth
call and does not affect the typesetting end result. After this call, the align structure is put in a\parbox{\ alignwidth}{}
into which it fits exactly. I'm writing a physics book and this has to do with creating complicated figure layouts. What's wrong with wanting to know how to measure things on the page, even if it's just out of curiosity? I enjoy playing around with Latex. One has to be careful with counters that might be set during the\settowidth
call.