我正在尝试对齐主标题,使其从计数器框 [红色] 后开始并向框的右侧运行,但到目前为止它一直向左延伸。我做错了什么?提前感谢任何帮助。
梅威瑟:
\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}%erlaubt Umlaute
\usepackage{lmodern}
\usepackage[skins]{tcolorbox}
\newtcolorbox[auto counter, ]{mybox1}[3][]{
enhanced,
arc=.3mm,
boxrule=0.3pt,
fonttitle=\bfseries,
colback=white,
colframe=red!65!black,
enlarge top by=10mm,
subtitle style={ boxrule=0.2pt,
colback=blue!40!white},
overlay={%
\path[fill=blue!65,line width=.4mm] (frame.north west)--++(17mm,0)coordinate(n2)--++(0,8mm)--++(-20mm,0) arc (-90:90:-4mm)--cycle;
\node at ([shift={(5mm,4mm)}]frame.north west){\color{white}{
\textbf{\sffamily #2}}};
\path[fill=red!65!blue] ([xshift=.4mm]n2)--++(0,8mm)--++(7mm,0)--++(0,-8mm)--cycle;
\node at ([shift={(4mm,4mm)}]n2){\color{white}{\textbf{\sffamily \thetcbcounter}}};
\node at ([shift={(18mm,4mm)}]n2){
\itshape\textbf{\sffamily #3}};
},
#1
}
\newcounter{mycounter}
%----------------------------------------------------------------------------------------
%TCOLORBOXES
%----------------------------------------------------------------------------------------
\begin{document}
\begin{mybox1}[label=one]{sample}{Gebäudeheizlast nach DIN 12831 nach Temperatur}
This is a \textbf{tcolorbox}.\par
a lot of text here ... This is Example \ref{one}
\tcbsubtitle{\textbf{ Formeln}}
some text
\end{mybox1}
\end{document}
答案1
最快的解决方案是选择正确的标题定位锚点(默认为中心)和所需的。这就是以下代码中xshift
所做的。mybox1
更复杂的解决方案是将填充路径替换为带有positioning
库的三个节点,这些节点是叠加节点。左侧节点来自rounded rectangle
库symbols.misc
。最后,使用text
和font
选项调整节点内容的方面。这就是 中显示的内容mybox2
。
\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}%erlaubt Umlaute
\usepackage{lmodern}
\usepackage[skins]{tcolorbox}
\usetikzlibrary{positioning, shapes.misc}
\newtcolorbox[auto counter, ]{mybox1}[3][]{
enhanced,
arc=.3mm,
boxrule=0.3pt,
fonttitle=\bfseries,
colback=white,
colframe=red!65!black,
enlarge top by=10mm,
subtitle style={ boxrule=0.2pt,
colback=blue!40!white},
overlay={%
\path[fill=blue!65,line width=.4mm] (frame.north west)--++(17mm,0)coordinate(n2)--++(0,8mm)--++(-20mm,0) arc (-90:90:-4mm)--cycle;
\node at ([shift={(5mm,4mm)}]frame.north west){\color{white}{
\textbf{\sffamily #2}}};
\path[fill=red!65!blue] ([xshift=.4mm]n2)--++(0,8mm)--++(7mm,0)--++(0,-8mm)--cycle;
\node at ([shift={(4mm,4mm)}]n2){\color{white}{\textbf{\sffamily \thetcbcounter}}};
\node[anchor=west] at ([shift={(8mm,4mm)}]n2){
\itshape\textbf{\sffamily #3}};
},
#1
}
\newtcolorbox[auto counter]{mybox2}[3][]{
enhanced,
arc=.3mm,
boxrule=0.3pt,
fonttitle=\bfseries,
colback=white,
colframe=red!65!black,
enlarge top by=10mm,
subtitle style={ boxrule=0.2pt,
colback=blue!40!white},
overlay={%
\node[fill=blue!65, rounded rectangle, rounded rectangle right arc=none, anchor=south west, text=white, font=\bfseries\sffamily, minimum width=24mm, minimum height=8mm] at (frame.north west) (n2) {#2};
\node[fill=red!65!blue, right=0pt of n2, minimum height=8mm, minimum width=7mm, text=white, font=\bfseries\sffamily] (n3) {\thetcbcounter};
\node[anchor=west, right=0mm of n3, minimum height=8mm, font=\bfseries\itshape\sffamily] {#3};
},
#1
}
\newcounter{mycounter}
%----------------------------------------------------------------------------------------
%TCOLORBOXES
%----------------------------------------------------------------------------------------
\begin{document}
\begin{mybox1}[label=one]{sample}{Gebäudeheizlast nach DIN 12831 nach Temperatur}
This is a \textbf{tcolorbox}.\par
a lot of text here ... This is Example \ref{one}
\tcbsubtitle{\textbf{ Formeln}}
some text
\end{mybox1}
\begin{mybox2}[label=one]{sample}{Gebäudeheizlast nach DIN 12831 nach Temperatur}
This is a \textbf{tcolorbox}.\par
a lot of text here ... This is Example \ref{one}
\tcbsubtitle{\textbf{ Formeln}}
some text
\end{mybox2}
\end{document}