I want to present some information in a format which has a scenario described then dotfill to a right aligned result. If the scenario+result would fill the line, I want it to break to the next line and dotfill the entire line with the result right aligned.
I can achieve this with \makebox, but that introduces unwanted spacing between the box and the dotfill so it isn't a continuous run of dots.
MWE:
\documentclass{scrreprt}
\begin{document}
\begin{description}
\item This is some text \dotfill Result
\item This is some text which almost fills a line so dotfill does not produce an output \dotfill Result
\item This is some text which does fill the line and a break occurs but dotfill doesn't dot \dotfill Result
\item I would prefer that if the text fills the line, dotfill fills the next line before the result \makebox[3cm]{\dotfill}\dotfill Result
\end{description}
\end{document}
I've tried various combinations of \unskip and \ignorespaces, but they don't give the desired result. I can \kern-3pt the space away, but that feels hacky. I'd much prefer to generalise a solution to a command I can use instead of dotfill:
\NewDocumentCommand\myDotfill{}{\makebox[3cm]{\dotfill}\MAGICSPACEKILLER\dotfill}
Can anyone advise what I should put in a command to try to kill the unwanted horizontal space?




I can see that you used
– jw5801 Jul 06 '23 at 01:10\ShowCommandto find the code for\dotfill, and replaced\hfillin it with\hskip 3cm plus 1filllwhich does exactly what I was looking for.