实现所需布局的样式

实现所需布局的样式

我想知道是否存在一个包或方法可以实现下图中那种盒子。

提前致谢 !

在此处输入图片描述

答案1

欢迎来到 TeX.SE!

实现所需布局的样式

正如评论中所说,这种盒子样式可以通过强大的功能获得tcolorbox。我分两步进行:

  1. 定义一种my box可以应用于任何事物tcolorbox并实现您想要的设计的样式。

  2. 用于定义一个使用该样式\newtcolorbox的环境。myboxmy box

当然,如果您愿意,您可以将该my box样式应用于其他tcolorboxes — — 这就是分离这两个操作的全部意义所在。

\documentclass{article}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\usepackage{lipsum}

\definecolor{boxTitle}{HTML}{fff79a}
\definecolor{boxBackground}{HTML}{fffce0}
\definecolor{boxFrame}{HTML}{f1e2b8}

\tcbset{my box/.style={
    enhanced, fonttitle=\bfseries,
    colback=boxBackground, colframe=boxFrame,
    coltitle=black, colbacktitle=boxTitle,
    attach boxed title to top left={xshift=0.3cm,
                                    yshift*=-\tcboxedtitleheight/2},
    boxed title style={
      before upper=\hspace*{0.5cm}, % reserve space for the image
      overlay={
       \node at ([xshift=0.5cm]frame.west)
         {\includegraphics[scale=0.65]{bc-dodecaedre}};
      }
    }
  }
}

\newtcolorbox{mybox}[1][]{my box, #1}

\begin{document}

\begin{mybox}[title={This is a great title, with a comma}]
\lipsum[1]
\end{mybox}

\end{document}

截屏

注意:bc-dodecaedre图形来自bclogo包,因此您必须安装它才能获得图形(.mps文件,使用 MetaPost 获得)。

自动编号的盒子

根据您在评论中的要求,以下是使用我们在上一节中开发的布局创建独立编号的一系列框的几种方法(由于样式的原因,重复使用它特别容易my box)。基本上有两种方法:

  • auto counter在第一个可选参数中使用\newtcolorbox(请参见下面示例中定义的两个盒子系列:A 类型的盒子和 B 类型的盒子);

  • 使用theoremstcolorbox(参见theorem示例中定义的环境)。

\documentclass{article}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{tcolorbox}
\tcbuselibrary{skins, theorems}
\usepackage{nameref}            % only needed if you use \nameref

\definecolor{boxTitle}{HTML}{fff79a}
\definecolor{boxBackground}{HTML}{fffce0}
\definecolor{boxFrame}{HTML}{f1e2b8}

\tcbset{my box/.style={
    enhanced, fonttitle=\bfseries,
    colback=boxBackground, colframe=boxFrame,
    coltitle=black, colbacktitle=boxTitle,
    attach boxed title to top left={xshift=0.3cm,
                                    yshift*=-\tcboxedtitleheight/2},
    boxed title style={
      before upper=\hspace*{0.5cm}, % reserve space for the image
      overlay={
       \node at ([xshift=0.5cm]frame.west)
         {\includegraphics[scale=0.65]{bc-dodecaedre}};
      }
    }
  }
}

\newtcolorbox[auto counter]{countedboxa}[2][]{%
  my box, title={Counted box of type A~(\thetcbcounter): #2}, #1}
\newtcolorbox[auto counter, number within=section]{countedboxb}[2][]{%
  my box, title={Counted box of type B.~(\thetcbcounter): #2}, #1}

\newtcbtheorem[number within=section]{theorem}{Theorem}{my box}{th}

\begin{document}

\section{First section}
\label{sec:first}

\begin{countedboxa}[label={first box of type A}]{Some title}
  My number is~\thetcbcounter.
\end{countedboxa}

\begin{countedboxb}[label={first box of type B}]{Other title}
  Note the different numbering style due to our use of
  \verb|number within=section| for boxes of type~B. My number is~\thetcbcounter.
\end{countedboxb}

\begin{countedboxa}[label={second box of type A}]{Another title}
  My number is~\thetcbcounter. The third box of type A is number~\ref{third
    box of type A} on page~\pageref{third box of type A}.
\end{countedboxa}

\begin{countedboxb}[label={second box of type B}]{The title}
   My number is~\thetcbcounter. The third box of type B is number~\ref{third
    box of type B} on page~\pageref{third box of type B}.
\end{countedboxb}

\begin{theorem}{Compacity of Foo spaces}{foo}
% Text (mostly) from the tcolorbox manual
This is the text of the theorem. The counter is automatically assigned and,
in this example, prefixed with the section number due to our use of
\verb|number within=section|. This theorem is numbered \ref{th:foo}, found
on page~\pageref{th:foo} and titled ``\nameref{th:foo}.''
\end{theorem}

An immediate but very convenient consequence of this result is
theorem~\ref{th:bar}.

\begin{theorem}{Bar}{bar}
Trivial consequence of theorem~\ref{th:foo}.
\end{theorem}

\section{Second section}

\begin{countedboxa}[label={third box of type A}]{Some title}
  See boxes~\ref{first box of type A} and \ref{second box of type A} in
  section~\ref{sec:first}.
\end{countedboxa}

\begin{countedboxb}[label={third box of type B}]{Title of the box}
  See boxes~\ref{first box of type B} and \ref{second box of type B} in
  section~\ref{sec:first}.
\end{countedboxb}

\begin{theorem}{Quux}{quux}
This is a very important result.
\end{theorem}

\end{document}

第 1 页:

第 1 页


第 2 页顶部:

第 2 页顶部

答案2

以下是针对第 1 点的答案,即shaded box with round corner

\documentclass{book}
\usepackage[tikz]{mdframed}
\tikzset{titregris/.style =
{draw=black, thick, fill=yellow, %
text=black, rectangle, rounded corners, right,minimum height=.7cm}}

\makeatletter
\newcounter{theo}[section]
\newenvironment{theo}[1][]{%
\stepcounter{theo}%
\ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt,linecolor=black]
\node[titregris,anchor=east,rectangle,fill=yellow!20]
{\strut Theorem~\thetheo};}}
}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[titregris,anchor=east,rectangle,fill=yellow!20]
{\strut Theorem~\thetheo:~#1};}}%
}%
\mdfsetup{innertopmargin=10pt,linecolor=yellow,roundcorner=5pt,backgroundcolor=yellow!10,%
linewidth=2pt,topline=true,
frametitleaboveskip=\dimexpr-\ht\strutbox\relax,}
\begin{mdframed}[]\relax%
}{\end{mdframed}}
\makeatother
\begin{document}

\begin{theo}[Inhomogeneous Linear]
This is my own box with a mandatory title
and options.

This is my own box with a mandatory title
and options following para.
\end{theo}

\end{document}

关于第 2 点,wavy vertical rule即文本,尚未完成,可能会有专家给出答案,同时我也在尝试......

相关内容