我怎样才能在标题区域周围创建黑色边框?

我怎样才能在标题区域周围创建黑色边框?

如何在标题区域周围创建黑色边框?到目前为止,我有以下代码:

\documentclass[answers]{article}

\usepackage[utf8]{inputenc}
\usepackage[framemethod=TikZ]{mdframed}

%Textbox
\newcounter{textb}[section] \setcounter{textb}{0}
\renewcommand{\thetextb}{\arabic{section}.\arabic{textb}}
\newenvironment{textb}[1][]{%
\refstepcounter{textb}%
\ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box)]
\node[rectangle,fill=white]
{\strut};}}%
}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box)]
\node[rectangle, fill=black!10]
{\strut#1};}}% 
}%
\mdfsetup{innertopmargin=10pt, linecolor=black!80,%
linewidth=2pt,topline=true,%
frametitleaboveskip=\dimexpr-\ht\strutbox\relax
}
\begin{mdframed}[]\relax%
}{\end{mdframed}}

\begin{document}

\begin{textb}[Title area]
    some text here
\end{textb}

\end{document}

在此处输入图片描述

答案1

您也可以添加draw=black以在标题周围添加框架。在下面的 MWE 中,我还使用该tcolorbox包添加了替代版本:

在此处输入图片描述

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}


\newcounter{textb}[section] \setcounter{textb}{0}
\renewcommand{\thetextb}{\arabic{section}.\arabic{textb}}
\newenvironment{textb}[1][]{%
\refstepcounter{textb}%
\ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box)]
\node[rectangle,fill=white]
{\strut};}}%
}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box)]
\node[rectangle, fill=black!10,draw=black] %<----------------------- added draw=black here
{\strut#1};}}% 
}%
\mdfsetup{innertopmargin=10pt, linecolor=black!80,%
linewidth=2pt,topline=true,%
frametitleaboveskip=\dimexpr-\ht\strutbox\relax
}
\begin{mdframed}[]\relax%
}{\end{mdframed}}


\usepackage[most]{tcolorbox}
\newtcolorbox{MyBox}[1]{
lower separated=true,
sharp corners,
boxrule=2pt,
colback=white,
colframe=black,
colbacktitle=black!10,
coltitle=black,
enhanced,
top=7mm,
boxed title style={colframe=black,boxrule=0.5pt,sharp corners},
attach boxed title to top left={xshift=0.5cm,yshift=-3.5mm},
title={#1}
 }

\begin{document}

\begin{textb}[Title area]
    mdframed box
\end{textb}


\begin{MyBox}{Title area}
    tcolorbox 
\end{MyBox}


\end{document}

相关内容