In an earlier question, align* in varwidth seems to ignore fleqn option, it appeared as if align* was not being properly handled by the varwidth environment. A "fix" was provided which results in the correct visual display. But, measuring the result still reports that the box is of \linewidth.

Note that the two varwidths report that same width of the box:

enter image description here


  • How do I measure the natural width of content that contains the use of align*?


Related Questions:



    Using align*:
        E &= mc^2
        F &= ma





Inside of \verb|\parbox{0.5\linewidth}|:

Inside \verb|varwidth| (without patch):

\medskip% Works visually, but still uses full width
%% https://tex.stackexchange.com/questions/394778/align-in-varwidth-seems-to-ignore-fleqn-option
Inside \verb|varwidth| (with patch):

\medskip%% This works fine.
Inside \verb|varwidth| with non-display content:
\ShowWidth{Some text}
  • Is the width you are interested in include the \intertext or just the math? Also, is supporting \intertext a required part of any solution? – Steven B. Segletes Oct 7 '17 at 1:27
  • @StevenB.Segletes: Yes, I need it to include the \intertext and do need \intertext support. – Peter Grill Oct 7 '17 at 1:39
  • 1
    it is reported as that width because it is that width, rows of an alignment are full width boxes to allow page breaking if nothing else. – David Carlisle Oct 7 '17 at 7:39
  • If the align has \intertext then it really is full width as that is a paragraph set with lines the current \hsize without that you could dump the column width data saved by the first \@measuringtrue pass of the alignment which will give you the max width of each column so you could in theory work something out, perhaps. – David Carlisle Oct 7 '17 at 7:42
  • @DavidCarlisle: Can't the text in\intertext be measured using \varwidth and then use the maximum of that and the displaymath to deternine the actual "natural" width? – Peter Grill Oct 7 '17 at 8:21

This answer is probably of no use to you, because you want it specifically for align*. However the tabstackengine package, which can build align-like entities in an hbox, keeps track of the individual cell contents, widths, heights and depths, which can be later recalled.

[Make sure you use it in conjunction with V1.5 of the listofitems package.]

The logical size of the align structure is
   \TABcells{} rows/\TABcells{1} columns.\\
The width of column 1 is \TABwd{1}\\
The width of column 2 is \TABwd{2}\\
The height of row 1 is \TABht{1}\\
The height of row 2 is \TABht{2}\\
with an \Sstackgap{} gap between rows.\\
The tokens of cell 1,2 are \getTABcelltoks[1,2]``%
The tokens of cell 2,2 are ``\detokenize\expandafter\expandafter\expandafter{\TABcellRaw[2,2]}''\\
That cell's contents (in the prevailing TAB mode/style)\\
\mbox{}~~~can be recovered as ``\TABcell{2}{2}''\\
That cell, accounting for its presented row height \&\\
\mbox{}~~column width, may be recovered as \fbox{\TABcellBox{2}{2}}\\
In the case of cell 2,1, that would be \fbox{\TABcellBox{2}{1}}

enter image description here

Thus, the natural width of the overall align structure can be obtained as

\dimexpr\TABwd{1} + \TABwd{2}\relax

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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