我在环境中有方程式flalign
和可能需要多行注释。\parbox
似乎很好,只是我不能告诉它自动地拉伸以填充从等式右端到页面右边缘的空间。如何解决?
我以前\fbox
只是在评论框周围放一个框架来查看发生了什么,但这不是必需的。
\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}
答案1
基于包 的解决方案linegoal
,用于测量从其插入点到右边距的剩余可用空间。对于带框的盒子;我定义了一个eqcomment
基于tabularx
和 的环境linegoal
。奇怪的是,日志文件警告数学环境末尾的溢出\box
(318 pt!),但 pdf 没有显示任何内容。
\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}