2

Consider this MWE

\documentclass[a4paper]{article}

\usepackage[top=1in, bottom=1.25in, left=1.25in, right=1.25in]{geometry}

\usepackage{enumerate}
\usepackage[ngerman]{babel}
\usepackage{ifthen} % for conditionals in newcommand
\usepackage[utf8]{inputenc}

\newcommand{\point}[1]{\ifthenelse{\equal{#1}{1}}{\hfill \mbox{(\emph{#1 point})}}{\hfill \mbox{(\emph{#1 points})}}} % command to display points 

\begin{document}
\begin{enumerate}[(a)]
  \item This is how it is mostly the case. \point{1}
  \item Here, I want the \textit{(2 points)} to be aligned on the right side. This sometimes happens\ldots \point{2}
\end{enumerate}

\end{document}

which gives this output (except for the red arrow/box): enter image description here

I would like the "(2 points)" to be aligned on the right, where the red box is. However, I do not know how to modify the \point command in order to achieve what I desire. Naively including the \hfill into the \mbox produces the same output as shown above.

So, how do I have to modify the \point command, in order to align text always on the right - even if there was a linebreak right before the "(x points)" part?

2

2 Answers 2

1

This shifts to the right an amount equal to the label size and places an \mbox{}\allowbreak (possibly forcing a line break). It then shifts back leftward by that amount, and issues an \hfill prior to the label.

\documentclass[a4paper]{article}

\usepackage[top=1in, bottom=1.25in, left=1.25in, right=1.25in]{geometry}

\usepackage{enumerate}
\usepackage[ngerman]{babel}
\usepackage{ifthen} % for conditionals in newcommand
\usepackage[utf8]{inputenc}
\newcommand{\point}[1]{\ifthenelse{\equal{#1}{1}}%
  {\def\tmpsfx{}}{\def\tmpsfx{s}}%
  \setbox0=\hbox{(\emph{#1 point\tmpsfx})}%
  \hspace{\wd0}\mbox{}\allowbreak\hspace{-\wd0}\hfill\box0%
  } % command to display points 

\begin{document}
\begin{enumerate}[(a)]
  \item This is how it is mostly the case. \point{1}
  \item Here, I want the \textit{(2 points)} to be aligned on the right side. This sometimes happens\ldots \point{2}
\end{enumerate}

\end{document}

enter image description here

1
  • @StevenBSegletes Thank you very much! Very nice solution
    – Lukas
    Mar 29, 2016 at 12:50
0

Thanks to the answer by @UlrikeFischer in another question, I was able to solve the issue based on the command \quelle which is provided in the answer referred to in above link:

\newcommand\toRight[1]{{%
      \unskip\nobreak\hfil\penalty50
      \hskip2em\hbox{}\nobreak\hfil #1%
      \parfillskip=0pt \finalhyphendemerits=0 \par}}

\newcommand{\point}[1]{\ifthenelse{\equal{#1}{1}}{\toRight{\mbox{(\emph{#1 point})}}}{\toRight{\mbox{(\emph{#1 points})}}}} % command to display points

Using this produces an output as desired: enter image description here

You must log in to answer this question.

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