2012-11-23 14 views

回答

6

您可以在conf.py文件中添加這樣的事(見doc爲LaTeX的輸出選項):

latex_custom = r''' 
\definecolor{Admonition}{RGB}{221,233,239} 

\makeatletter 
    \newenvironment{admonitionbox}{ 
    \begin{lrbox}{\@tempboxa}\begin{minipage}{\columnwidth} 
    }{ 
    \end{minipage}\end{lrbox} 
    \colorbox{Admonition}{\usebox{\@tempboxa}} 
    } 

    \renewenvironment{notice}[2]{ 
    \begin{admonitionbox} 
    }{ 
    \end{admonitionbox} 
    } 
\makeatother 
''' 

latex_elements = {'preamble': latex_custom} 

這是一個基本的例子,它會改變所有的告誡的背景顏色盒子(注意,警告,小費等)。

+0

謝謝!這對我有用! – starviscount

1

我的解決方案受到尼古拉斯答案的啓發。它建立在./_build/latex/sphinx.sty中的原始獅身人面像代碼之上。與Nicolas的解決方案相反,它保留了原始的獅身人面像佈局(間距,框架等),併爲其添加了背景顏色。此外,它不同地對待lightbox(注意,提示,提示,重要)和heavybox(警告,警告,注意,危險,錯誤)警告框樣式。

添加下面的代碼在你的conf.py文件 (最終輸出應該是這個樣子this):

latex_custom = r''' 
\definecolor{AdmonitionHeavyColor}{RGB}{255,204,204} 
\definecolor{AdmonitionLightColor}{RGB}{238,238,238} 

\makeatletter 

    \renewcommand{\[email protected]}{ 
    \setlength{\fboxrule}{1pt} 
    \setlength{\fboxsep}{6pt} 
    \setlength{\[email protected]}{\linewidth} 
    \addtolength{\[email protected]}{-4\fboxsep} 
    \addtolength{\[email protected]}{-2\fboxrule} 
    %\setlength{\shadowsize}{3pt} 
    \Sbox 
    \minipage{\[email protected]} 
    } 

    \renewcommand{\[email protected]}{ 
    \endminipage 
    \endSbox 
    \savebox{\@tempboxa}{\fbox{\TheSbox}} 
    \colorbox{AdmonitionHeavyColor}{\usebox{\@tempboxa}} 
    } 

    \renewcommand{\[email protected]}{ 
    {% 
     \setlength\parskip{0pt}\par 
     \noindent\rule[0ex]{\linewidth}{0.5pt}% 
     %\par\noindent\vspace{-0.2ex}% 
    } 
    \setlength{\[email protected]}{\linewidth} 
    \setlength{\fboxrule}{0pt} 
    \setlength{\fboxsep}{2pt} 
    %\setlength{\[email protected]}{\linewidth} 
    \addtolength{\[email protected]}{-4\fboxsep} 
    \addtolength{\[email protected]}{-2\fboxrule} 
    \Sbox 
    \minipage{\[email protected]} 
    } 

    \renewcommand{\[email protected]}{ 
    \endminipage 
    \endSbox 
    \savebox{\@tempboxa}{\fbox{\TheSbox}} 
    \colorbox{AdmonitionLightColor}{\usebox{\@tempboxa}} 
    {% 
     \setlength{\parskip}{0pt}% 
     \par\noindent\rule[0.5ex]{\linewidth}{0.5pt}% 
     \par\vspace{-0.5ex}% 
    } 
    } 


\makeatother 
''' 


latex_elements = {'preamble': latex_custom}