Hfill – Too long content before \hfill breaks right alignment

alignmentformattinghfill

I have a list where each item has a number of points assigned to it, which should be in the same row on the right side. This works very well in almost all cases with \hfill. However, if the line becomes too long and there is no more space for the number of points, it is moved to the next line but not right-justified, but left-justified.
Is there a way to keep this for all points, independent of the length of the line, always on the right side?

\documentclass[a4paper,12pt]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[sfdefault]{libertine}

\begin{document}

\begin{enumerate}
    \item blablabla \hfill 1~P
    \item Beschreiben Sie ausführlich eine Maßnahme zur Förderung der Gesundheit in der Kita\hfill 3~P
\end{enumerate}

\end{document}

enter image description here

Best Answer

Try using \hspace*{\fill} instead of \hfill. Moreover, I'd pack the formatting into a macro, just in case you have to adjust the formatting. Put

\newcommand\Punkte[1]{\unskip\hspace*{\fill}~#1~P}

into the preamble and use it as

... Gesundheit in der Kita\Punkte{3}

enter image description here

\documentclass[a4paper,12pt]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[sfdefault]{libertine}
\newcommand\Punkte[1]{\unskip\hspace*{\fill}~#1~P}
\begin{document}

\begin{enumerate}
    \item blablabla\Punkte{1}
    \item Beschreiben Sie ausführlich eine Maßnahme zur Förderung der Gesundheit in der Kita\Punkte{3}
\end{enumerate}

\end{document}
Related Question