實作提供所需佈局的樣式

實作提供所需佈局的樣式

我想知道是否有一個套件或方法可以完全實現下圖中的那種盒子。

提前致謝 !

在此輸入影像描述

答案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即文本,尚未完成,可能有一些專家可能會給出答案,同時我也在嘗試...

相關內容