示例环境旁边的垂直线会改变 itemize 和 enumerate 列表的缩进

示例环境旁边的垂直线会改变 itemize 和 enumerate 列表的缩进

我正在尝试使用此示例环境在我的书中。我真的很喜欢它在示例旁边创建垂直线的方式。我想自定义外观,但这是一个单独问题

在这个问题中,我想关注另一个问题。当我在我的 中使用它时kaobook,它会改变 kaobox 环境内的列表的缩进:

在此处输入图片描述

\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}

注意第一个和第二个kaobox列表的缩进是正确的。但是在带有红色垂直线的示例之后,kaobox后面的所有内容的缩进都是错误的。

以下是一个链接Overleaf 项目,如果有帮助的话。

答案1

使用\usepackage{styles/mdftheorems}; 添加到您的 MWE

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

并纠正

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

解决了问题。

A

相关内容