parbox自动宽度计算

parbox自动宽度计算

考虑以下 MWE:

\documentclass[letterpaper]{article}
\usepackage{amsmath}
\begin{document}
\noindent
$\begin{aligned}[t]
  \left( \frac{1}{2}-\frac{1}{4} \right) \left( \frac{1}{2}-\frac{3}{4} \right) 
  &= \left( \frac{4-2}{8} \right) \left( \frac{4-6}{8} \right) 
  & & \parbox[t]{0.5\textwidth}{Simplify within parenthesis. 
          Simplify within parenthesis. Simplify within parenthesis. 
          Simplify within parenthesis.} \\
  &= \left( \frac{2}{8} \right) \left( \frac{-2}{8} \right) 
  & &\parbox[t]{0.5\textwidth}{Add within grouping symbols.} \\
  &= \left( \frac{1}{4} \right) \left(-\frac{1}{4} \right) 
  & & \parbox[t]{0.5\textwidth}{Multiply.}\\
  &=  -\frac{1}{16}
\end{aligned}$
\end{document}

发出错误

在此处输入图片描述

这主要是由于\parbox[t]{0.5\textwidth}{<content>}.

是否可以创建一个环境,linewidth独立计算每行剩余量以供\parbox使用?

在此处输入图片描述


linegoal考虑使用@zarko 建议的包的MWE :

\documentclass[letterpaper]{article}
\usepackage{geometry}
\usepackage{mathtools}
\usepackage{linegoal}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}

    \begin{alignat*}{2}    
\left( \frac{1}{2} - \frac{1}{4} \right) \left( \frac{1}{2} - \frac{3}{4} \right)
    & = \left( \frac{4 - 2}{8} \right) \left( \frac{4 - 6}{8} \right) 
        &\qquad     
            &   \rlap{\parbox{\linegoal}{\raggedright
                Simplify within parenthesis. Simplify within parenthesis.}}
                                                                    \\[1ex]
    & = \left( \frac{2}{8} \right) \left( \frac{-2}{8} \right)        
        &   &  \rlap{\parbox{\linegoal}{\raggedright
                Add within grouping symbols}}                       \\
    & = \left( \frac{1}{4} \right) \left(-\frac{1}{4} \right)         
        &   & \rlap{\parbox{\linegoal}{Multiply}}                   \\
    & = -\frac{1}{16}
    \end{alignat*}
        \begin{alignat*}{2}    
\left( \frac{1}{2} - \frac{1}{4} \right) \left( \frac{1}{2} - \frac{3}{4} \right)
    & = \left( \frac{4 - 2}{8} \right) \left( \frac{4 - 6}{8} \right) 
        &\qquad     
            &   \rlap{\parbox{\linegoal}{\raggedright
                Simplify within parenthesis. Simplify within parenthesis.}}
                                                                    \\[1ex]
    & = \left( \frac{2}{8} \right) \left( \frac{-2}{8} \right)        
        &   &  \rlap{\parbox{\linegoal}{\raggedright
                Add within grouping symbols}}                       \\
    & = \left( \frac{1}{4} \right) \left(-\frac{1}{4} \right)         
        &   & \rlap{\parbox{\linegoal}{Multiply}}                   \\
    & = -\frac{1}{16}
    \end{alignat*}
\end{document}

它发出如下所示的警告:

在此处输入图片描述

有办法解决这个问题吗?

答案1

使用linegoal(表示 parboxes 宽度)和nccmath(表示左边的局部移动方程):

\documentclass[letterpaper]{article}
\usepackage{geometry}
\usepackage{nccmath}  
\usepackage{linegoal}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}

\begin{fleqn}[4em]
\[
\begin{aligned}
\left( \frac{1}{2} - \frac{1}{4} \right) \left( \frac{1}{2} - \frac{3}{4} \right)
    & = \left( \frac{4 - 2}{8} \right) \left( \frac{4 - 6}{8} \right) 
        &\qquad     
            &   \rlap{\parbox{\linegoal}{\raggedright
                Simplify within parenthesis. Simplify within parenthesis.}}
                                                                    \\[1ex]
    & = \left( \frac{2}{8} \right) \left( \frac{-2}{8} \right)        
        &   &  \rlap{\parbox{\linegoal}{\raggedright
                Add within grouping symbols}}                       \\
    & = \left( \frac{1}{4} \right) \left(-\frac{1}{4} \right)         
        &   & \rlap{\parbox{\linegoal}{Multiply}}                   \\
    & = -\frac{1}{16}
    \end{aligned}
\]
\end{fleqn}

\end{document}

编辑: 上述第一次编译后,MWE 给出了许多警告,主要是关于未定义的引用。这些警告在第二次编译后(即 parbox 达到最终大小时)消失:

在此处输入图片描述

(红线表示文本边框)

答案2

猜测列的宽度p是 tabularx 包的主要动机:

在此处输入图片描述

\documentclass{article}

\usepackage{tabularx}
\usepackage{amsmath}

\begin{document}


\begin{flushleft}
  \begin{tabularx}{\linewidth}{
@{}
>{$\displaystyle}r<{$}
@{}
>{$\displaystyle{}}l<{$}
>{\raggedright\arraybackslash}X
@{}
}
  \left( \frac{1}{2}-\frac{1}{4} \right) \left( \frac{1}{2}-\frac{3}{4} \right) 
  &= \left( \frac{4-2}{8} \right) \left( \frac{4-6}{8} \right) 
  & Simplify within parenthesis. 
          Simplify within parenthesis. Simplify within parenthesis. 
          Simplify within parenthesis. \\[12pt]
  &= \left( \frac{2}{8} \right) \left( \frac{-2}{8} \right) 
  & Add within grouping symbols. \\[12pt]
  &= \left( \frac{1}{4} \right) \left(-\frac{1}{4} \right) 
  & Multiply.\\[12pt]
  &=  -\frac{1}{16}
  \end{tabularx}
\end{flushleft}

\end{document}

相关内容