![tcolorbox 带框架标题的精美文本框 - 标题调整](https://linux22.com/image/344900/tcolorbox%20%E5%B8%A6%E6%A1%86%E6%9E%B6%E6%A0%87%E9%A2%98%E7%9A%84%E7%B2%BE%E7%BE%8E%E6%96%87%E6%9C%AC%E6%A1%86%20-%20%E6%A0%87%E9%A2%98%E8%B0%83%E6%95%B4.png)
我正在使用带标题的文本框,这是@Alenanno 在 灵感来自 Indesign 的精美盒子。
此标题设计为右对齐。有人可以将其改为左对齐吗?
\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage{amsmath,amssymb}% pour les maths
\usepackage{enumitem}
\usepackage[svgnames]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\tcbset{
lemmastyle/.style={enhanced, colback=white, colframe=blue!20, arc=0pt,
fonttitle=\bfseries, description color=Maroon,
colbacktitle=white, coltitle=DarkOliveGreen,
top=\tcboxedtitleheight,
boxed title style={arc=0pt},
attach boxed title to top left={yshift=-\tcboxedtitleheight/2,
xshift=4mm}%
},
}
\newtcbtheorem{myLemma}{Long text here without counter }{lemmastyle}{thm}
\usetikzlibrary{calc, fit}
\newcommand{\mybox}[4][8cm]{
\begin{figure}[!h]
\centering
\begin{tikzpicture}
\node[line width=0.5mm, rounded corners, text width=#1, draw=#2] (one) {\vspace{25pt}\\ #4};
\node[text=white,anchor=north east,align=center, minimum height=20pt] (two) at (one.north east) {#3};
\path[fill=#2]
(one.north west|-two.west) --
($(two.west)+(-1.5cm,0)$)
to[out=0,in=180] (two.south west) --
(two.south east) [rounded corners] --
(one.north east) --
(one.north west) [sharp corners] -- cycle;
\node[text=white,anchor=north east,align=center, minimum height=25pt, text height=2ex] (three) at (one.north east) {#3 \hspace*{.5mm}};
\end{tikzpicture}
\end{figure}
}
\usepackage{pifont}
\begin{document}
\mybox[6cm]{green!70!black}{Long Fancy Title}{
\begin{enumerate}
\item Show that
${\displaystyle D_2f(x,y) = \frac{\partial {}}{\partial{y}} \left ( \int_0^xg_1 (t,0) \ dt + \int_0^y g_2(x,s) \ ds \right)}$
\item prove that
${ \displaystyle \left(\forall x\in\mathbb{R} \right)\left(\forall y \in \mathbb{R} \right) x\neq y\, \text{and} \, x+y \neq 2 \implies x^{2}-2x \neq y^2-2y }$
\end{enumerate}
}
\begin{myLemma}{}{}
\begin{enumerate}
\item Show that
${\displaystyle D_2f(x,y) = \frac{\partial {}}{\partial{y}} \left ( \int_0^xg_1 (t,0) \ dt + \int_0^y g_2(x,s) \ ds \right)}$
\item prove that
${ \displaystyle \left(\forall x\in\mathbb{R} \right)\left(\forall y \in \mathbb{R} \right) x\neq y\, \text{and} \, x+y \neq 2 \implies x^{2}-2x \neq y^2-2y }$
\end{enumerate}
\end{myLemma}
\mybox[6cm]{blue!70!black}{Very Very Long Fancy Title}{Duis id dolor et ligula eleifend imperdiet. Mauris luctus, quam vitae viverra sagittis, dolor nibh imperdiet augue, eu venenatis eros augue et nisl. Vivamus nec fermentum est.}
Nullam libero augue, luctus et est vitae, fermentum aliquet libero. Maecenas dictum placerat eros, eu fermentum sem fermentum dapibus. Quisque non tellus nec magna feugiat luctus.
\end{document}
答案1
阿莱南诺mybox
用命令定义TiKZ
。可以使用tcolorbox
允许页面间可破坏的框来定义。
\documentclass[a4paper]{article}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\makeatletter
\newtcolorbox{mytcbox}[2][]{%
enhanced,
breakable,
colback=white,
colframe=blue!30!black,
attach boxed title to top left={yshift=-2pt}, title={#2},
boxed title size=standard,
boxrule=0pt,
boxed title style={%
sharp corners,
rounded corners=northwest,
colback=tcbcolframe,
boxrule=0pt},
sharp corners=north,
overlay unbroken={%
\path[fill=tcbcolback]
([xshift=-2pt]title.south east)
to[out=0, in=180] ([xshift=1.5cm]title.east)--
(title.east-|frame.east) |-
([xshift=-2pt]title.south east)--cycle;
\path[fill=tcbcolframe] (title.south east)
to[out=0, in=180] ([xshift=1.5cm]title.east)--
(title.east-|frame.east)
[rounded corners=\kvtcb@arc] |-
(title.north-|frame.north)
[sharp corners] -| (title.south east);
\draw[line width=.5mm, rounded corners=\kvtcb@arc,
tcbcolframe]
(title.north west) rectangle
(frame.south east);
},
overlay first={%
\path[fill=tcbcolback]
([xshift=-2pt]title.south east)
to[out=0, in=180] ([xshift=1.5cm]title.east)--
(title.east-|frame.east) |-
([xshift=-2pt]title.south east)--cycle;
\path[fill=tcbcolframe] (title.south east)
to[out=0, in=180] ([xshift=1.5cm]title.east)--
(title.east-|frame.east)
[rounded corners=\kvtcb@arc] |-
(title.north-|frame.north)
[sharp corners] -| (title.south east);
\draw[line width=.5mm, rounded corners=\kvtcb@arc,
tcbcolframe]
(frame.south west) |- (title.north) -|
(frame.south east);
},
overlay middle={%
\draw[line width=.5mm, tcbcolframe]
(frame.north west)--(frame.south west)
(frame.north east)--(frame.south east);
},
overlay last={%
\draw[line width=.5mm, rounded corners=\kvtcb@arc,
tcbcolframe]
(frame.north west) |- (frame.south) -|
(frame.north east);
},
#1
}
\makeatother
\begin{document}
\begin{mytcbox}{Long fancy title}
\lipsum[1-12]
\end{mytcbox}
\begin{mytcbox}[colframe=blue!70!black, colback=red!20, width=.75\linewidth]{Even Longer fancy title}
\lipsum[1]
\end{mytcbox}
\begin{mytcbox}[colback=white]{Title}
\lipsum[1]
\end{mytcbox}
\end{document}
笔记以前的代码已更新以兼容tcolorbox v4.20
。如果您使用的是以前的版本,请将颜色形式重命名tcbcol...
为旧形式 tcbcol@...
。
答案2
您需要重建\mybox
命令里面完成的路径:
\usetikzlibrary{calc, fit, backgrounds}
\usepackage{varwidth}
\newcommand{\mybox}[4][\textwidth-\pgfkeysvalueof{/pgf/inner xsep}-2mm]{%
\begin{figure}[!h]
\centering
\begin{tikzpicture}
\node[line width=0.5mm, inner ysep=10pt, text width=#1, outer sep=0] (text) {\begin{varwidth}{\textwidth}#4\end{varwidth}};
\node[text=white, above right, align=left] (title) at (text.north west) {#3};
\node[fit=(title) (text), line width=0.5mm, rounded corners, draw=#2, inner sep=0pt] (box){};
\begin{scope}[on background layer]
\fill[#2] (title.south west) -- (title.south east) to[out=0, in=180] ([xshift=1.5cm]title.east) -- (title.east-|box.north east) [rounded corners] -- (box.north east) -- (box.north west) [sharp corners] -- cycle;
\end{scope}
\end{tikzpicture}
\end{figure}
}
还用到了backgrounds
库,避免了白色节点的重复,以及fit
库+vardiwdth
包使得盒子更加灵活。