2
\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{nicefrac}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{xcolor}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

\usepackage[lastexercise]{exercise}

\definecolor{DarkBlue}{rgb}{0.00,0.08,0.45} % #000086
\renewcommand{\Question}{ \color{DarkBlue}}

\begin{document}

\section{Minimal Beispiel} \vspace{2cm}

\begin{ExerciseList}
\Exercise{teest}
  \Question{Hier steht die Frage?}
  \Answer{Hier steht die Antwort}
\end{ExerciseList}

\end{document}
1
  • Welcome to TeX.SX! I assume you do not like the result of \Question{\textcolor{DarkBlue}{Hier steht die Frage?}} ? Nov 20, 2021 at 10:44

1 Answer 1

2

Welcome to TeX.SX! Sadly, this package does not allow for easy styling, therefore you need to do some tricks.

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{xcolor}

\usepackage[lastexercise]{exercise}

\definecolor{DarkBlue}{rgb}{0.00,0.08,0.45} % #000086

\let\OldQuestion\Question
\renewcommand{\Question}[1]{\OldQuestion{\color{DarkBlue} #1}}

% in case you also want to color the number:
\renewcommand{\QuestionNB}{{\color{DarkBlue}\arabic{Question}.\ }}

\begin{document}

\section{Minimal Beispiel} \vspace{2cm}

\begin{ExerciseList}
\Exercise{teest}
  \Question{Hier steht die Frage?}
  \Answer{Hier steht die Antwort}
\end{ExerciseList}

\end{document}

enter image description here


Since you asked, let me give you a short explanation what is going on:

The macro \Question does a lot of formatting stuff to the argument (the part in curly brackets) that you pass to it. Its defintion is actually as follows (there no need to understand this definition, of course):

\def\Question{\@InitQuestion\@ifnextchar[\@@Question{\@@Question[]}}%]

Now, if you say \renewcommand{\Question}{\color{DarkBlue}} you overwrite all this definition and the formatting gets lost. Instead you get quite a quirky output that you would probably not expect. (You are actually lucky that you did not get an error at all.)

What would actually work is placing the color macro inside the argument of the \Question macro: \Question{\color{DarkBlue}Steht hier eine Frage?}. But of course you would have to do this for every single question and I understand that you want to use this color for all questions and therefore are looking for a better solution.

Now, the solution actually is to copy the original macro and then replace the original one. The macro \let does exactly this: It copies the definition of the old macro \Question to a new macro, which I called \OldQUestion. Having stored the original defintion somewhere else, we can safely redefine the original \Question macro with \OldQuestion{\color{DarkBlue} #1}. This way, we have included the color macro inside the \Question macro. The #1 part stands for the argument you pass to the macro. I hope this explanation was understandable.

2
  • What happens at OldQuestion? Why do I need oldQuestion?
    – quittiert
    Nov 21, 2021 at 15:01
  • 1
    @quittiert I added an explanation to my answer. Nov 21, 2021 at 17:07

You must log in to answer this question.

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