0

I am attempting to use this example environmment in my book. I really like how it creates a vertical line next to examples. I would like to customize the appearance, but that is a separate question.

In this question, I would like to focus on another issue. When I use this in my kaobook, it changes the indentation of lists inside of kaobox environments:

enter image description here

\documentclass[
fontsize=10pt, % Base font size
twoside=false, % Use different layouts for even and odd pages (in particular, if twoside=true, the margin column will be always on the outside)
%open=any, % If twoside=true, uncomment this to force new chapters to start on any page, not only on right (odd) pages
%chapterprefix=true, % Uncomment to use the word "Chapter" before chapter numbers everywhere they appear
%chapterentrydots=true, % Uncomment to output dots from the chapter name to the page number in the table of contents
numbers=noenddot, % Comment to output dots after chapter numbers; the most common values for this option are: enddot, noenddot and auto (see the KOMAScript documentation for an in-depth explanation)
%draft=true, % If uncommented, rulers will be added in the header and footer
%overfullrule=true, % If uncommented, overly long lines will be marked by a black box; useful for correcting spacing problems
]{kaobook}

% Set the language
\usepackage[english]{babel} % Load characters and hyphenation
\usepackage[english=british]{csquotes} % English quotes

% Load mathematical packages for theorems and related environments. NOTE: choose only one between 'mdftheorems' and 'plaintheorems'.
\usepackage{styles/mdftheorems}
%\usepackage{styles/plaintheorems}

\usepackage[most]{tcolorbox}
\newcounter{bookexample}
\usepackage{xparse}

%https://tex.stackexchange.com/questions/369265/math-book-how-to-write-exercise-and-answers
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{multicol}
\usepackage{ifthen}
\newboolean{firstanswerofthechapter}  
\usepackage{xcolor}
\colorlet{lightcyan}{cyan!40!white}
\usepackage{chngcntr}
\usepackage{stackengine}
\usepackage{tasks}
\newlength{\longestlabel}
\settowidth{\longestlabel}{\bfseries viii.}
\settasks{label=\roman*., label-format={\bfseries}, label-width=\longestlabel,
    item-indent=20pt, label-offset=2pt, column-sep={10pt}}
\usepackage[lastexercise,answerdelayed]{exercise}
\counterwithin{Exercise}{chapter}
\counterwithin{Answer}{chapter}
\renewcounter{Exercise}[chapter]
\newcommand{\QuestionNB}{\bfseries\arabic{Question}.\ }
\renewcommand{\ExerciseName}{EXERCISES}
\renewcommand{\ExerciseHeader}{\noindent\def\stackalignment{l}% code from https://tex.stackexchange.com/a/195118/101651
    \stackunder[0pt]{\colorbox{cyan}{\textcolor{white}{{\bfseries\LARGE\ExerciseHeaderNB\hspace{0.27em}}{\bfseries\large\ExerciseName}}}}{\textcolor{lightcyan}{\rule{\linewidth}{2pt}}}\medskip}
\renewcommand{\AnswerName}{Exercises}
\renewcommand{\AnswerHeader}{\ifthenelse{\boolean{firstanswerofthechapter}}%
    {\bigskip\noindent\textcolor{cyan}{\textbf{CHAPTER \thechapter}}\newline\newline%
        \noindent\bfseries\emph{\textcolor{cyan}{\AnswerName\ \ExerciseHeaderNB, page %
                \pageref{\AnswerRef}}}\smallskip}
    {\noindent\bfseries\emph{\textcolor{cyan}{\AnswerName\ \ExerciseHeaderNB, page \pageref{\AnswerRef}}}\smallskip}}
\setlength{\QuestionIndent}{16pt}

%https://tex.stackexchange.com/questions/420643/adding-vertical-line-next-to-example-environment
\def\exampletext{Example} % If English
\NewTColorBox[use counter=bookexample]{bookexamplebox}{O{}o}{%
% Example Frame Start
empty,% Empty previously set parameters
%enhanced,
title={\exampletext\ \thetcbcounter: #1},% use \thetcbcounter to access the 
% Attaching a box requires an overlay
attach boxed title to top left,
% Ensures proper line breaking in longer titles
minipage boxed title,
% (boxed title style requires an overlay)
boxed title style={empty,size=minimal,toprule=0pt,top=4pt,left=3mm,overlay={}},
coltitle=colexam,
fonttitle=\bfseries, 
before=\par\medskip\noindent,
boxsep=0pt,left=3mm,
right=0mm,top=2pt,
breakable,
pad at break=0mm,
before upper=\csname @totalleftmargin\endcsname0pt, % Use instead of 
parbox=true, %This ensures parskip is inherited by box.
% Handles box when it exists on one page only
overlay unbroken={\draw[colexam,line width=5pt] ([xshift=-0pt]title.north 
  west) -- ([xshift=-0pt]frame.south west); 
},
%Handles multipage box: first page
overlay first={\draw[colexam,line width=5pt] ([xshift=-0pt]title.north west) 
  -- ([xshift=-0pt]frame.south west); },
%Handles multipage box: middle page
overlay middle={\draw[colexam,line width=5pt] ([xshift=-0pt]frame.north west) 
  -- ([xshift=-0pt]frame.south west); },
% Handles multipage box: last page
overlay last={\draw[colexam,line width=5pt] ([xshift=-0pt]frame.north west) - 
  - ([xshift=-0pt]frame.south west); },%
IfValueTF={#2}{#2}{},
}
\NewDocumentEnvironment{bookexample}{O{}O{}}
{%
  \colorlet{colexam}{red!55!black} % Global example color
  \begin{bookexamplebox}[#1][#2]
}{\end{bookexamplebox}\endlist}

\begin{document}
\chapter{Chapter Name}

\begin{objective}
Consider the following list:
\begin{itemize}
    \item Item 1
    \item Item 2
    \item Item 3
\end{itemize}
\end{objective}

\begin{theorem}
Consider the following list:
\begin{enumerate}
    \item Question 1
    \item Question 2
    \item Question 3
\end{enumerate}
\end{theorem}

\begin{bookexample}{
Consider the following list:
\begin{enumerate}
    \item Question 1
    \item Question 2
    \item Question 3
\end{enumerate}}
\end{bookexample}

\begin{kaobox}[frametitle=Solution]
Consider the following list:
\begin{enumerate}
    \item Solution 1
    \item Solution 2
    \item Solution 3
\end{enumerate}
\end{kaobox}

\begin{objective}
Consider the following list:
\begin{itemize}
    \item Item 1
    \item Item 2
    \item Item 3
\end{itemize}
\end{objective}

\begin{theorem}
Consider the following list:
\begin{enumerate}
    \item Question 1
    \item Question 2
    \item Question 3
\end{enumerate}
\end{theorem}

\begin{Exercise}\label{EX11}
\vspace{-\baselineskip}% <-- You don't need this line of code if there's some text here
\Question Multiple choice question
\settasks{label={(\Alph*)}}
\begin{tasks}(4)
\task Choice 1
\task Choice 2
\task Choice 3
\task\label{correctchoice_1.1.1} Choice 4
\end{tasks}

\Question Multi-part question
\settasks{label={\roman*.}}
\begin{tasks}(1)
\task Part 1
\task Part 2
\task Part 3
\end{tasks}
\end{Exercise}
\begin{Answer}[ref={EX11}]
\Question This is a solution of Ex 1
\end{Answer}
\setboolean{firstanswerofthechapter}{false}
\end{document}

Notice how the first and second kaobox have lists that are indented properly. But after the example with the red vertical line, indentation is wrong for all every kaobox that follows.

Here is a link to an Overleaf project, if it helps.

2
  • (1) Your MWE does not compile (Missing \usepackage{styles/mdftheorems}). (2) Link to Overleaf not shared. Commented Jul 12, 2021 at 14:48
  • Oops! Overleaf link fixed! Thank you for the notice Commented Jul 12, 2021 at 16:35

1 Answer 1

2

Using \usepackage{styles/mdftheorems}; adding to your MWE

\newmdenv[
style=kaoboxstyle,
backgroundcolor=Cyan!15!White,
frametitlebackgroundcolor=Cyan!15!White,
]{objective}

and correcting

\NewDocumentEnvironment{bookexample}{O{}O{}}
{%
    \colorlet{colexam}{red!55!black} % Global example color
    \begin{bookexamplebox}[#1][#2]
    }{\end{bookexamplebox}}% changed <<<

solves the problem.

a

You must log in to answer this question.

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