tcolorbox 标题定位和框大小

tcolorbox 标题定位和框大小

我正在为我的课程重新制作一个自定义课程。我有一个使用 TikZ 的旧课程,它允许我实现以下行为:

在此处输入图片描述

但是它存在缺陷并且不允许易受破坏的环境。

我现在尝试重新制作所有内容tcolorbox,但我发现的代码产生了以下内容:

在此处输入图片描述

以下是我使用的代码:

\newlength{\mylen}
\newlength{\hauteur}
\settowidth{\mylen}{Méthode}
\setlength{\hauteur}{\baselineskip}
\addtolength{\hauteur}{0.5mm}

\newtcbtheorem{methode}{Méthode :}{
    enhanced,
    breakable,
    coltitle=eggplant, fonttitle=\bfseries, 
    detach title,
    opacityfill=0,
    frame hidden,
    %left=\dimexpr\textwidth-\mylen\relax,
    %top=0mm,
    %boxsep=0mm,
    borderline west = {0.5pt}{0pt}{},
    overlay unbroken and first={
        \node[xshift=-\mylen,yshift=-\hauteur] at (frame.north west) {\tcbtitle};
    }
}{meth}

sidebyside选项可以工作但它不允许易破坏的环境,有人可以给我指出正确的方向吗?

编辑:正如这里所问的是一些可编译的代码:

\documentclass[a4paper,oneside]{extreport}

\usepackage{fullpage}

\usepackage[svgnames]{xcolor}

\usepackage{arev}

\usepackage[french]{babel}

\usepackage{tcolorbox}
\tcbuselibrary{most}

\newlength{\mylen}
\newlength{\hauteur}
\newlength{\malongueur}
\settowidth{\mylen}{Méthode :}
\setlength{\hauteur}{\baselineskip}
\addtolength{\hauteur}{0.5mm}
\settowidth{\malongueur}{408.52pt}
%\addtolength{\malongueur}{-\mylen}

%définition des couleurs
\definecolor{blueslategray}{cmyk}{0.189, 0.091, 0, 0.439}
\definecolor{greenbrown}{HTML}{555544}
\definecolor{cottonseed}{cmyk}{0, 0.026, 0.047, 0.255}
\definecolor{lightblue}{cmyk}{0.272, 0.068, 0, 0.192}
\definecolor{bluetrout}{cmyk}{0.18, 0.15, 0, 0.608}
\definecolor{brownred}{cmyk}{0, 0.531, 0.557, 0.239}
\definecolor{orangewhite}{cmyk}{0, 0.031, 0.075, 0.004}
\definecolor{avocado}{cmyk}{0.06, 0, 0.55, 0.37}
\definecolor{eggplant}{cmyk}{0.04, 0.24, 0, 0.47}
\definecolor{darkblue}{rgb}{0.12,0.47,0.87}

\newtcbtheorem{theoreme}{Théorème}{
    lower separated=false,
    colback=orangewhite,
    colframe=white, fonttitle=\bfseries,
    colbacktitle=brownred,
    coltitle=orangewhite,
    coltext=brownred,
    enhanced,
    breakable,
    boxed title style={colframe=greenbrown},
    attach boxed title to top left={yshift=-2mm},
}{theo}

\newtcbtheorem{methode}{Méthode :}{%
    enhanced,
    breakable,
    coltitle=eggplant, fonttitle=\bfseries, 
    detach title,
    opacityfill=0,
    frame hidden,
    %left=30mm,
    %top=0mm,
    %boxsep=0mm,
    borderline west = {0.5pt}{0pt}{},
    overlay unbroken and first={
        \node[xshift=-\mylen,yshift=-\hauteur] at (frame.north west) {\tcbtitle};
    }
}{meth}

\begin{document}
\begin{theoreme}{}{}
    du texte \textbf{texte} \dotfill
\end{theoreme}

\begin{methode*}{}{}
    du texte
\end{methode*}
\end{document}

这是一个“工作”版本:

\documentclass[a4paper,oneside]{extreport}

\usepackage{fullpage}

\usepackage[svgnames]{xcolor}

\usepackage{arev}

\usepackage[french]{babel}
\usepackage{lipsum}
\usepackage{tcolorbox}
\tcbuselibrary{most}

\newlength{\mylen}
\newlength{\hauteur}
\newlength{\malongueur}
\settowidth{\mylen}{Méthode :}
\setlength{\hauteur}{\baselineskip}
\addtolength{\hauteur}{0.5mm}
\settowidth{\malongueur}{408.52pt}
%\addtolength{\malongueur}{-\mylen}

%définition des couleurs
\definecolor{blueslategray}{cmyk}{0.189, 0.091, 0, 0.439}
\definecolor{greenbrown}{HTML}{555544}
\definecolor{cottonseed}{cmyk}{0, 0.026, 0.047, 0.255}
\definecolor{lightblue}{cmyk}{0.272, 0.068, 0, 0.192}
\definecolor{bluetrout}{cmyk}{0.18, 0.15, 0, 0.608}
\definecolor{brownred}{cmyk}{0, 0.531, 0.557, 0.239}
\definecolor{orangewhite}{cmyk}{0, 0.031, 0.075, 0.004}
\definecolor{avocado}{cmyk}{0.06, 0, 0.55, 0.37}
\definecolor{eggplant}{cmyk}{0.04, 0.24, 0, 0.47}
\definecolor{darkblue}{rgb}{0.12,0.47,0.87}

\newtcbtheorem{theoreme}{Théorème}{
    lower separated=false,
    colback=orangewhite,
    colframe=white, fonttitle=\bfseries,
    colbacktitle=brownred,
    coltitle=orangewhite,
    coltext=brownred,
    enhanced,
    breakable,
    boxed title style={colframe=greenbrown},
    attach boxed title to top left={yshift=-2mm},
}{theo}

\newtcbtheorem{methode}{Méthode :}{%
    enhanced,
    breakable,
    coltitle=eggplant, fonttitle=\bfseries, 
    colbacktitle=white,
    detach title,
    opacityfill=0,
    frame hidden,
    left skip=1.55\mylen,
    left=0mm,
    top=0.3mm,
    toptitle=0mm,
    %boxsep=0mm,
    %attach boxed title to top left,
    %borderline west = {0.5pt}{0pt}{},
     overlay unbroken and first={
         \node[below left] at (interior.north west) {\tcbtitle};
     }
}{meth}

\newtcbtheorem{exemple}{Exemple :}{%
    enhanced,
    breakable,
    coltitle=eggplant, fonttitle=\bfseries, 
    colbacktitle=white,
    detach title,
    opacityfill=0,
    frame hidden,
    left skip=1.55\mylen,
    left=0mm,
    top=0.3mm,
    toptitle=0mm,
    %boxsep=0mm,
    %attach boxed title to top left,
    %borderline west = {0.5pt}{0pt}{},
     overlay unbroken and first={
         \node[below left] at (interior.north west) {\tcbtitle};
     }
}{exemp}

\begin{document}

\begin{theoreme}{}{}
dsds\dotfill
\end{theoreme}

\begin{methode*}{}{}
fkdlsmfkdlsm \dotfill
\lipsum
\end{methode*}

\begin{exemple*}{}{}
turlututu \lipsum
\end{exemple*}

\end{document}

答案1

以下代码展示了对 OP 代码的一些修改,以获得更类似于原始图像的结果。

现在 Theorem 环境具有尖角,标题附加但不与文本内容重叠,并且右侧和底部有边框线。

在 中exampleoverlay部分内容已被修改,在标题和内容之间引入了垂直线。类似的解决方案可以应用于methode环境。

\documentclass[a4paper,oneside]{extreport}

\usepackage{fullpage}

\usepackage[svgnames]{xcolor}

\usepackage{arev}

\usepackage[french]{babel}
\usepackage{lipsum}
\usepackage{tcolorbox}
\tcbuselibrary{most}

\newlength{\mylen}
\newlength{\hauteur}
\newlength{\malongueur}
\settowidth{\mylen}{Méthode :}
\setlength{\hauteur}{\baselineskip}
\addtolength{\hauteur}{0.5mm}
\settowidth{\malongueur}{408.52pt}
%\addtolength{\malongueur}{-\mylen}

%définition des couleurs
\definecolor{blueslategray}{cmyk}{0.189, 0.091, 0, 0.439}
\definecolor{greenbrown}{HTML}{555544}
\definecolor{cottonseed}{cmyk}{0, 0.026, 0.047, 0.255}
\definecolor{lightblue}{cmyk}{0.272, 0.068, 0, 0.192}
\definecolor{bluetrout}{cmyk}{0.18, 0.15, 0, 0.608}
\definecolor{brownred}{cmyk}{0, 0.531, 0.557, 0.239}
\definecolor{orangewhite}{cmyk}{0, 0.031, 0.075, 0.004}
\definecolor{avocado}{cmyk}{0.06, 0, 0.55, 0.37}
\definecolor{eggplant}{cmyk}{0.04, 0.24, 0, 0.47}
\definecolor{darkblue}{rgb}{0.12,0.47,0.87}

\newtcbtheorem{theoreme}{Théorème}{
    lower separated=false,
    sharp corners,
    colback=orangewhite,
    colframe=brownred, 
    leftrule=0pt, toprule=0pt,
    fonttitle=\bfseries,
    colbacktitle=brownred,
    coltitle=orangewhite,
    coltext=brownred,
    enhanced,
    breakable,
    boxed title style={colframe=brownred, sharp corners},
    attach boxed title to top left,
}{theo}

\newtcbtheorem{methode}{Méthode :}{%
    enhanced,
    breakable,
    coltitle=eggplant, fonttitle=\bfseries, 
    colbacktitle=white,
    detach title,
    opacityfill=0,
    frame hidden,
    left skip=1.55\mylen,
    left=0mm,
    top=0.3mm,
    toptitle=0mm,
    %boxsep=0mm,
    %attach boxed title to top left,
    %borderline west = {0.5pt}{0pt}{},
     overlay unbroken and first={
         \node[below left] at (interior.north west) {\tcbtitle};
     }
}{meth}

\newtcbtheorem{exemple}{Exemple :}{%
    enhanced,
    breakable,
    coltitle=eggplant, fonttitle=\bfseries, 
    colbacktitle=white,
    detach title,
    opacityfill=0,
    frame hidden,
    left skip=1.55\mylen,
    left=0mm,
    top=0.3mm,
    toptitle=0mm,
    %boxsep=0mm,
    %attach boxed title to top left,
    %borderline west = {0.5pt}{0pt}{},
     overlay unbroken and first={
         \node[below left] at (interior.north west) {\tcbtitle};
         \draw[eggplant, line width=1.5pt] (interior.north west)--(interior.south west);
     },
     overlay middle and last={
         \draw[eggplant, line width=1.5pt] (interior.north west)--(interior.south west);
     }
}{exemp}

\begin{document}

\begin{theoreme}{}{}
dsds\dotfill
\end{theoreme}

\begin{methode*}{}{}
fkdlsmfkdlsm \dotfill
\lipsum
\end{methode*}

\begin{exemple*}{}{}
turlututu \lipsum
\end{exemple*}

\end{document}

在此处输入图片描述

在此处输入图片描述

相关内容