# Align Text within Minipage

I have seen some similar posts, but none of the suggested solutions worked in my case, so I need to post the question.

The problem seems simple, but somehow I mess it up. I have a minipage on my front cover and within this minipage I have two titles of parts of my thesis, followed by the advisor. The advisor should be aligned right and if the title does not exceed one line, then the advisor should be put in the next line (and flushed right). For long titles this works, but not for short ones.

I have first tried \\ \hfill, and although this did not produce vertical space (as expected), it also did not flush the advisor to the right. I then tried flushright (see MWE), but this produces the vertical space seen in the output.

How do I flush the advisor to the right if the line is empty, without producing additional vertical white space?

MWE:

\documentclass{book}
\begin{document}
\begin{minipage}[t]{1\textwidth}
{Part \textrm{I}: This is a very very very  very very very very very very very very long title name \hfill Advisor: First Name \textsc{Second Name}}\vspace{0.5\baselineskip}
{Part \textrm{II}: This is a very very very long title name}\\%
{\begingroup\setlength\topsep{0pt}
\begin{flushright}
Advisor: First Name \textsc{Second Name}
\end{flushright}
\endgroup}
\end{minipage}
\end{document}


Current output:

Desired output:

Any help is very appreciated!

Too long for a comment, here is some code from the memoir class

\documentclass{book}

\makeatletter
% verbatim copy from the memoir class
\newcommand*{\sourceatright}[2][2em]{{%
\unskip\nobreak\hfil\penalty50
\hskip#1\hbox{}\nobreak\hfil{#2}
\parfillskip\z@\finalhyphendemerits=0\par}}
\makeatother

\begin{document}

\begin{minipage}[t]{1\textwidth}
Part \textrm{I}: This is a very very very  very very very very very
very very very long title name
\sourceatright{Advisor: First Name \textsc{Second Name}}

\vspace{0.5\baselineskip}

Part \textrm{II}: This is a very very very long title name
\sourceatright{Advisor: First Name \textsc{Second Name}}
\end{minipage}
\end{document}


• @JohnA. note that memoir is more or less a drop in replacement for the book class, plus more... If it worked mark the answer as approved. – daleif Feb 1 '18 at 13:52