0

My problem sounds rather simple, but I couldn't find a solution yet. I'm trying to typeset a long, colored title (which spans over two lines), such that the second line is right-aligned. In other words, I'm looking for something like the multline environment, but for colored text. Sounds easy, but neither the general solutions for right-aligned text here (nor here) work.

\documentclass[a4paper, 11pt, ngerman]{scrartcl}

\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenx}
\renewcommand*\sfdefault{phv}

\parindent0mm
\usepackage[a4paper, left=12.7mm, right=12.7mm, top=12.7mm, bottom=13mm]{geometry}
\usepackage{showframe}
\usepackage{setspace}
\onehalfspacing

\usepackage{xcolor}

\title{Alignment inside Textcolor}
\author{rotton}
\date{}

\begin{document}

{\sffamily
%% Not working as expected
\textcolor{blue}{\LARGE Richard David Precht: Wer bin ich -- und wenn ja, wie viele? \\
{\raggedleft{} Eine philosophische Reise}}

%% Not working as expected
\textcolor{red}{\LARGE Richard David Precht: Wer bin ich -- und wenn ja, wie viele? \\
\hfill Eine philosophische Reise}

%% Working, but with big vertical offset
\textcolor{green}{\LARGE Richard David Precht: Wer bin ich -- und wenn ja, wie viele? \\
\begin{flushright} Eine philosophische Reise \end{flushright}}

%% Working, but not inside textcolor
{\LARGE Richard David Precht: Wer bin ich -- und wenn ja, wie viele? \par
\hfill Eine philosophische Reise}
}

Etwas mehr Text.
\end{document}

What I'm trying to achieve should look like the fourth example, but with colored text: Right aligned colored text

4
  • 1
    {\color{red}\LARGE Richard David Precht: Wer bin ich -- und wenn ja, wie viele? \par \hfill Eine philosophische Reise} Commented Feb 7, 2017 at 17:18
  • It works. So the question boils down to: Why does \par work inside \color, but gives an error inside \textcolor?
    – winkmal
    Commented Feb 7, 2017 at 17:31
  • \color is a switch. \textcolor is a command with argument and not long. So it does not allow \par inside the text argument. Commented Feb 7, 2017 at 17:38
  • Ok. But I'm still wondering why neither \` nor \newline{}` work instead of \par?
    – winkmal
    Commented Feb 7, 2017 at 17:47

2 Answers 2

1

The following should do the job. (\leavevmode allows you to write several paragraphs in the same color, so it might be useful.)

    \documentclass[a4paper, 11pt, ngerman]{scrartcl}

    \usepackage[ngerman]{babel}
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenx}
    \renewcommand*\sfdefault{phv}

    \parindent0mm
    \usepackage[a4paper, left=12.7mm, right=12.7mm, top=12.7mm, bottom=13mm]{geometry}
    \usepackage{showframe}
    \usepackage{setspace}
    \onehalfspacing

    \usepackage{xcolor}

    \newcommand{\Blue}[1]{{\leavevmode\color{blue}{#1}}}


    \title{Alignment inside Textcolor}
    \author{rotton}
    \date{}

    \begin{document}

    {\sffamily
    \Blue{\LARGE Richard David Precht: Wer bin ich -- und wenn ja, wie viele? \par
    \hfill Eine philosophische Reise}
    }

    Etwas mehr Text.
    \end{document}
1
  • Thanks, it works although there's one pair of curly braces too many. I tried to include LARGE inside the command definition in the preamble, but this increases the line space between first and second line. Still wondering why \textcolor doesn't work here. I understand that \color is a switch and \textcolor not, but even with \leavemode, \par inside \textcolor gives an error, and \` inside \textcolor` gives two left-aligned lines, ignoring \hfill. :/ One probably needs a deeper knowledge of TeX interiors to understand this behavior.
    – winkmal
    Commented Feb 22, 2017 at 10:58
2

Perhaps not the best solution, but it works with \textcolor.

Responding to the space problem at the end of the second line mentioned by @rotton I edited my code examples. The space is a result of the closing curly brace on a separate line. I have no technical explanation for this, but added several examples how to solve the problem.

% produces space at the end of the second line
{\sffamily
\textcolor{red}{\LARGE Richard David Precht: Wer bin ich -- und wenn ja, wie viele? \\
\mbox{}\hfill Eine philosophische Reise}
}

% no space at the end of the second line
\textcolor{red}{\LARGE Richard David Precht: Wer bin ich -- und wenn ja, wie viele? \\
\mbox{}\hfill Eine philosophische Reise}

% no space at the end of the second line
{\sffamily
\textcolor{red}{\LARGE Richard David Precht: Wer bin ich -- und wenn ja, wie viele? \\
\mbox{}\hfill Eine philosophische Reise}% <--
}

% no space at the end of the second line
{\sffamily
\textcolor{red}{\LARGE Richard David Precht: Wer bin ich -- und wenn ja, wie viele? \\
\mbox{}\hfill Eine philosophische Reise}}

% no space at the end of the second line
\textcolor{red}{\sffamily\LARGE Richard David Precht: Wer bin ich -- und wenn ja, wie viele? \\
\mbox{}\hfill Eine philosophische Reise}

% no space at the end of the second line
\sffamily
\textcolor{red}{\LARGE Richard David Precht: Wer bin ich -- und wenn ja, wie viele? \\
\mbox{}\hfill Eine philosophische Reise}
2
  • Working, but not very elegant. Also, "Reise" is not 100% right-aligned, i.e., there's a tiny space between it and the right margin, which is not present with @marmot 's solution.
    – winkmal
    Commented Feb 22, 2017 at 10:52
  • 1
    @rotton I edited my post to respond to your problem.
    – Nils Vogel
    Commented Feb 23, 2017 at 12:52

You must log in to answer this question.

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