我想在 中获得下面的精确输出LaTeX
。但无法修复它以及如何在每个example
环境的 marginpar 中设置图像。
我的 MWE 是:
\documentclass{book}
\usepackage{tcolorbox}
\usepackage[tikz]{mdframed}
\makeatletter
\definecolor{examplecolor}{cmyk}{0.7,0.63,0.07,0}
\definecolor{examplecolortext}{cmyk}{1,0.2,0,0}
\tikzset{
my example style/.style={font=\bfseries, anchor=west, align=left, text=examplecolor},
}
\newcounter{example}[chapter]
\renewcommand{\theexample}{\arabic{example}}
\newenvironment{example}[1][]{
\stepcounter{example}%
\ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\begin{tikzpicture}
\node [my example style, text width=.2\linewidth] {\strut Example~\theexample};
\end{tikzpicture}%
}%
}%
}%
{\mdfsetup{%
frametitle={%
\begin{tikzpicture}
\node (some node) [my example style, text width=.2\linewidth, inner xsep=0pt, inner ysep=-10pt] {\strut Example~\theexample};
\node [my example style, text=examplecolortext, text width=.75\linewidth] {\strut\hspace*{-35pt}#1};
\end{tikzpicture}%
}%
}%
}%
\mdfsetup{%
frametitlebackgroundcolor=examplecolortext,
linecolor=white,%
linewidth=0pt,
frametitlerule=true,
frametitlerulewidth=2.5pt,
}\relax
\begin{mdframed}%
}{%
\end{mdframed}%
}
\makeatother
\begin{document}
\begin{example}[Writing expressions from word descriptions]
Write an expression for each of the following.
\begin{enumerate}
\item 5 more than
\item 3 less than
\item the sum of
\item double the value of
\item the product of
\end{enumerate}
\end{example}
\end{document}
答案1
一种可能性是使用tcolorbox
(根据您的需要调整设置):
代码:
\documentclass{book}
\usepackage{graphicx}
\usepackage{changepage}
\usepackage[many]{tcolorbox}
\usepackage{lipsum}
\definecolor{titlecolor}{RGB}{0,135,221}
\definecolor{titleheadcolor}{RGB}{107,88,168}
\definecolor{titlebg}{RGB}{249,252,98}
\definecolor{framebg}{RGB}{252,254,197}
\newtcbtheorem{myexample}{Example}{
breakable,
enhanced,
freelance,
frame empty,
interior empty,
toptitle=5pt,
bottomtitle=5pt,
check odd page,
overlay={
\ifoddpage
\node[overlay,anchor=west]
at ([xshift=\marginparsep]title.east)
{\includegraphics[height=22pt]{image-1}};
\else
\node[overlay,anchor=east]
at ([xshift=-\marginparsep]title.west)
{\includegraphics[height=22pt]{image-1}};
\fi
},
title code={
\fill[titlebg]
(title.south west) {[rounded corners=10pt] --
(title.north west) --
(title.north east)} --
(title.south east) --
(title.south west);
\draw[white,line width=3pt]
(title.south west) -- (title.south east);
},
segmentation code={
\draw[white,line width=3pt]
(segmentation.west) -- (segmentation.east);
}
coltitle=titlecolor,
colback=framebg,
fonttitle=\sffamily,
coltitle=titleheadcolor,
boxrule=0pt,
description color=titlecolor
}{exa}
\newcommand\SolExp{%
\par\bigskip\color{titlecolor!90}\textsc{solution}\hfill\textsc{explanation}\hfill\null%
\tcblower
}
\begin{document}
\begin{myexample}{Writing expressions from world descriptions}{expressions}
\lipsum[4]
\SolExp
\lipsum[4]
\end{myexample}
\lipsum[1-4]
\begin{myexample}{Writing expressions from world descriptions and a longer title spanning more than one line}{longer}
\lipsum[4]
\SolExp
\lipsum[4]
\end{myexample}
\end{document}