In another thread I asked for a little help with setting up an own solution
environment to use in student assignment-sheets.
We there checked a boolean (if it's the solution sheet or only the assignment sheet for the students) and if the boolean returns to true
, the answers inside the solution
environment are printed. (Code is inside the MWE)
As the questions are set up in an enumerate
environment, the questions and the answers are indented.
The little issue I now have, is that the solution-container (a tcolorbox
) is wider than the linewidth
. If I indent a second time it's even bigger...
How can I restrict this environment to the real \linewidth
?
Here is a MWE:
\documentclass[12pt]{article}
% %%%
% Packages
% %%%
\usepackage[utf8]{inputenc}
\usepackage[showframe]{geometry}
\geometry{verbose, a4paper, tmargin=3cm, bmargin=3cm, lmargin=2.5cm, rmargin=2.5cm}
\usepackage{lipsum, enumerate, ifthen, tcolorbox}
\tcbuselibrary{breakable}
% %%%
% Variable Settings
% %%%%
\newboolean{solution}
\setboolean{solution}{true}
% %%%
% Environments / Commandy
% %%%%
\newcommand{\Problem}[1]{
{
\vspace*{0.5cm}
\textsf{\textbf{Problem #1}}
\vspace*{0.2cm}
}
}
\newenvironment{solution}
{
\ifthenelse{\boolean{solution}}{
\tcolorbox[breakable, width=\textwidth, colframe=red, colback=white]
}{}
}
{
\ifthenelse{\boolean{solution}}{
\endtcolorbox
\vspace*{-\baselineskip}
}{}
}
% %%%
% Document
% %%%%
\begin{document}
\begin{center}
\LARGE \sf \textbf{MWE}
\end{center}
\vspace*{0.2cm}
\Problem{1: Foo}
\begin{enumerate}
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In hac habitasse platea dictumst.
\begin{solution}
\lipsum[4-5]
\end{solution}
\begin{enumerate}
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In hac habitasse platea dictumst.
\begin{solution}
\lipsum[4-4]
\end{solution}
\end{enumerate}
\end{enumerate}
\end{document}
I used the showframe
attribute of the geometry
-package to show the real \linewidth
and where my environment is. It's clear, that the overlapping is exactly the same as the indention of the enumerate.
Thank you very much for your help.