3

I am typesetting exercises with the exercise package. I want to have my custom exercise header, my custom answer header as well as the exercise and answer body all left aligned. It works well for the answer environment, but not really for the exercise part.

\documentclass[a4paper]{article}
\usepackage{exercise}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage{amsmath}
\usepackage{amsthm} 
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[left=2cm,right=2.5cm,top=2.5cm,bottom=2cm]{geometry}
\numberwithin{equation}{Exercise}


\renewcommand{\ExerciseHeader}{\par\noindent\textsf{\textbf{
        Aufgabe \ExerciseHeaderNB} (\ExerciseHeaderTitle)
}\smallskip\newline}
%\ExerciseHeaderDifficulty
\renewcommand{\AnswerHeader}{\flushright \textbf{\textsf{Lösung
            \ExerciseHeaderNB}         }\ExerciseHeaderOrigin\smallskip\newline}

\renewcommand{\ExerciseHeaderTitle}{\ExerciseTitle}
\setlength{\ExerciseSkipBefore}{0\baselineskip}

\begin{document}

\begin{Exercise}[label = wdsw, title = Widerstandswürfel , difficulty =      2]
Gegeben ist ein Würfel, wobei jede der Kanten einen Widerstand von $R = 1~\mathrm{\Omega}$ hat.\\
Wie groß ist der Widerstand entlang einer Raumdiagonale?
\end{Exercise}
\begin{Answer}[ref=wdsw]
Wir wollen den Widerstand zwischen den Punkten $X$ und $Y$ bestimmen,   also entlang der Raumdiagonale (siehe Abb. \ref{fig:wdsws1}). Weil die Raumdiagonale eine Symmetrieachse ist, sollte das Problem symmetrisch sein, und deswegen eine recht einfache Lösung haben.\\
\end{Answer}
3

There are two parts to this answer:

  • After redefining the macros \ExerciseHeader and \AnswerHeader, the indentation of the the headlines equals the usual indentation of the text. You can set this to zero with:

    \setlength\parindent{0pt}
    
  • In the code of the exercise package, there is a hard-coded \hspace{.66em} at the start of the Exercise body. To neutralize it, you can redefine \AtBeginExercise:

    \renewcommand{\AtBeginExercise}{\hspace{-0.66em}}
    

So your full header section on the style of the Exercise and Answer could look like this:

\setlength\parindent{0pt}

\renewcommand{\DifficultyMarker}{}
\renewcommand{\ExerciseName}{Aufgabe}
\renewcommand{\AnswerName}{Lösung}

\renewcommand{\ExerciseHeader}{\large\textbf{\ExerciseName~\ExerciseHeaderNB} (\ExerciseTitle)\smallskip\newline}
\renewcommand{\AtBeginExercise}{\hspace{-0.66em}}

\renewcommand{\AnswerHeader}{\large\textbf{\AnswerName~\ExerciseHeaderNB}\smallskip\newline}

\setlength\AnswerSkipBefore{1em}

enter image description here


Update: You might be right, there is still too much space before the exercise title, and I'm not one hundred percent sure about the space in front of the exercise body. So with changing "Aufgabe" to "Hausaufgabe" and "Gegeben ist ein Würfel" to "Es ist ein Würfel gegeben" (to have straigth lines at the left to compare indentation more easily), I find this configuration satisfying to my eye:

\setlength\parindent{0pt}

\renewcommand{\DifficultyMarker}{}
\renewcommand{\ExerciseName}{Hausaufgabe}
\renewcommand{\AnswerName}{Lösung}

\newcommand{\AtBeginExerciseHeader}{\hspace{-0.2pt}}
\renewcommand{\ExerciseHeader}{\AtBeginExerciseHeader\large\textbf{\ExerciseName~\ExerciseHeaderNB} (\ExerciseTitle)\newline}
\renewcommand{\AtBeginExercise}{\hspace{-8.7pt}}

\renewcommand{\AnswerHeader}{\large\textbf{\AnswerName~\ExerciseHeaderNB}\smallskip\newline}

\setlength\AnswerSkipBefore{1em}

enter image description here

  • Thanks. That really solves nearly everything. I don't want to nitpick, but there is still a (very small, I didn't realise it at first) misalignment of the first line of the exercise body and the title of the the exercise ("Gegeben" is a bit off to the right). Is there a way to remove this, or to adjust the answer environment? – Razupaltuff May 15 '17 at 10:00
  • You can of course play with the definition of \AtBeginExercise. I first had it at -7pt, maybe that is a good starting point for you. Similarly, you could define a \AtBeginExerciseHeader, insert it at the beginning of the redefinition of \ExerciseHeader and start trying like -1pt there. Just change in small steps until you (and the cangaroo ;) ) are satisfied. – Tiuri May 15 '17 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.