使用 mdframed 获取文本左侧的规则,跳过环境的第一行

使用 mdframed 获取文本左侧的规则,跳过环境的第一行

我正在尝试获取一个定义环境,其中文本左侧有一条规则,但第一行除外。我目前使用 有下面的 MWE mdframed,但我不知道如何跳过规则的第一行并且不在该行上缩进。我愿意接受类似的解决方案并使用 的替代方案mdframed,但希望保留这些amsthm功能。感谢您的帮助! 在此处输入图片描述

\documentclass{article}
\usepackage{amsthm}
\usepackage{mdframed}
\usepackage{lipsum}

% Rule on the left environment
\newmdenv[
topline=false, bottomline=false, rightline=false,
skipabove=0pt, skipbelow=0pt,
leftmargin=0pt, innerleftmargin=5pt,
innerbottommargin=0pt
]{leftrule}

\theoremstyle{definition}
\newtheorem{def_internal}{Definition}

\newenvironment{defin}[1][]{
    \begin{def_internal}[{#1}]
        \begin{leftrule}
        }{%%
        \end{leftrule}
    \end{def_internal}
}   

\begin{document}
    This is my definition
    \begin{defin}
        \lipsum[66]
    \end{defin}
    but I'm hoping for something formatted automatically like
    \begin{def_internal}
        Here's the first line of my definition that I forced this length
        \begin{leftrule}
            and here's the rest! \lipsum[66]
        \end{leftrule}
    \end{def_internal}
\end{document}

答案1

使用ntheoremtcolorbox

\documentclass{article}
\usepackage{lipsum}

\usepackage{ntheorem}
\theoremindent10pt 
\theoremheaderfont{\normalfont\bfseries\hspace{-\theoremindent}}
\theorembodyfont{\normalfont}
\theoremseparator{.}
\newtheorem{defin}{Definition}

\usepackage[most]{tcolorbox}
\tcolorboxenvironment{defin}{% 
  blanker, breakable, 
  before skip=10pt,after skip=10pt, 
  overlay={\draw ([xshift=1pt,yshift=-11pt]frame.north west) -- ([xshift=1pt]frame.south west);},
  overlay first={\draw ([xshift=1pt,yshift=-11pt]frame.north west) -- ([xshift=1pt]frame.south west);},
  overlay middle and last={\draw ([xshift=1pt]frame.north west) -- ([xshift=1pt]frame.south west);},
  }


\begin{document}
    This is my definition \lipsum[1]
    \begin{defin}
        A definition not broken across pages.
        \lipsum[1]
    \end{defin}
    \lipsum[1]
    \begin{defin}
        A definition broken across pages.
        \lipsum[70]
    \end{defin}
    \lipsum[1]
\end{document}

在此处输入图片描述

细节:

在此处输入图片描述

答案2

只需添加一个结合 CarLaTeX 答案的答案tcolorbox即可这个答案这帮助我使用类似的缩进定义了一种新的定理样式amsthm

\documentclass{article}
\usepackage{amsthm}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
    
    
\makeatletter
\newtheoremstyle{indented_def} % name
{\topsep}                    % Space above
{\topsep}                    % Space below
{\addtolength{\@totalleftmargin}{10pt}
    \addtolength{\linewidth}{-10pt}
    \parshape 1 10pt \linewidth}                  % Body font
{-10pt}                           % Indent amount
{\bfseries}                   % Theorem head font
{.}                          % Punctuation after theorem head
{.3em}                       % Space after theorem head
{}  % Theorem head spec (can be left empty, meaning ‘normal’)
\makeatother

\theoremstyle{indented_def}
\newtheorem{def_internal}{Definition}

\newenvironment{defin}[1][]{
        \begin{def_internal}[{#1}]
            \begingroup
            \parindent = 15pt
    }{%
            \endgroup
        \end{def_internal}
    }


\tcolorboxenvironment{def_internal}{% 
    blanker, breakable, 
    before skip=10pt,after skip=10pt, 
    overlay={\draw ([xshift=1pt,yshift=-11pt]frame.north west) -- ([xshift=1pt]frame.south west);},
    overlay first={\draw ([xshift=1pt,yshift=-11pt]frame.north west) -- ([xshift=1pt]frame.south west);},
    overlay middle and last={\draw ([xshift=1pt]frame.north west) -- ([xshift=1pt]frame.south west);},
}

\begin{document}
    \lipsum[66]
    \begin{defin}[New def which resets indentation]
        \lipsum[66]
        
        \lipsum[66]
    \end{defin}
    \lipsum[66]
    \begin{def_internal}[Internal def (paragraphs don't indent)]
        \lipsum[66]
        
        \lipsum[66]
    \end{def_internal}
\end{document}

在此处输入图片描述

相关内容