自定义盒装标题框环境

自定义盒装标题框环境

我正在尝试从 Peter Atkins 物理化学书中获取盒装标题框环境,如下所示, 截图2

在阅读了软件包的文档之后tcolorbox,我发现在软件包手册的“ tcolorbox10.2.3 盒式标题框选项”一节中有一个自定义的 tcolorbox 样式。

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\usepackage{varwidth}
\newtcolorbox{mybox}[2][]{enhanced,
before skip=2mm,after skip=2mm, colback=black!5,colframe=black!50,boxrule=0.2mm,
attach boxed title to top left={xshift=1cm,yshift*=1mm-\tcboxedtitleheight}, varwidth boxed title*=-3cm,
boxed title style={frame code={
            \path[fill=tcbcolback!30!black]
              ([yshift=-1mm,xshift=-1mm]frame.north west)
                arc[start angle=0,end angle=180,radius=1mm]
              ([yshift=-1mm,xshift=1mm]frame.north east)
                arc[start angle=180,end angle=0,radius=1mm];
            \path[left color=tcbcolback!60!black,right color=tcbcolback!60!black,
              middle color=tcbcolback!80!black]
              ([xshift=-2mm]frame.north west) -- ([xshift=2mm]frame.north east)
              [rounded corners=1mm]-- ([xshift=1mm,yshift=-1mm]frame.north east)
              -- (frame.south east) -- (frame.south west)
              -- ([xshift=-1mm,yshift=-1mm]frame.north west)
              [sharp corners]-- cycle;
            },interior engine=empty,
          },
          fonttitle=\bfseries,
          title={#2},#1}

\begin{document}

        \begin{mybox}[colbacktitle=green]{Lorem Ipsum}
        \lipsum[1]
        \end{mybox}

\end{document}

它看起来与 Atkins 有点相似,但我无法实现 Atkins 盒子风格 截屏

任何帮助都将受到赞赏。

编辑:经过一些努力,我得到了这个结果截图3 使用tcolorbox包,

\documentclass{article}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\usepackage{xcolor}


\definecolor{mygreen}{HTML}{07a56d}

\newtcbtheorem{briefillus}{Brief Illustration}{
  enhanced,
  sharp corners,
  attach boxed title to top left={
    xshift=0pt, 
    yshift=-\tcboxedtitleheight, 
    yshifttext=-\tcboxedtitleheight/2
  },
  colback=white,
  colframe=mygreen,
  fonttitle=\bfseries,
  coltitle=white,
  boxed title style={
    rounded corners,
    arc=2pt,
    size=small,
    colback=mygreen,
    colframe=mygreen,
  },
  leftrule=0pt, 
  rightrule=0pt, 
}{thm}

\begin{document}

\begin{briefillus}{Lorem Ipsum}{}
  \lipsum[1]
\end{briefillus}

\end{document}

但我仍然无法实现下侧有圆角的标题框的倒等腰梯形。

答案1

这是一个可行的解决方案。您只需frame code为标题框定义一个:

\documentclass{article}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\usepackage{xcolor}


\definecolor{mygreen}{HTML}{07a56d}

\newtcbtheorem{briefillus}{Brief Illustration}{
  enhanced,
  sharp corners,
  attach boxed title to top left={
    xshift=5pt, 
    yshift*=-\tcboxedtitleheight-0.5mm, 
%    yshifttext=-\tcboxedtitleheight/2
  },
  colback=white,
  colframe=mygreen,
  fonttitle=\bfseries,
  coltitle=white,
  boxed title style={
     frame code={\fill[tcbcolback]([xshift=-5pt]frame.north west) [rounded corners=2pt]--(frame.south west)--(frame.south east)[sharp corners]--([xshift=5pt]frame.north east)--cycle;},
%    rounded corners,
%    arc=2pt,
    size=small,
    colback=mygreen,
    colframe=mygreen,
  },
  leftrule=0pt, 
  rightrule=0pt, 
}{thm}

\begin{document}

\begin{briefillus}{Lorem Ipsum}{}
  \lipsum[1]
\end{briefillus}

\end{document}

在此处输入图片描述

答案2

以下是一些遵循相同模式的替代想法:

  • 放 2 条水平线
  • 放一些(短)tikz代码或fboxraised
  • 改变:hrule-box 与 box-hrule
  • 进行一些垂直调整(这里:简单\bigskip

如您所见,调整要筹集的金额至关重要。为了简单起见,我使用了预定义的\baselineskip。我还lipsum用一些较短的文本替换了包,以便将其全部放在一页上以供截图。

tikz使用的优点fbox是:

  • tikz您可以在环境中轻松更改线条、填充和字体的颜色
  • 你可以画任何你喜欢的形状(这里我只使用默认的矩形)

外表:

  • 定义一个简单的 \newcommand,它执行你最喜欢的解决方案,允许像这样的调用\yourBox{Brief illustration 5A.3}

结果

\documentclass[10pt,a4paper]{article}
\usepackage{tikz}

\newcommand\blindtext[0]{Lorem ipsum dolor sit amet consectetuer laoreet nibh tristique wisi sem. Augue Suspendisse tortor leo hendrerit vel Vestibulum lorem Curabitur elit sapien. Euismod quis In nunc tincidunt sed purus nibh sed dolor Vivamus. Adipiscing.}

% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\begin{document}

\section{Alternative 1}
Puts some tikz-code above a hrule.

\raisebox{-\baselineskip}{
    \tikz{
        \node[draw=gray!20,fill=gray!10] {Brief illustration 4B.3};
    }
}
\hrule
\bigskip

\blindtext

\bigskip
\hrule

\bigskip

\section{Alternative 2}
Puts some tikz-code below a hrule.\bigskip

\hrule
\raisebox{-\baselineskip}{
    \tikz{
        \node[draw=gray!20,fill=gray!10] {Brief illustration 4B.3};
    }
}
\bigskip

\blindtext

\bigskip
\hrule


\section{Alternative 1b}

Same idea, just with fbox.\bigskip

\raisebox{-\baselineskip}{
    \fbox{Brief illustration 4B.3}
}
\hrule
\bigskip

\blindtext

\bigskip
\hrule

\section{Alternative 2b}

Same idea, just with fbox.

\hrule
\raisebox{-\baselineskip}{
    \fbox{Brief illustration 4B.3}
}
\bigskip

\blindtext

\bigskip
\hrule

\end{document}

相关内容