创造新环境

创造新环境

我在网上找到一个代码,可以创建一个环境,但我无法解决错误。请帮帮我。

% arara: xelatex
\documentclass[twoside]{book}
\usepackage{TikZ}
\usepackage{xcolor,mdframed}
%\usepackage{xepersian}
%\settextfont{XB Niloofar}

\begin{document}
\chapter{ftjfyg}
\section{sdg}
\mdfsetup{skipabove=\topskip,skipbelow=\topskip}
\newrobustcmd\ExampleText{%
An \textit{inhomogeneous linear} differential equation has the form
%\begin{align}
%L[v ] = f,
%\end{align}
where $L$ is a linear differential operator, $v$ is the dependent
variable, and $f$ is a given non−zero function of the independent
variables alone.
}

\newcounter{theo}[section]
\newenvironment{theo}[1][]{%
\stepcounter{theo}%
\ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=blue!20]
{\strut Theorem~\thetheo};}}
}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,fill=blue!20]
{\strut Theorem~\thetheo:~#1};}}%
}%
\mdfsetup{innertopmargin=10pt,linecolor=blue!20,%
linewidth=2pt,topline=true,
frametitleaboveskip=\dimexpr−\ht\strutbox\relax,}
\begin{mdframed}[]\relax%
}{\end{mdframed}}

\begin{theo}[Inhomogeneous Linear]
\ExampleText
\end{theo}
\begin{theo}
\ExampleText
\end{theo}
\end{document}

答案1

您的代码有两个错误。

  1. 该包已命名tikz,而不是TikZ
  2. 这是一个更微妙的问题。

    frametitleaboveskip=\dimexpr−\ht\strutbox\relax
    

    不是常规连字符,但是减号 (U+2212). 作为 TeX 尺寸中的减号,只允许使用常规连字符,即

    frametitleaboveskip=\dimexpr-\ht\strutbox\relax
    

    (您可能会注意到连字符-比 短一点

不过,我认为您应该使用对定理的内置支持mdframed

\documentclass{article}
\usepackage{amsmath}
\usepackage{mdframed}
\usepackage{xcolor}

\mdtheorem
  [linecolor=blue!20,linewidth=2pt,
   frametitlebackgroundcolor=blue!20,
   skipabove=1ex,skipbelow=1ex]
  {theo}
  {Theorem}

\begin{document}

\def\ExampleText{%
  An \emph{inhomogeneous linear} differential equation has the form
  \begin{align}
    L[v] = f,
  \end{align}
  where $L$ is a linear differential operator, $v$ is the dependent
  variable, and $f$ is a given non−zero function of the independent
  variables alone.%
}

\begin{theo}[Inhomogeneous Linear]
  \ExampleText
\end{theo}

\begin{theo}
  \ExampleText
\end{theo}

\end{document}

enter image description here

相关内容