Tcolorbox、xshift 和框的对称性

Tcolorbox、xshift 和框的对称性

我向颜色框添加了在 x 轴上移动的选项。

然而,出现了一个问题:盒子是对称的,当我将它向右移动时,左边也会向中心移动,使盒子变得非常小。如何消除这种影响?

这是代码(如果仍然有多余的内容,请告诉我。我想知道如何做 MWE)。

\documentclass[10pt,a4paper,twoside,openright]{book}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[left=2.5cm,right=2.5cm,top=4cm,bottom=4cm]{geometry}%réglages des marges du document selon vos préférences ou celles de votre établissemant
\setlength{\headheight}{15pt}% hauteur de l'entête

\usepackage{amsmath,amsfonts,amssymb}%extensions de l'ams pour les mathématiques
\usepackage{fancyhdr}%pour les entêtes et pieds de pages
\usepackage[most]{tcolorbox}
\usepackage[english,french]{babel}%pour un document en français

\definecolor{viol}{RGB}{134,0,175}



\tcbset{
    thmbox/.style={
        enhanced,
        breakable,
        sharp corners=all,
        fonttitle=\bfseries\normalsize,
        fontupper=\normalsize\itshape,
         top=0mm,
         bottom=0mm,
         right=0mm,
        %colback=white,
        colframe=white,
        colbacktitle=white,
        %coltitle=red,
        before={\vspace{0.1cm}}, 
        after={\vspace{0.3cm}},     
        attach boxed title to top left={xshift=-.20\linewidth, yshift= -.5 mm},
        minipage boxed title=.15\linewidth,
        left skip={0.09\linewidth},
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
        boxed title style={empty, size=minimal, bottom=1.5mm},
        overlay unbroken ={
            \draw (title.south west)--(title.south east);
            \draw ([xshift=3.5mm]frame.north west)|-%
                  (frame.south east)--(frame.north east);},
        overlay first={
            \draw (title.south west)--(title.south east); 
            \draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);
            \draw (frame.north east)--(frame.south east);},
        overlay middle={
            \draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);
            \draw (frame.north east)--(frame.south east);},
        overlay last={
            \draw ([xshift=3.5mm]frame.north west)|-%
                  (frame.south east)--(frame.north east);},
        },   
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEMONSTRATION
    SQ/.style={thmbox, coltitle=viol, colback=white!95!viol,  left skip={.12\linewidth},
        overlay unbroken ={
            \draw[viol][thick] (title.south west)--(title.south east);
            \draw[viol][thick] ([xshift=3.5mm]frame.north west)|-([xshift=15mm]frame.south west);
            \node[anchor=east] at (frame.south east) {$\square$};},
        overlay first={
            \draw[viol][thick] (title.south west)--(title.south east); 
            \draw[viol][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        overlay middle={
            \draw[viol][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        overlay last={
            \draw[viol][thick] ([xshift=3.5mm]frame.north west)|-([xshift=3.5mm]frame.south west);
            \node[anchor=east] at (frame.south east) {$\square$};},
    }
}

\newtcbtheorem[auto counter, number within=section]{demo}{Démonstration}{thmbox,SQ}{theo}

\begin{document}

hi !


\begin{demo}{}{}
OH!
\end{demo}

\end{document}

在此处输入图片描述

此外,我还有一个次要问题:我怎样才能稍微移动一下正方形(出现在 pdf 文档中)?我希望它位于框内,而不是像现在这样一半在框外。

答案1

你搞砸了一些东西,因为你在样式thmbox中使用了样式SQ,但它们具有相同的选项但具有不同的值,然后,你再次\newtcbtheorem使用它们两者进行了定义。

我把它们分开,即使为了方便,你也可以创建一个带有选项的样式,相同对于两种风格,然后将其用于thmboxSQ,只添加选项不同对他们每个人来说。

对于文本末尾的方形符号,我使用了\qedforasmthm和此选项:after upper={\hfill$\qed$}

我没有改变规则设置(但对我来说它也显得有点混乱),因为我仍然不明白你想要的最终外观是什么。

\documentclass[10pt,a4paper,twoside,openright]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{mwe}% <-- for testing purpose only, delete it

\usepackage[left=2.5cm,right=2.5cm,top=4cm,bottom=4cm]{geometry}%réglages des marges du document selon vos préférences ou celles de votre établissemant
\setlength{\headheight}{15pt}% hauteur de l'entête

\usepackage{amsmath,amsfonts,amssymb, amsthm}%amsthm added

\usepackage{fancyhdr}%pour les entêtes et pieds de pages
\usepackage[most]{tcolorbox}
\usepackage[english,french]{babel}%pour un document en français

\definecolor{viol}{RGB}{134,0,175}



\tcbset{
    thmbox/.style={
        enhanced,
        breakable,
        sharp corners=all,
        fonttitle=\bfseries\normalsize,
        fontupper=\normalsize\itshape,
        top=0mm,
        bottom=0mm,
        right=0mm,
        %colback=white,
        colframe=white,
        colbacktitle=white,
        %coltitle=red,
        before={\vspace{0.1cm}}, 
        after={\vspace{0.3cm}},     
        attach boxed title to top left={xshift=-.20\linewidth, yshift= -.5 mm},
        minipage boxed title=.15\linewidth,
        left skip={0.09\linewidth},
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
        boxed title style={empty, size=minimal, bottom=1.5mm},
        overlay unbroken ={
            \draw (title.south west)--(title.south east);
            \draw ([xshift=3.5mm]frame.north west)|-%
            (frame.south east)--(frame.north east);},
        overlay first={
            \draw (title.south west)--(title.south east); 
            \draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);
            \draw (frame.north east)--(frame.south east);},
        overlay middle={
            \draw ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);
            \draw (frame.north east)--(frame.south east);},
        overlay last={
            \draw ([xshift=3.5mm]frame.north west)|-%
            (frame.south east)--(frame.north east);},
    },   
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEMONSTRATION
    SQ/.style={%thmbox,
        enhanced,
        breakable,
        sharp corners=all,
        fonttitle=\bfseries\normalsize,
        fontupper=\normalsize\itshape,
        colframe=white,
        colback=white!95!viol, 
        colbacktitle=white!95!viol,
        coltitle=viol, 
        before={\vspace{0.1cm}}, 
        after={\vspace{0.3cm}},      
        attach boxed title to top left={xshift=-.25\linewidth%, yshift= -.5 mm
        },
        minipage boxed title=.23\linewidth,
        after upper={\hfill$\qed$},
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
        %boxed title style={left=0mm, boxrule=0pt, boxsep=0pt},
        left skip={.25\linewidth},
        overlay unbroken ={
            \draw[viol][thick] (title.south west)--(title.south east);
            \draw[viol][thick] ([xshift=3.5mm]frame.north west)|-([xshift=15mm]frame.south west);},
        overlay first={
            \draw[viol][thick] (title.south west)--(title.south east); 
            \draw[viol][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        overlay middle={
            \draw[viol][thick] ([xshift=3.5mm]frame.north west)--([xshift=3.5mm]frame.south west);},
        overlay last={
            \draw[viol][thick] ([xshift=3.5mm]frame.north west)|-([xshift=3.5mm]frame.south west);},
    }
}

\newtcbtheorem[auto counter, 
    number within=section]{demo}{Démonstration}{SQ}{theo}

\begin{document}
    hi !
    \blindtext% <-- for testing purpose only, delete it
    \begin{demo}{}{}
        OH!
    \end{demo}
    \blindtext% <-- for testing purpose only, delete it 
\end{document}

在此处输入图片描述

相关内容