0

I have equations in a flalign environment and comments that may need to be multi-liner. \parbox seems fine except I can't tell it to automatically stretch in order to fill the space from the right-end of the equation to the right margin of the page. How to solve?

I used \fbox just to put a frame around the box of the comment to see what's going on, but that is not necessary.

The parbox is too small and text goes beyond the margins of the page

\documentclass[11pt,a4paper]{book}
\usepackage[showframe]{geometry}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{dsfont}

\begin{document}

\begin{flalign*}
& a=a & \text{This is a comment} \\
& b=b & \text{T} \\
& \begin{aligned}
    \Aboxed{& (a,b,c\in\mathds{R}\wedge a+b=a+c)\Rightarrow{}} \\
    \Aboxed{& \qquad\Rightarrow(a+b,a+c\in\mathds{R}\wedge a+b=a+c)}
\end{aligned} & \fbox{\parbox{\fill}{Hello this is a comment}} \\
& (a,b,c\in\mathds{R}\wedge a+b=a+c)\Rightarrow(a+b,a+c\in\mathds{R}\wedge a+b=a+c) & \fbox{\parbox{\fill}{Another comment in a parbox}} \\
& (a,b,c\in\mathds{R}\wedge a+b=a+c)\Rightarrow(a+b,a+c\in\mathds{R}\wedge a+b=a+c) & \fbox{\parbox{2cm}{This new parbox has fixed length}}
\end{flalign*}

\end{document}
  • Please edit the MWE in the question so that compiles as is and produces the incorrect results that you have show. – Peter Grill Nov 9 '18 at 18:03
  • Do you require any form of alignment between the equations? Or are you mainly interested in posting equations and have some comment accompanying them? Also, what about alignment of the comments with respect to one another? – Werner Nov 9 '18 at 18:06
  • @peter Sorry I think I forgot to \usepackage{mathtools}, which provides \Aboxed, and \usepackage{dsfont}, which provides \mathds. I'll fix this as soon as I arrive at home. – the_eraser Nov 9 '18 at 18:22
  • @werner Yes I'd like to keep it as is, except some way to tell to \parbox (or other means) to automatically stretch from a minimum length to a max that goes from the right-end of the equation to the right margin of the page – the_eraser Nov 9 '18 at 18:27
1

A solution based on package linegoal, which measures the free space remaining from its insertion point to the right margin. For the framed boxed; I defined an eqcomment environment, based on tabularx and linegoal. Stangely, the log files warns about an overfull \box (318 pt!) at the end of the maths environment, but the pdf shows none.

\documentclass[11pt,a4paper]{book}
\usepackage[showframe]{geometry}
\usepackage{mathtools, nccmath, dsfont, tabularx, ragged2e}
\usepackage{linegoal}

\newenvironment{eqcomment}{\mbox{}\setlength{\tabcolsep}{3pt}\tabularx{\linegoal}{|>{\RaggedRight\arraybackslash}X|}\hline}%
{\\\hline\endtabularx}

\begin{document}

\begin{fleqn}
\setlength{\arraycolsep}{3pt}
\begin{alignat*}{2}
& a=a & & \text{This is a comment} \\
& b=b & & \text{T} \\
& \begin{aligned}
 \Aboxed{& (a,b,c\in\mathds{R}\wedge a+b=a+c)\Rightarrow{}} \\
 \Aboxed{& \quad\Rightarrow(a+b,a+c\in\mathds{R}\wedge a+b=a+c)}
\end{aligned} &&\mbox{}\parbox{\linegoal}{Hello this is a comment} \\
& (a,b,c\in\mathds{R}\wedge a+b=a+c)\Rightarrow(a+b,a+c\in\mathds{R}\wedge a+b=a+c) & \hspace{1.25em} & \begin{eqcomment} Another comment in a parbox\end{eqcomment} \\
& (a,b,c\in\mathds{R}\wedge a+b=a+c)\Rightarrow(a+b,a+c\in\mathds{R}\wedge a+b=a+c) & & \begin{eqcomment}This new parbox has variable length\end{eqcomment}
\end{alignat*}
\end{fleqn}

\end{document} 

enter image description here

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.