彩色框中的垂直对齐

彩色框中的垂直对齐

在下面的框中,我想将“示例 1”与“测试”垂直对齐。以下是代码:

\documentclass{article}
\usepackage[many]{tcolorbox}

\usetikzlibrary{calc}

\tcbset{mystyle/.style={
  breakable,
  enhanced,
  outer arc=0pt,
  arc=0pt,
  colframe=blue,
  colback=blue,
  attach boxed title to top left,
  boxed title style={
    colback=blue,
    outer arc=0pt,
    arc=0pt,
    top=2pt,
    bottom=2pt
    }
  }
}

\newtcolorbox[auto counter]{example}[1][]{
  mystyle,
  colback=white,
  rightrule=0pt,
  toprule=0pt,
  title={\bf Example \thetcbcounter},
  overlay unbroken and first={
      \path
        let
        \p1=(title.north east),
        \p2=(frame.north east)
        in
        node[anchor=west,color=blue,text width=\x2-\x1]
        at (title.east) {#1};
  }
}

\begin{document}

\begin{example}
Test
\end{example}

\end{document}

欢迎任何帮助。

答案1

这就是你要找的吗?

在此处输入图片描述

\documentclass{article}
\usepackage[many]{tcolorbox}

\tcbset{mystyle/.style={
  breakable,
  enhanced,
  arc=0pt, outer arc=0pt,
  colframe=blue, colback=white,
  left=4pt, right=4pt, top=2pt,
  attach boxed title to top left,
  boxed title style={colback=blue,
                     arc=0pt, outer arc=0pt,
                     left=4pt, right=4pt, top=2pt, bottom=2pt
                    } }
                        }% end of mystyle

\newtcolorbox[auto counter]{example}[1][]%
{
    mystyle,
    title={\textbf{Example \thetcbcounter}},
}

\usepackage{lipsum}

\begin{document}

\begin{example}
Test
% \lipsum[1-5]
\end{example}

\end{document}

或者当示例框分为两页时使用较长的文本(example框中的文本被视为由 生成的文本\lipsum[1-8]

在此处输入图片描述

相关内容