我有以下框,但我想稍微改变所有边距。是否可以设置自定义边距(即控制文本的开始和结束位置)?我还想将字幕稍微向左移动。请注意,文本应该在字幕之前开始,因为当前文本和字幕的开头是对齐的。
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\newtcolorbox{openningbox}[2]{
colback = white,
colframe = black,
before upper = \tcbsubtitle{\tikz{\node[draw=black,fill=white,line width=1pt,rounded corners=3.5pt,font=\bfseries\color{black}]{\rule[-.3\baselineskip]{0pt}{\baselineskip}\normalsize\sffamily\bfseries\normalfont ~~\textbf{Experiment} #1~~};}},
before lower = \tcbsubtitle{\tikz{\node[draw=black,fill=white,line width=1pt,rounded corners=3.5pt,font=\bfseries\color{black}]{\rule[-.3\baselineskip]{0pt}{\baselineskip}\normalsize\sffamily\bfseries\normalfont ~~\textbf{Experiment} #2~~};}},
subtitle style = {
enhanced,
interior hidden,
frame hidden,
top=-0.8cm
},
boxrule=1pt,
arc=2.5pt,
sidebyside,
sidebyside align = top,
enhanced,
segmentation style = {solid,line width=1pt}
}
\begin{document}
\begin{openningbox}{Real}{Ideal}
\lipsum*[1]
\tcblower
\lipsum*[2]
\end{openningbox}
\end{document}
答案1
这是 OP 的另一种定义openningbox
。
主要变化如下:
- 标题和副标题被替换为
attach boxed title to top
并\node
通过overlay
选项添加。我们还可以使用两个叠加选项来确保标题的几何形状相同。 left
文本边距使用和参数进行调整right
。并排段落之间的内部间隙使用 进行固定sidebyside gap
。sidebyside align=top
yshift*
在方框标题中的选项的帮助下工作。shorten
分割规则可以通过其样式中的选项来缩短。
代码如下:
\documentclass{article}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\newtcolorbox{openningbox}[2]{
enhanced,
colback = white,
colframe = black,
title = {\textbf{Experiment}~#1~~},
coltitle=black,
boxed title style={colframe=black, colback=white},
attach boxed title to top left={yshift*=-\tcboxedtitleheight/2, xshift=5mm},
overlay={\node[rounded corners=2.5pt, line width=1pt, draw, anchor=west, fill=white, inner xsep=3mm, inner ysep=1.25mm] at ([xshift=5mm]segmentation.north) {\textbf{Experiment}~#2~~};},
boxrule=1pt,
boxsep=0pt,
left=2mm,
right=2mm,
sidebyside gap=4mm,
arc=2.5pt,
sidebyside,
sidebyside align = top,
enhanced,
segmentation style = {solid,line width=1pt, shorten >=1cm, shorten <=1cm}
}
\begin{document}
\begin{openningbox}{Real}{Ideal}
\lipsum*[1]
\tcblower
\lipsum*[2]
\end{openningbox}
\end{document}