hohei’s diary

備忘録?

tcolorboxで作るフレームの紹介

はじめに

tcolorboxパッケージを用いて作成したフレームを紹介します。

自分がよく使うものも,まったく使わないものも入っています。 フレームは,一部分をどこかから拾ってきたものや,パッケージのマニュアルそのままのもの,イチから作ったもの,と色々です。

フレームたち

自分が色付きで使わないので,すべて白黒です。

\begin{mybox}
 mybox\\
 mybox\\
 mybox
\end{mybox}

\begin{mybox2}{あああ}
 mybox2\\
 mybox2\\
 mybox2
\end{mybox2}

\begin{mybox3}{あああ}
 mybox3\\
 mybox3\\
 mybox3
\end{mybox3}

\begin{mybox4}{あああ}
 mybox4\\
 mybox4\\
 mybox4
\end{mybox4}

\begin{mybox5}{あああ}
 mybox5\\
 mybox5\\
 mybox5
\end{mybox5}

\begin{mybox7}
 mybox7\\
 mybox7\\
 mybox7
\end{mybox7}

\begin{mybox8}{ああああ}
 mybox8\\
 mybox8\\
 mybox8\\
 mybox8
\end{mybox8}

\begin{marker}
marker\\
marker\\
marker
\end{marker}

\begin{mycross}
mycross\\
mycross\\
mycross
\end{mycross}

\begin{frog}
frog\\
frog\\
frog
\end{frog}

\begin{heart}
heart\\
heart\\
heart
\end{heart}

\begin{edgeball}
 edgeball\\
 edgeball\\
 edgeball
\end{edgeball}

\begin{leaf}
leaf\\
leaf\\
leaf\\
leaf
\end{leaf}

\begin{flower}
flower\\
flower\\
flower\\
flower
\end{flower}

プリアンブルでの記述

長いので,別ファイルにして管理するのがいいと思います。

% ビックリ枠
% マニュアルの枠
\newtcolorbox{marker}[1][]{%
  enhanced,before skip=2mm,after skip=3mm,
  boxrule=0.4pt,left=5mm,right=2mm,top=1mm,bottom=1mm,
  colback=white!50,colframe=white!20!black,
  sharp corners,rounded corners=southeast,arc is angular,arc=3mm,
  underlay={%
    \path[fill=black] ([yshift=3mm]interior.south east)--++(-0.4,-0.1)--++(0.1,-0.2);
    \path[draw=black,shorten <=-0.05mm,shorten >=-0.05mm] ([yshift=3mm]interior.south east)--++(-0.4,-0.1)--++(0.1,-0.2);
    \path[fill=black,draw=none] (interior.south west) rectangle node[white]{\Huge\bfseries !} ([xshift=4mm]interior.north west);
    },
  drop fuzzy shadow,#1}

% バッテン
\newtcolorbox{mycross}{enhanced,colback=white,colframe=white,left=4em,right=4em,
  interior code={
    \path[dotted,draw=black,line width=0.5mm]%line cap=round
     ([xshift=3mm,yshift=-3mm]interior.north west)
     --([xshift=-3mm,yshift=3mm]interior.south east)
     ([xshift=3mm,yshift=3mm]interior.south west)
     --([xshift=-3mm,yshift=-3mm]interior.north east);}}

%% カエル
\newtcolorbox{frog}{enhanced,colback=white,colframe=black!65!black,boxrule=1mm,enlarge top by=5.5mm,overlay={\foreach \x in {2cm,3.5cm}{
\begin{scope}[shift={([xshift=\x]frame.north west)}]
  \path[draw=black,fill=white,line width=1mm] (0,0) arc (0:180:5mm);
  \path[fill=black] (-0.2,0) arc (0:180:1mm);
\end{scope}}}}

% 2つのフレームで使用
\newcommand{\edgeleaf}{%
    \foreach ~ in {0,90,180,270}
      \draw[fill=white,rotate=~] (0,0) .. controls +(-.5,0) and +(-.1,-.1) .. (-.5,.5) .. controls +(.1,.1) and +(0,.5) .. (0,0);
    \foreach ~ in {1,-1}
      \draw[fill=white,yscale=~,rotate=45-~*45]
        (0,0) .. controls +(0,.55) and +(-.1,-.1) .. (-.3,.7) .. controls +(.1,.1) and +(0,.55) .. (0,0)
        (0,0) .. controls +(0,.8) and +(-.4,.1) .. (0,1) .. controls +(.3,-.1) and +(0,.7) .. (0,0);
    \draw[black]
      (0,0) to[relative,in=190,out=0] (0,1)
      (0,0) to[relative,in=170,out=0] (-1,0);
    \draw[black,scale=.5] (0,0) .. controls +(-.5,0) and +(-.1,-.1) .. (-.5,.5) .. controls +(.1,.1) and +(0,.5) .. (0,0);
}

%% leaf
\newtcolorbox{leaf}{enhanced,colback=white,colframe=black,boxrule=0.2mm,enlarge top by=5.5mm,enlarge bottom by=5.0mm,overlay={
% enlarge top by でフレーム前後の余白の調節
\begin{scope}[scale=0.8,rotate=180,shift=(frame.north west)]
\edgeleaf
\end{scope}
%
\begin{scope}[scale=0.8,rotate=-90,shift=(frame.south west)]
\edgeleaf
\end{scope}
%
\begin{scope}[scale=0.8,rotate=0,shift=(frame.south east)]
\edgeleaf
\end{scope}
%
\begin{scope}[scale=0.8,rotate=90,shift=(frame.north east)]
\edgeleaf
\end{scope}
}}

% flower
\newtcolorbox{flower}{enhanced,colback=white,colframe=black,boxrule=0.6mm,enlarge top by=5.5mm,enlarge bottom by=2.0mm,top=15pt,bottom=15pt,
overlay={
% enlarge top by でフレーム前後の余白の調節
%
% 小さい花たち
\foreach \x in {-2.2\linewidth,-2.0\linewidth,...,2.2\linewidth}{%
\begin{scope}[scale=0.2,rotate=0,shift={([xshift=\x,yshift=-1.5mm]frame.north)}]% xshift,yshift: 花の場所
  \foreach \a in {0,60,...,350}{%
    \draw[fill=white, draw=black,rotate=\a+30 + \x/10]% <- \x/10 で回転させる
      (0.8,0) ellipse(0.6 and 0.4);
    }
\end{scope}
}
\foreach \x in {-2.2\linewidth,-2.0\linewidth,...,2.2\linewidth}{%
\begin{scope}[scale=0.2,rotate=0,shift={([xshift=\x,yshift=1.5mm]frame.south)}]
  \foreach \a in {0,60,...,350}{%
    \draw[fill=white, draw=black,rotate=\a+30 + \x/10]% <- \x/10 で回転させる
      (0.8,0) ellipse(0.6 and 0.4);
    }
\end{scope}
}
\begin{scope}[scale=0.8,rotate=180,shift=(frame.north west)]
  \edgeleaf
\end{scope}
%
\begin{scope}[scale=0.8,rotate=-90,shift=(frame.south west)]
  \edgeleaf
\end{scope}
%
\begin{scope}[scale=0.8,rotate=0,shift=(frame.south east)]
  \edgeleaf
\end{scope}
%
\begin{scope}[scale=0.8,rotate=90,shift=(frame.north east)]
  \edgeleaf
\end{scope}
}}

% ハート
\newtcolorbox{heart}{enhanced,
colback=white,frame hidden,
enlarge top by=5.5mm,enlarge bottom by=5.0mm,
borderline north={0.5mm}{0mm}{black,dash pattern=on 0.1pt off 4pt,line width=1.5pt,line cap=round},
borderline south={0.5mm}{0mm}{black,dash pattern=on 0.1pt off 4pt,line width=1.5pt,line cap=round},
overlay={%
% enlarge top by でフレーム前後の余白の調節
\newcommand{\edgeheart}{%
\begin{scope}[xscale=1,yscale=1]% heartの形の調節
  \draw[black,fill=black] (0,0) .. controls (0,0.6) and (-1.5,1.00) .. (-1.5,2)  arc (180:0:0.75)  -- cycle;
  \draw[black,fill=black] (0,0) .. controls (0,0.6) and ( 1.5,1.00) .. ( 1.5,2)  arc (0:180:0.75) -- cycle;
\end{scope}
}
\begin{scope}[scale=0.2,shift={([xshift=10mm,yshift=-10mm]frame.north west)},rotate=45]
  \edgeheart
\end{scope}
%
\begin{scope}[scale=0.2,shift={([xshift=10mm,yshift=10mm]frame.south west)},rotate=135]
  \edgeheart
\end{scope}
%
\begin{scope}[scale=0.2,shift={([xshift=-10mm,yshift=10mm]frame.south east)},rotate=-135]
  \edgeheart
\end{scope}
%
\begin{scope}[scale=0.2,shift={([xshift=-10mm,yshift=-10mm]frame.north east)},rotate=-45]
  \edgeheart
\end{scope}
}}

% 角にボール
\newtcolorbox{edgeball}{%
  breakable,enhanced,colback=white,colframe=black,boxrule=1.0pt,leftupper=0.5em,rightupper=0.5em,enlarge top by=2.5mm,enlarge bottom by=2.0mm,
  frame code={%
  \foreach \n in {north east,north west,south east,south west}
  {\path [fill=black] (interior.\n) circle (3mm); }; }}

% フツーの枠
\newtcolorbox{mybox}{%
  breakable,enhanced,colback=white,colframe=black,left=0.5em,right=0.5em,boxrule=1.0pt}

\newtcolorbox{mybox2}[1]{%
  breakable,enhanced,colback=white,colframe=black,fonttitle=\bfseries,title=#1,leftupper=0.5em,rightupper=0.5em,boxrule=1.0pt}

\newtcolorbox{mybox3}[1]{%
  breakable,enhanced,colbacktitle=white,coltitle=black,colback=white,colframe=black,sharp corners,fonttitle=\bfseries,title=#1,leftupper=0.5em,rightupper=0.5em,boxrule=1.0pt}

\newtcolorbox{mybox4}[1]{%
  breakable,enhanced,colback=white,colframe=black,fonttitle=\bfseries,colbacktitle=black,attach boxed title to top center={yshift*=-2mm},title=#1,boxrule=1.0pt}

% enlarge top by: 箱の頭と記述の距離
\newtcolorbox{mybox5}[1]{%
  breakable,enhanced,enlarge top by=0mm,colback=white,colframe=black,fonttitle=\bfseries,colbacktitle=black,attach boxed title to top left={xshift=3mm,yshift*=-\tcboxedtitleheight/2},title=#1,boxrule=1.0pt}

%% manual p.152
\newtcolorbox{mybox7}{%
  breakable,enhanced,arc=3mm,colback=white,frame hidden,left=0.5em,right=0.5em,borderline={1.0pt}{0pt}{black,dotted}
}

\newtcolorbox{mybox8}[1]{%
  enhanced,title=#1,
  fonttitle=\sffamily\bfseries,top=2pt,bottom=2pt,boxrule=6pt,arc=0pt,
  colframe=white,coltitle=white,colback=white,
  attach boxed title to top left={yshift=-2pt,xshift=-1pt},
  borderline north={0.5mm}{0mm}{%
    black,dash pattern=on 0.1pt off 4pt,line width=2pt,line cap=round},
  borderline south={0.5mm}{0mm}{%
    black,dash pattern=on 0.1pt off 4pt,line width=2pt,line cap=round},
  boxed title style={
    colback=black,colframe=black,sharp corners,
    rounded corners=northeast,arc=3mm,boxrule=0pt}
}

コンパイル

コンパイルの例です。 www.overleaf.com