尝试制作帝国风格的边缘盒子

尝试制作帝国风格的边缘盒子

我是 LaTeX 的新手,我正在尝试使用它来创建这个,但无法完全弄清楚。

在此处输入图片描述

重点,标题栏。可以垂直扩展。右边缘变成倒角。应水平扩展到列宽。垂直扩展以适合内容。

我当前使用的方法是tcolorbox,并TikZ产生以下效果:

在此处输入图片描述

这就是我的代码

\newcommand{\ranked}
{
    \begin{tikzpicture}
    \draw[white, sharp corners] (0.4em,0) -- (0,0.4em) -- (0.4em,0.8em);
    \fill[white, sharp corners] (0.55em, 0) -- (0.15em, 0.4em) -- (0.55em, 0.8em) -- (0.95em, 0.4em);
    \end{tikzpicture}
}
\newcommand{\rankedTalentBox}[3][color-active]
{
  \begin{tcolorbox}[colback=white,colframe=#1,title=#2\hspace*{0pt}\hfill \ranked]
  #3
  \end{tcolorbox}
}

有没有更好的方法?

答案1

€dit:更简单。

在此处输入图片描述

% Box with Pins  - v2.0 =====
\documentclass{book}
\usepackage[showframe=false]{geometry}
%\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{calc}
\pgfkeys{/tikz/savevalue/.code 2 args={\global\edef#1{#2}}}

% Values 1/2 ===============
\pgfmathsetlengthmacro\frule{1.75pt}
\pgfmathsetlengthmacro\BoxSep{2.5pt}
\pgfmathsetlengthmacro\pin{2*\frule}

\newtcolorbox{mybox}[3][]{      %show bounding box,
% Values 2/2 ===============
width=4.25cm,
colframe=gray, 
colback=white,
colbacktitle=purple,   
% =====================
boxrule=\frule, 
boxsep=\BoxSep, % additional value
top=0pt, left=\BoxSep, right=\BoxSep, 
bottom=\BoxSep+\BoxSep, % some more space for bottom title
enhanced, % allows TikZ etc. 
fontupper=\sffamily,
% Top Title  =======
title=#2, % Title Text
flushleft title,
fonttitle=\color{white}\sffamily\bfseries,
attach boxed title to top={
xshift=0pt,
yshift*=-\BoxSep-\tcboxedtitleheight,
},
boxed title style={    
frame empty, sharp corners,
left=0pt,
boxrule=0pt, 
opacityback=0, % no default fill of title
},     
underlay boxed title={ % manuell styled fill of title: 
\pgfmathsetlengthmacro\s{\tcboxedtitleheight/(2*cos(45))}
\pgfmathsetlengthmacro\h{\s*sin(45)}
\path[fill=tcbcolbacktitle]  (title.north west) rectangle  ([xshift=-\h]title.south east) coordinate(Y1);
\path[fill=tcbcolbacktitle, draw=none] (Y1) -- ++(45:\s) coordinate(Y2) -- ++(135:\s) --cycle;
\node[draw=none, diamond, fill=white, inner sep=0.4*\h] at ([xshift=-\h-1pt]Y2){};
},
% Pin Box  =======
arc is angular,
arc=5pt,
sharp corners=northwest,
finish={ % Pins =======
\path[draw=tcbcolframe, line width=0.75*\pin]  (frame.north) -- +(0,\pin);
\path[draw=tcbcolframe, line width=0.75*\pin]  (frame.south) -- +(0,-\pin);
\path[draw=tcbcolframe, line width=0.75*\pin]  ($(frame.south west)!0.8!(frame.north west)$) -- +(-\pin,0);
% Bottom Title =======
\node[fill=tcbcolbacktitle, draw=none, font=\color{white}\sffamily\footnotesize, outer sep=0pt, 
anchor=center, inner sep=1pt, yshift=0.5*\frule] at ($(frame.south)!0.45!(frame.south east)$) (btitle) {#3}; % Bottom Title Text
\path let \p1=($(btitle.north east)-(btitle.south east)$) in 
\pgfextra{  \pgfmathsetlengthmacro{\H}{sin(45)*veclen(\x1,\y1)}   }
[savevalue={\bh}{\H}];         
\path[fill=tcbcolbacktitle, draw=none]  (btitle.north east) -- +(-45:\bh) -- (btitle.south east) --cycle;
\path[fill=tcbcolbacktitle, draw=none]  (btitle.north west) -- +(225:\bh) -- (btitle.south west)  --cycle;
},
left skip=\pin, #1
}

\begin{document}
\begin{mybox}[]{The Top Title}{Cost 10\$}
Once per round, draw or holster a weapon or item as an incidental.
\end{mybox}
\end{document}

答案2

哦哦。@cis 刚刚打败了我!

只要有时间和耐心,你几乎可以做任何事情tcolorbox

\documentclass{article}

\usepackage[sfdefault,condensed]{roboto}
\usepackage[most]{tcolorbox}

\tcbset{active/.style={colbacktitle=red!50!black}}

\newtcolorbox{rankedtalentbox}[3][]{%
  enhanced,
  colback=white,
  colframe=black!50,
  title filled=false,
  titlerule=0pt,
  fonttitle=\bfseries,
  arc is angular,
  arc=6pt,
  sharp corners=northwest,
  text width=3.8cm,
  boxrule=1.5pt,
  left=3pt,
  right=3pt,
  top=3pt,
  bottom=9pt,
  boxsep=1.5pt,
  halign=flush left,
  attach boxed title to top left={
    xshift=3pt,
    yshift*=-3pt-\tcboxedtitleheight},
  boxed title style={
    interior code={},
    frame empty,
    left=0pt,
    boxrule=0pt,
    sharp corners},
  underlay boxed title={
    \path[tcb fill title] 
      (title.north west) --
      ([xshift=-3.5pt-0.5*\tcboxedtitleheight,yshift=-3pt]frame.north east) --
      ([xshift=-3.5pt,yshift=-3pt-0.5*\tcboxedtitleheight]frame.north east) --
      ([xshift=-3.5pt-0.5*\tcboxedtitleheight,yshift=-3pt-\tcboxedtitleheight]frame.north east) --
      (title.south west) -- cycle;
      \path[fill=tcbcoltitle]
      ([xshift=-4pt-0.5*\tcboxedtitleheight,yshift=-4.5pt]frame.north east) --
      ([xshift=-5.5pt,yshift=-3pt-0.5*\tcboxedtitleheight]frame.north east) --
      ([xshift=-4pt-0.5*\tcboxedtitleheight,yshift=-1.5pt-\tcboxedtitleheight]frame.north east) --
      ([xshift=-2.5pt-\tcboxedtitleheight,yshift=-3pt-0.5*\tcboxedtitleheight]frame.north east) --
      cycle;
      \path[draw=tcbcolframe,line width=1.5pt] (frame.north) -- ++(0,3pt);
      \path[draw=tcbcolframe,line width=1.5pt] (frame.south) -- ++(0,-3pt);
      \path[draw=tcbcolframe,line width=1.5pt] ([xshift=-3pt]title.west) -- ++(-3pt,0);
      \path[tcb fill title]
        ([xshift=-7.5pt,yshift=0.75pt]frame.south east) -- ++(135:4pt) --
        ++(-1.5cm,0) -- ++(-135:4pt) -- ++(-45:4pt) -- ++(1.5cm,0) -- cycle
        [insert path={node[font=\tiny,text=tcbcoltitle]
          at (current path bounding box.center) {COST #3}}];
  },
  active,
  title=#2,
  #1
}

\begin{document}

\begin{rankedtalentbox}{QUICK DRAW}{10}
  Once per round draw or holster a weapon or item as an incidental.
\end{rankedtalentbox}

\end{document}

输出

相关内容