如何合并框架(mdframed)和标题(titlesec)

如何合并框架(mdframed)和标题(titlesec)

假设我有一个框架:

\mdfdefinestyle{aaa}{
        linecolor=black!50,
        backgroundcolor=Honeydew3!80,
        roundcorner = 6pt,
        fontcolor = black,
        shadow=true,
        shadowsize=3pt,
        shadowcolor=Honeydew3!20,
        userdefinedwidth = 0.5\columnwidth,
        outerlinewidth = 0.3}

我想将其放在标题格式,例如:

\titleformat{\section}[runin]{\Large}{\thesection}{0.2cm}{\begin{aaa}}[\end{aaa}]

这不起作用。这是我得到的结果: 在此处输入图片描述

你知道原因是什么吗?我该如何解决?

完整代码如下:

% Preview source code

%% LyX 2.2.3 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[a4paper,english,hebrew]{article}
\usepackage{fontspec}
\usepackage{fancyhdr}
\pagestyle{fancy}
\setcounter{secnumdepth}{-2}
\setlength{\parindent}{0bp}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\pdfpageheight\paperheight
\pdfpagewidth\paperwidth


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
\usepackage{theorem}
\theorembodyfont{\upshape}
\newtheorem{theorem}{\R{משפט}}[section]
\AtBeginDocument{\make@lr\thetheorem}

% The following chunk fixes export with XeTeX.
% It is needed because polyglossia is used by default
% and \make@lr is only defined by babel.
\@ifundefined{make@lr}
{\def\make@lr#1{\begingroup
    \toks@=\expandafter{#1}%
    \edef\x{\endgroup
  \def\noexpand#1{\noexpand\@number{\the\toks@}}}%
  \x}}{\relax}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\newfontfamily\hebrewfont[Script=Hebrew]{David CLM}
\newfontfamily\hebrewfonttt[Script=Hebrew]{Miriam Mono CLM}
\newfontfamily\hebrewfontsf[Script=Hebrew]{Yehuda CLM}
\setlength{\columnseprule}{0.4pt}
\renewcommand{\labelenumi}{\alph{enumi}.}
\usepackage{titlesec}
\usepackage[x11names,usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage[framemethod=TikZ,framemethod=pstricks]{mdframed}
\mdfdefinestyle{aaa}{
linecolor=black!50,
backgroundcolor=Honeydew3!80,
roundcorner = 6pt,
fontcolor = black,
shadow=true,
shadowsize=3pt,
shadowcolor=Honeydew3!20,
userdefinedwidth = 0.5\columnwidth,
outerlinewidth = 0.3}

\titleformat{\section}[runin]{\Large}{\thesection}{0.2cm}{\begin{mdframed}[style=partl]}[\end{mdframed}]

\makeatother

\usepackage{xunicode}
\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\begin{document}
\begin{english}[variant=american]%

\section{Hello}
\end{english}%

\end{document}

谢谢你!!

答案1

我可以提出这个建议,它依赖于pstricks。我建议使用样式wrap,因此第 1 行和第 2 行之间的内衬不会改变:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[x11names]{xcolor} 
\usepackage{mdframed, framed}
\usepackage[explicit]{titlesec}
\usepackage{bigstrut}
\usepackage{pstricks, auto-pst-pdf}
\usepackage{lipsum}

\titleformat{\section}[wrap]{\Large}{}{0cm}{\psshadowbox*[linecolor=Honeydew4, fillcolor=Honeydew3!80, shadowcolor=Honeydew3!20]{\thesection.\enspace#1\bigstrut[b]}}
\titleformat{name=\section, numberless}[wrap]{\Large}{}{0cm}{\psshadowbox*[linecolor=Honeydew4, fillcolor=Honeydew3!80, shadowcolor=Honeydew3!20]{#1\bigstrut[b]}}

\begin{document}

\section{A Test section}
\lipsum[2]

\end{document} 

在此处输入图片描述

或者,如果您可以不用阴影,那么只需使用以下简单方法即可获得几乎相同的结果\fcolorbox

\titleformat{\section}[runin]{\Large}{}{0cm}{\fcolorbox{Honeydew4}{Honeydew3!80}{\thesection.\enspace#1\bigstrut[b]}}

\titleformat{name=\section, numberless}[runin]{\Large}{}{0cm}{\fcolorbox{Honeydew4}{Honeydew3!80}{#1\bigstrut[b]}}

在此处输入图片描述

相关内容