如何将小顶框移至框架的右侧以执行以下代码

如何将小顶框移至框架的右侧以执行以下代码

标题框位于左上方。

我想将其移动到顶部和右侧。

我怎样才能移动这个节点?

\documentclass[10pt,a5paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[framemethod=tikz]{mdframed}
\newcounter{theo}
\newenvironment{theo}[1][]{%
  \refstepcounter{theo}%
  \ifstrempty{#1}%
  {\mdfsetup{%
      frametitle={%
        \tikz[baseline=(current bounding box.east),outer sep=0]
        \node[anchor=east,rectangle,fill=gray]
        { Theorem~\thetheo};}}`
  `}%
  {\mdfsetup{%
      frametitle={%
        \tikz[baseline=(current bounding box.east),outer sep=0]
        \node[anchor=east,rectangle,fill=gray]
        { Theorem~\thetheo:~#1};}}%
  }%
  \mdfsetup{innertopmargin=7pt,linecolor=gray!20,linewidth=2pt,topline=true,
    frametitleaboveskip=-15pt}
  \begin{mdframed}[]\relax%
  }{%
\end{mdframed}%
}`
`\begin{document}
\begin{theo}
  hi
\end{theo}
\end{document}

答案1

快速修复;只需null\hfill在 之前添加frametitle

\documentclass[10pt,a5paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[framemethod=tikz]{mdframed}
\newcounter{theo}
\newenvironment{theo}[1][]{%
  \refstepcounter{theo}%
  \ifstrempty{#1}%
  {\mdfsetup{%
      frametitle=\null\hfill{%   <======
        \tikz[baseline=(current bounding box.east),outer sep=0]
        \node[anchor=east,rectangle,fill=gray]
        { Theorem~\thetheo};}}
  }%
  {\mdfsetup{%
      frametitle=\null\hfill{%   <======
        \tikz[baseline=(current bounding box.east),outer sep=0]
        \node[anchor=east,rectangle,fill=gray]
        { Theorem~\thetheo:~#1};}}%
  }%
  \mdfsetup{innertopmargin=7pt,linecolor=gray!20,linewidth=2pt,topline=true,
    frametitleaboveskip=-15pt}
  \begin{mdframed}[]\relax%
  }{%
\end{mdframed}%
}
\begin{document}
\begin{theo}
  hi
\end{theo}
\end{document}

在此处输入图片描述

答案2

这显示了所需的结果,但使用tcolorbox定理环境而不是mdframed定理环境。

\documentclass[10pt,a5paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\usepackage[most]{tcolorbox}

\newtcbtheorem{mytheo}{Theorem}{enhanced,
colback=white, colframe=gray!20,
colbacktitle=gray, coltitle=black,
fonttitle=\bfseries, sharp corners, 
attach boxed title to top right={xshift=-5mm, yshift=-.5mm},
boxed title style={sharp corners, boxrule=0pt}
}{th}


\begin{document}

\begin{mytheo}{}{a}
  hi
\end{mytheo}

\begin{mytheo}{A nice theorem}{b}
  hi
\end{mytheo}

As can be seen, Theorem~\ref{th:b} shows a title while Theorem~\ref{th:a} doesn't.
\end{document}

在此处输入图片描述

相关内容