我想在我的文档中制作块,就像 javadoc 方法描述一样(见图)
我写了一个宏:
\def\makemybox{%
\noindent%
\fcolorbox[HTML]{9EADC0}[HTML]{F9F9F9}{%
\makebox[\textwidth]{%
\vbox{%
\noindent%
\fcolorbox[HTML]{9EADC0}[HTML]{DEE3E9}{%
\makebox[\textwidth][l]{\textbf{Method name}}
}\par%
\noindent%
\makebox[\textwidth][l]{Method description}
}
}
}}
但我得到了错误的框。参见图
我该如何修复我的宏?我尝试设置 \fboxsep,但没有结果。
答案1
有了tcolorbox
它就很容易了。
梅威瑟:
\documentclass{article}
\usepackage[most]{tcolorbox}
\definecolor{blue1}{HTML}{DEE3E9}
\definecolor{blue2}{HTML}{F9F9F9}
\definecolor{blue3}{HTML}{9EADC0}
\newtcolorbox{mybox}[1]{%
arc=0pt,
outer arc=0pt,
top=0pt,
bottom=0pt,
left=0pt,
right=0pt,
boxrule=0.4pt,
breakable,
colback=blue2,
colframe=blue3,
colbacktitle=blue1,
coltitle=black,
fonttitle=\bfseries,
title=#1
}
\begin{document}
\begin{mybox}{Method name}
asdfgfgbaaf
\end{mybox}
\end{document}
答案2
和mdframed
:
\documentclass{article}
\usepackage[framemethod=TikZ]{mdframed}
\definecolor{blue1}{HTML}{DEE3E9}
\definecolor{blue2}{HTML}{F9F9F9}
\definecolor{blue3}{HTML}{9EADC0}
\mdfdefinestyle{mybox}%
{leftmargin=0pt, rightmargin=2pt,innerleftmargin=5pt,
frametitlerule=true,frametitlerulecolor=blue3,
frametitlebackgroundcolor=blue1,
%frametitlerulewidth=0.4pt,
%linewidth=0.5pt,
backgroundcolor=blue2,
linecolor=blue3,
frametitlefont={\bfseries\sffamily\color{black}},
}
\newmdenv[style=mybox]{mybox}
\begin{document}
\begin{mybox}[frametitle={Method name}]
asdfgfgbaaf
\end{mybox}
\end{document}