邊距中的定理與定義名稱

邊距中的定理與定義名稱

我想讓定理名稱出現在頁邊空白處。我嘗試過使用頁邊註釋來做到這一點,但我無法做到這一點。

這是我正在嘗試做的事情的圖片。最上面一行是定理環境預設的工作方式,以下是我想要的。 在此輸入影像描述

這是我嘗試做的事情,儘管我必須承認我不太了解如何做這樣的事情

 \newenivorment{margintheorem}[#2]{
 \begin{theorem}[\marginnote{#2}]

 \end{theorem}
 }

答案1

您可以間接定義theorem環境:

\documentclass{article}
\usepackage{amsthm,marginnote,xparse}

\newtheorem{theoreminner}{Theorem}
\NewDocumentEnvironment{theorem}{o}
 {\theoreminner\IfValueT{#1}{\marginnote{\normalfont\footnotesize#1}}}
 {\endtheoreminner}

\reversemarginpar

\begin{document}

\begin{theorem}
This theorem has no attribution.
\end{theorem}

\begin{theorem}[theorem name]
This theorem has a name.
\end{theorem}

\end{document}

在此輸入影像描述

答案2

您的問題缺少一些重要的細節,特別是您沒有指定是否使用特定的套件來定義「類似定理」的環境。我假設您正在使用amsthm.

以下解決方案直接侵入amsthm指令的定義\@begintheorem,因此自動適用於各種「類似定理」的環境(命題、引理、定義…)。它基於\marginparLaTeX 核心中命令的使用:這使事情變得更加複雜,因為該命令必須「以外部段落模式」發出。事實上,我編寫程式碼的目的正是為了表明基於原始\marginpar命令的解決方案是可能的。

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

% \usepackage{amsmath} % not essential, but you probably want it too
\usepackage{amsthm}
\usepackage{etoolbox} % for "\patchcmd"/"\pretocmd"



%%%%%%%% BEGIN WIZARDRY %%%%%%%%

\makeatletter

\wlog{****************************************}
\patchcmd{\@begintheorem}{% search for:
    \@ifempty{#3}{\let\thmnote\@gobble}{\let\thmnote\@iden}%
    \thm@swap\swappedhead\thmhead{#1}{#2}{#3}%
}{% replace with:
    \let\thmnote\@gobble
    \thm@swap\swappedhead\thmhead{#1}{#2}{}%
}{% execute if succeeded:
    \wlog{>>> 1st patch succeeded.}
}{% execute if failed:
    \wlog{>>> 1st patch FAILED!}
}
\pretocmd{\@begintheorem}{% prepended code:
    \@ifnotempty{#3}{\def\@thm@marginal@note@text{#3}}%
}{% execute if succeeded:
    \wlog{>>> 2nd patch succeeded.}
}{% execute if failed:
    \wlog{>>> 2nd patch FAILED!}
}
\wlog{****************************************}

\newcommand*\@thm@marginal@note@text{}
\newcommand*\@thm@marginal@note@helper{%
    \begingroup \setbox\z@ \lastbox \endgroup
    \marginnote{\@thm@marginal@note@text}%
}
\dth@everypar = \expandafter {%
    \expandafter \@thm@marginal@note@helper
    \the \dth@everypar
}

\makeatother

%%%%%%%%  END WIZARDRY  %%%%%%%%



\newcommand*{\marginnote}[1]{%
    \marginpar
        [\footnotesize\raggedleft  #1]%
        {\footnotesize\raggedright #1}%
}
\reversemarginpar % ?

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}  {Lemma}
\theoremstyle{definition}
\newtheorem{defin}{Definition}



\begin{document}

This text comes before the first definition.

\begin{defin}[Important definition]
    A definition is \textbf{important} if and only if it is not
    unimportant.
\end{defin}

And, of course:

\begin{defin}
    An \textbf{unimportant} definition is one that is not important.
\end{defin}

Now a theorem:

\begin{theorem}[Important Theorem]
    All theorems are important, but some theorems are more important 
    than others.
\end{theorem}

The proof rests on the following

\begin{lemma}[Important lemma]
    Not all theorems (or lemmas) are equally important.
\end{lemma}

An unimportant theorem:

\begin{theorem}
    Blah blah blah\ldots
\end{theorem}

And an unimportant lemma:

\begin{lemma}
    Blah blah blah\ldots
\end{lemma}

Here is a little more text.

\end{document}

請注意老式的「老式」代碼及其使用\expandafter…;-)

輸出:

程式碼的輸出

相關內容