Alignment: "Breaking out" of environment (enumerate / minipage)
You can put the text in box of fixed size hidden in a box of zero width. Here I have encapsulated this in a \subtotal
macro. To make this match you need the total in a corresponding box too. You should calculate the width from the space you know you have left. Note you were missing a \noindent
before your minipage
.
\documentclass{article}
\usepackage{lipsum}
\newlength{\mytotboxwd}
\setlength{\mytotboxwd}{20pt}
\newcommand{\subtotal}[2][\mytotboxwd]{\hbox to 0pt{\hbox to #1{\hss #2}\hss}}
\newcommand{\total}[2][\mytotboxwd]{\hbox to #1{\hss #2}}
\begin{document}
\setlength{\mytotboxwd}{.1\textwidth}
\noindent
\begin{minipage}{.9\textwidth}
\begin{enumerate}
\item \lipsum[1]
\begin{enumerate}
\item Something \dotfill 11
\item Something \dotfill 84\subtotal{95}
\end{enumerate}
\item \lipsum[2]
\begin{enumerate}
\item Something \dotfill 4
\item Something \dotfill 300\subtotal{304}
\end{enumerate}
\end{enumerate}
\end{minipage}
\null\hfill\total{Total: 399}
\end{document}
Do you want something like this? It takes two LaTeX runs to synchronize.
\documentclass{article}
\usepackage{microtype} % not essential, but better typesetting
\usepackage{lipsum,showframe}
\newenvironment{totals}
{%
\par
\addtocounter{envtotals}{1}%
\settowidth{\totalswidth}{\ref{\theenvtotals label}\quad}%
\setcounter{totals}{0}%
\begin{list}{}{\leftmargin=0pt\rightmargin=\totalswidth}\item\relax
}
{\par
\addtocounter{totals}{-1}\refstepcounter{totals}\label{\theenvtotals label}%
\noindent\hfill Total:\subtotalbox{\ref{\theenvtotals label}}%
\end{list}
}
\newcommand{\subtotalbox}[1]{\makebox[0pt][l]{\makebox[\totalswidth][r]{#1}}}
\newenvironment{quantities}
{\begin{enumerate}\setcounter{subtotals}{0}}
{\unskip\subtotalbox{\thesubtotals}\addtocounter{totals}{\value{subtotals}}\end{enumerate}}
\newcommand{\quantity}[2]{%
\item #1\dotfill#2%
\addtocounter{subtotals}{#2}%
}
\newcounter{envtotals}
\newcounter{totals}
\newcounter{subtotals}
\newlength{\totalswidth}
\begin{document}
\begin{totals}
\begin{enumerate}
\item \lipsum[1]
\begin{quantities}
\quantity{Something}{11}
\quantity{Something}{84}
\end{quantities}
\item \lipsum[2]
\begin{quantities}
\quantity{Something}{4}
\quantity{Something}{300}
\end{quantities}
\end{enumerate}
\end{totals}
\end{document}