3

Consider the following 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}

issues the error

enter image description here

This is primarily due to the \parbox[t]{0.5\textwidth}{<content>}.

Is it possible to create an environment that calculates the remaining linewidth for each line independently that the \parbox can use?

enter image description here


Consider the MWE using the linegoal package suggested by @zarko:

\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}

it issues the warnings shown below:

enter image description here

Is there a fix to this?

2 Answers 2

2

With use of linegoal (for parboxes widths) and nccmath (for local moving equation to the left):

\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}

Edit: After first compilation above MWE gives number of warnings, mostly regarding to undefined references. These warnings disappear after second compilation when the parbox get final size:

enter image description here

(red lines indicate text borders)

12
  • It issues the warning Extended allocation already in use. Say you copy several instances of the code above right after each other, the linegoal package issues several errors/warnings.
    – azetina
    Jan 4, 2021 at 5:40
  • @azetina, I didn't observe such varning.
    – Zarko
    Jan 4, 2021 at 5:53
  • I updated my question with your suggested answer. For some reason or the other I get those warnings.
    – azetina
    Jan 4, 2021 at 6:03
  • @azetina, warnings are just warnings. Those warnings doesn't harm result. Linegoal xpect equation numbering which are not present. Meanwhile I a wee bit improve code and result. BTW, if you in edited question use code from my answer, it would be nice to mention this :-)
    – Zarko
    Jan 4, 2021 at 6:15
  • I updated my questions with credits to you. BTW you are missing the \begin{aligned}
    – azetina
    Jan 4, 2021 at 6:21
1

Guessing the width of a p column is the main motivation for the tabularx package:

enter image description here

\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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .